Hey MacScripter, and AppleScriptObjC coders alike!
I’m not sure if you all knew this, but you know how there’s the “AppDelegate” script? If you add extra scripts after that, and create the object in your interface, you can use that script.(See the example below)
script AppDelegate
property parent : class "NSObject"
on applicationWillFinishLaunching_(aNotification)
end applicationWillFinishLaunching_
on applicationShouldTerminate_(sender)
return current application's NSTerminateNow
end applicationShouldTerminate_
end script
script ScriptWithVariableNeeded
property NeededVariable : false
end script
script MeatAndTaters
if NeededVariable = true then return
end script
Can anyone help me find a way to import NeededVariable into MeatAndTaters?
You can, but it’s usually more convenient to store them as separate files.
Make instances of them both (blue cubes), add a property to MeatAndTaters set to missing value and connect it to the NeededVariable instance, then use the property to ask the NeededVariable instance for the value with NeededVariable().
Where I said NeededVariable instance, it should have been ScriptWithVariableNeeded instance. Your code would look like:
script ScriptWithVariableNeeded
property NeededVariable : false
end script
script MeatAndTaters
property swvnInstance: missing value -- connected to instance of ScriptWithVariableNeeded in UI
on doSomething()
if swvnInstance's NeededVariable() as boolean = true then return
end doSomething
end script