Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I launch an applescript.scpt file from the terminal and pass terms / variables?

I have an applescript that does something along these lines:

using terms from application "Quicksilver"
    on open theseitems
        repeat with aitem in theseitems
            display dialog aitem as text
        end repeat
    end open
end using terms from

But what I'd like to do is be able to start running a particular applescript.scpt file via the Terminal and pass in a variable, like a path to a file.

osascript ~/applescript.scpt /path/to/my/file.txt

and then have the Applescript run with access to that parameter. In this case it would (hopefully) display a dialog with that path, /path/to/my/file.txt

I know I could achieve that by doing something like

osascript -e "display dialog "~/path/to/file.txt"

But the point is not to display a dialog with Applescript, rather it's more about knowing if I would be able to pass a variable in to a script file.

like image 853
cwd Avatar asked Dec 08 '11 01:12

cwd


1 Answers

In the script you pass in the arguments with the on run like this :

on run arg
  --do whatever you want with arg
end run

If more than one argument is specified the arg variable is a list. enter image description here

enter image description here

like image 112
Kassym Dorsel Avatar answered Sep 28 '22 11:09

Kassym Dorsel