Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AppleScript: Call handler inside tell statement

I get this error everytime i run this script: System Events got an error: "Test123" doesn’t understand the notify message.

Code:

--more code...
tell application "System Events"
    if some_system_events_property then
         my notify of "Test123" thru "Test"
    end if
end tell
--more code...
to notify of message thru level
    display dialog message with titel level
end notify

I have tried to replace

my notify of "Test123" thru "Test"

with the following, without any success:

notify of "Test123" thru "Test" of me
(notify of "Test123" thru "Test") of me
like image 546
Tyilo Avatar asked May 05 '11 19:05

Tyilo


People also ask

What is Applescript handler?

Collections of script statements that can be invoked by name are referred to as handlers in AppleScript, functions or methods in JavaScript, and subroutines in some other languages.

What is a handler script?

A handler is a part of a script that defines what the script will do when a particular message is sent to it. There are three primary types of handlers: command handlers (sometimes called on handlers), function handlers, and generic handlers (also known as to handlers).


2 Answers

not exactly sure what your trying to do but here is an example of how to call a function and pass parameter

tell application "System Events"
    set m to "message content"
    my notify(m)
end tell
--more code...
on notify(message)
    display dialog (message)
end notify
like image 167
mcgrailm Avatar answered Oct 01 '22 09:10

mcgrailm


Try this:

tell application "System Events"
    if some_system_events_property then
        tell me to notify of "Test123" thru "Test"
    end if
end tell

to notify of message thru level
    display dialog message with title level
end notify

Although I'll also say that I never use the direct parameter syntax for AppleScript handlers, preferring positional parameters (i.e., notify( message, level )), as it avoids the ambiguous syntax troubles you discovered.

like image 29
Chuck Avatar answered Oct 01 '22 07:10

Chuck