I'm trying to call a function/handler from a tell block, but AppleScript keeps throwing an error:
Result: error "AppleEvent handler failed." number -10000
The script fails where I'm calling start_varnish():
tell application "System Events"
set iTermIsRunning to exists (processes where name is "iTerm")
end tell
tell application "iTerm"
activate
try
tell current terminal
if iTermIsRunning then
launch session "Default Session"
end if
tell the last session
my start_varnish()
end tell
end tell
on error err
log "Reopening iTerm2"
reopen
tell current terminal
tell the last session
my start_varnish()
end tell
end tell
end try
end tell
on start_varnish()
set name to "Varnish Cache"
end start_varnish
When I move the contents of the handler and place it directly in the code above, it works fine, but I would like to wrap the functionality in a handler for reusability.