Bananimus Prime
Bananimus Prime

Reputation: 25

Share a String Variable Between AppleScript & Objective C

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!!!

Upvotes: 0

Views: 314

Answers (1)

vadian
vadian

Reputation: 285180

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

Upvotes: 1

Related Questions