0

I have perhaps 1% Objective C knowledge, and am more comfortable using AppleScript for small tasks.

I'm developing an app that requires a more attractive alert window though, so I have started to learn more about AppleScriptObjC.

My question is, how do I get my AppleScript variable 'serialNumber', which is set to a string from the clipboard that will be something like "* 1234567890 *", into the Objective C side of things so that I can display the string through the label object?

I've already got my label set up as

'property serialNumberLabel: missing value'

I just don't know how to transfer the variable between the two languages, so that I can set the serialNumberLabel value to the string currently stored in the serialNumber variable.

Thanks!!!

1 Answer 1

1

AppleScript strings are implicitly bridged to NSString, so you can write

set serialNumber to the clipboard
serialNumberLabel’s setStringValue:serialNumber

In the opposite direction you need to coerce the NSString object to text

set serialNumber to serialNumberLabel’s stringValue() as text
Sign up to request clarification or add additional context in comments.

2 Comments

Hi Vadian, thanks for your reply. When I add 'serialNumberLabel's setStringValue:serialNumber' to my AppleScript code, I get an error saying 'Expected end of line, etc. but found unknown token.' Should that line be going inside the AppleScript 'on applicationWillFinishLaunching_(aNotification)' code block, or somewhere else?
Yes the script vadian posted like all scripts should be used inside a block (unless the blocks are included in the snippet.) like applicationWillFinishLaunching_(aNotification) which will be triggered when the application launches. so if you paste the script he supplied you with inside the block - When the application launches it will read your clipboard setting its contents to variable "serialNumber" then the Label "serialNumberLabel" will set its stringValue (its text) to "serialNumber"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.