Kevin
Kevin

Reputation: 1106

XCODE AppelScript ObjC : set a variable

property parent : class "NSObject"

    -- IBOutlets
    property theWindow : missing value
    set value1 to :value number 1

on buttonClick_(sender)
         set the clipboard to value1
    end buttonClick_

I'm very lost with the way Xcode is handling variable. My variable are reported not defined, I figured out that this is actually not the case when I set the variable in a "sender"

but what If I want to use a variable outside a button/sender ? or what if I want to use the same variable in two different buttons.

I have the feeling that what I'm asking not making much sense but hopefully someone will get me there.

Upvotes: 0

Views: 124

Answers (1)

vadian
vadian

Reputation: 285180

It's like in Objective-C or Swift:

Either declare a property with a default value:

property value1 : 1

Or declare the property without a value and set the value in a handler:

property value1 : missing value

...

on applicationDidFinishLaunching_(aNotification)
   set value1 to 1
end applicationWillFinishLaunching_

AppleScript code must always run in a handler. Even in a simple compiled script if you write code on the top level of the script the compiler wraps the code in the implicit on run handler.

Upvotes: 1

Related Questions