AppleScript handlers with whitespace in parameter names and without "given"

57 Views Asked by At

I read about interleaved- handlers and parameters in handlers in Apple's documentation, but I don't know why some specific open-source code is working for others while not for me.

In the documentation of Handlers with Labeled Parameters it declares that:

These are the only labels that can be used without the special label given

But, for example, I saw this handler in some library (among many other examples):

on create special window windowTitle special width theWidth special height theHeight clicks neededClicks : 0

How and why this code is gonna work? I'm trying to execute it via "osascript" tool (using a plain-text non-compiled script file) - and not from Script Editor - without any luck.

I tried to wrap the spaced-names with vertical-bar sign, but without luck:

on |create special window| windowTitle |special width| theWidth |special height| theHeight |clicks| neededClicks : 0

But this code returns "script error: Expected “given”, “into”, “with”, “without” or other parameter name but found identifier. (-2741)".

Maybe outside of Script Editor, it's not possible to use handlers this way? Or since it's from a library it has a different syntax restrictions? Or maybe the Script Editor "hides" required syntax when copying from it?

Note, I'm not even sure the problem is whitespace, or the lack of the "given"-label keyword, or maybe a missing colon trying to be parsed as "Interleaved Parameter", but I see code like this anywhere and can't understand why it's working.

Other way to ask the same question: how "display dialog" built-in command's handler is defined? how it works with whitespaces in the command name and parameters?

1

There are 1 best solutions below

0
Robert Kniazidis On

You can define multiword name functions with multiword labels using the given keyword and pipes. Here the function name is "|create special window|" :

on |create special window| given |window title|:windowTitle, |special width|:theWidth
    display dialog "Window Title:     " & windowTitle & return & "Speacial Width:  " & theWidth
end |create special window|

|create special window| given |window title|:"newWindow", |special width|:600