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

soumya
  • 3,801
  • 9
  • 35
  • 69

1 Answers1

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
vadian
  • 274,689
  • 30
  • 353
  • 361
  • 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? – Bananimus Prime Sep 08 '15 at 09:48
  • 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" – YeaTheMans Jul 17 '17 at 05:25