Skip to main content
Solved

Pass script parameters to an applescript


Forum|alt.badge.img+11

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?

Best answer by mscottblake

@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 original
Did this topic help you find an answer to your question?

8 replies

Forum|alt.badge.img+16
  • Legendary Contributor
  • 7880 replies
  • October 6, 2015

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


bentoms
Forum|alt.badge.img+35
  • Legendary Contributor
  • 4331 replies
  • October 6, 2015

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

What was the outcome again?


Forum|alt.badge.img+11
  • Author
  • Valued Contributor
  • 120 replies
  • October 6, 2015

@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.


Forum|alt.badge.img+24
  • Honored Contributor
  • 341 replies
  • Answer
  • October 6, 2015

@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

Forum|alt.badge.img+11
  • Author
  • Valued Contributor
  • 120 replies
  • October 6, 2015

BEAUTIFUL!

Thanks @mscottblake!


bentoms
Forum|alt.badge.img+35
  • Legendary Contributor
  • 4331 replies
  • October 6, 2015

@mscottblake to the rescue!!


Forum|alt.badge.img+16
  • Legendary Contributor
  • 7880 replies
  • October 6, 2015

That's good information. Bookmarking this page :)


Forum|alt.badge.img
  • New Contributor
  • 1 reply
  • March 20, 2018

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


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings