Please can someone help. Why do I get an error using the script below?
The app runs OK until I uncheck (or re-check) the check box in the UI i have.
script AppDelegate
property parent : class "NSObject"
property window : missing value
property Thischeckbox : true
on buttonClicked_(sender)
tell application "Adobe Illustrator"
activate
tell document 1
display dialog "The check box returned = " & Thischeckbox
end
end
end
on applicationWillFinishLaunching_(aNotification)
-- Insert code here to initialize your application before any files are opened
end applicationWillFinishLaunching_
on applicationShouldTerminate_(sender)
-- Insert code here to do any housekeeping before your application quits
return current application's NSTerminateNow
end applicationShouldTerminate_
end script
Also, I do not get an error if I move the dialog to before the document tell block. Something about Illustrator seems to be loosing the boolean value of the checkbox.
I don’t know if this matters, but at least from a readability standpoint, I would rewrite your buttonClicked method like this:
on buttonClicked_(sender)
tell application "Adobe Illustrator"
activate
tell document 1
display dialog "The check box returned = " & Thischeckbox
end tell
end tell
end buttonClicked_
A checkbox is a button, and its state is not a boolean yes/no, but an integer 0/1/-1, where -1 is mixed state (if you allow it). Normally you can get away with using booleans, but sometimes it causes problems.
So when the state of the button is set by the UI, it is no longer an AS true/false, but rather an NSNumber. To display that value in an AppleScript dialog, you have to coerce it AppleScript as an integer (or boolean). So try this:
display dialog "The check box returned = " & (Thischeckbox as integer)
Still no luck. Tried your solution but the dialog still does not like it.
I get the error: “Can’t make «class ocid» id «data optr0000000000F8577DFF7F0000» into type integer. (error -1700)”
I’ve managed to get around the problem however by passing off the result to a another variable before the error occurs but would still be interested in a solution.
on buttonClicked_(sender)
set theResponse to Thischeckbox as integer
tell application "Adobe Illustrator"
activate
tell document 1
display dialog "The check box returned = " & theResponse
end tell
end tell
end buttonClicked_