Learning to work with handlers in AppleScript I've run into an issue. Currently I have trimmed my application to call a handler when ran but currently I get an error:
error "Script Editor returned error -1708" number -1708
When I compile I have no issues. When I try to research for a solution I'm unable to find a reason why this doesn't work under the application Finder. To memory, I recall the on run must be declared last in the application.
the code:
on checkForRebels(tieFighter, starDestroyer)
display dialog "dark enough" as text
end checkForRebels
on run
tell application "Finder"
set the starDestroyer to (choose folder with prompt "Please select the Destroyer")
set tieFighter to items of starDestroyer
checkForRebels(tieFighter, starDestroyer)
end tell
end run
I tried searching for
applescript items throw error when passing to handler
but I returned Apple's Working with Errors which doesn't answer my question. When I review Apple's documentation About Handlers I don't see anything disclosing what the issue should be.
When I modify my script to:
on checkForRebels(tieFighter, starDestroyer)
display dialog "dark enough" as text
end checkForRebels
on run
tell application "Finder"
set the starDestroyer to (choose folder with prompt "Please select the Destroyer")
set tieFighter to items of starDestroyer
end tell
checkForRebels(tieFighter, starDestroyer)
end run
it works without any issue but why does the handler checkForRebels() not work in application Finder's tell block? When I call a handler do I have to always do it outside of an application for it to work?
When you are calling a handler from within a tell block or other handler, you need to specify "my", otherwise it is looking for that command in the Finder dicitonary.
my checkForRebels(tieFighter, starDestroyer)
From the Applescript Language Guide Calling Handlers in a tell Statement:
To call a handler from within a tell statement, you must use the reserved words of me or my to indicate that the handler is part of the script and not a command that should be sent to the target of the tell statement.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With