Pass script parameters to an applescript

NowAllTheTime
Contributor III

Does anyone know if it is possible to pass the default script parameters and/or the custom parameters to an applescript?

It's easy enough to pass to a shell script, but I can't quite seem to figure out any syntax that will use the script parameters in an applescript.

If you've managed to do this could you give a quick sample of the syntax you used to utilize the parameter as a variable?

1 ACCEPTED SOLUTION

mscottblake
Valued Contributor

@jasonaswell @bentoms This takes parameter 4 ($4 in bash) if it was passed and prompts for the value if it wasn't. Useful for things like Self Service scripts that you would also like to make usable with Casper Remote.

on run argv
    if (count of argv) > 3 then
        set result to item 4 of argv
    else
        set result to text returned of (display dialog "Enter the Username to be made an admin:" default answer "")
    end if

    ....

end run

View solution in original post

8 REPLIES 8

mm2270
Legendary Contributor III

A pure Applescript? As in a .scpt file? Or do you mean in a shell script that uses Applescript/osascript within it?

bentoms
Release Candidate Programs Tester

@mscottblake we were talking about this in the AppleScript channel on the MacAdmins.org Slack.

What was the outcome again?

NowAllTheTime
Contributor III

@mm2270 pure Applescript

I can get it to work if I do a shell script with an osascript call inside of it, but I'm currently writing something in Applescript that's too long to reasonably be nested within a shell script.

mscottblake
Valued Contributor

@jasonaswell @bentoms This takes parameter 4 ($4 in bash) if it was passed and prompts for the value if it wasn't. Useful for things like Self Service scripts that you would also like to make usable with Casper Remote.

on run argv
    if (count of argv) > 3 then
        set result to item 4 of argv
    else
        set result to text returned of (display dialog "Enter the Username to be made an admin:" default answer "")
    end if

    ....

end run

NowAllTheTime
Contributor III

BEAUTIFUL!

Thanks @mscottblake!

bentoms
Release Candidate Programs Tester

@mscottblake to the rescue!!

mm2270
Legendary Contributor III

That's good information. Bookmarking this page :)

talexmaxim
New Contributor

http://hints.macworld.com/article.php?story=2004012913110734