Given the following AppleScript code
on myHandler()
display dialog ("I'm your Handler!")
end myHandler
How do I call myHandler
from osascript
(using Terminal
), plain without parameters, but also with?
applescript
Given the following AppleScript code
on myHandler()
display dialog ("I'm your Handler!")
end myHandler
How do I call myHandler
from osascript
(using Terminal
), plain without parameters, but also with?
Best Answer
Assuming your shell is
bash
orzsh
, there are a couple of ways, depending on your needs or preferences. You can send your code through directly, which only needs an extra line at the bottom in this case to actually call the handler in order to execute its code (just as you did in your Python code:"{applescript.read()}\nmyHandler()"
):If you, say, stored your script in a file, which was located at
~/Documents/myscript.applescript
, then you can pass the file intoosascript
like so:Of course, you would still need to include the call to your handler in your
.applescript
file, i.e. an extra line at the end or the beginning of your script that simply saysmyHandler()
If you wanted to pass a commandline parameter to make the contents of the dialog more dynamic, you can edit your script to look like this:
Then call it from the command line like this:
Hopefully, if I anticipated my example script's set up correctly, it should work without the quotes: