Basic AppleScript w/Terminal Question

Joined
Jan 28, 2012
Messages
10
Reaction score
0
Points
1
Hello,
I'm new to applescript and need help. I've read that using
PHP:
do shell script "command here"
will run a command in terminal for you. My question is: how do you retrieve the output of that command and store it as a variable?:Blushing:
 
Joined
Aug 13, 2011
Messages
200
Reaction score
7
Points
18
Location
West Sussex
You simply set the variable to the do shell script command like this.

Code:
set myApplications to do shell script "ls /Applications/"

By default the returned myApplications variable result is a Applescript text type, as UTF-8 format, but you can use different types like this.

Code:
set theBinaryData to do shell script ("curl " & quoted form of theURLvariable) as data

this will return binarydata.

If you dont have Administrator privileges, you can use a command like this.

Code:
set myApplications to do shell script "ls /Applications/" with administrator privileges ¬
      user name "adminName" password "adminPassword"

To find out all of the options for the do shell script command, look in the
StandardAdditions.sdef file, from the Window / Library menu.

Also you can script the Terminal Application like this.

Code:
tell application "Terminal"
        activate
        do script "ls /Applications/"
end tell

In all of the above examples, you can also use echo and pipes in your shell commands.

Hope this is of some help

Regards Mark
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top