New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus • Advice and insight from world-class Apple enthusiasts • Exclusive access to members-only contests, giveaways and deals

Join today!

Start a Discussion

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
OS X - Development and Darwin Discussion and questions about development for Mac OS X.

Basic AppleScript w/Terminal Question

Post Reply New Thread Subscribe

Thread Tools

Member Since: Jan 28, 2012
Posts: 10
salgala2000 is on a distinguished road

salgala2000 is offline
I'm new to applescript and need help. I've read that using
PHP Code:
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?
QUOTE Thanks
Mark FX

Mark FX's Avatar
Member Since: Aug 13, 2011
Location: West Sussex, UK
Posts: 180
Mark FX has a spectacular aura about

Mark FX is offline
You simply set the variable to the do shell script command like this.

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.

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.

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.

tell application "Terminal"
        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
QUOTE Thanks

Post Reply New Thread Subscribe

« need developer to convert powerpc program to Lion compatible | make ERROR on Mac OS 10.6.8 »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Starter
Last Post
Basic Newbe iTunes Question Macvalk Switcher Hangout 1 01-29-2012 05:33 PM
Basic Pages for iPad question propita iOS and Apps 2 04-22-2011 02:29 AM
Quick question concerning basic web graphics design BrianC22 Images, Graphic Design, and Digital Photography 4 02-12-2010 09:44 PM
newbie question on XCode 3.2: how to populate pop up buttons/link to applescript nickharambee OS X - Operating System 0 10-21-2009 07:10 AM
another basic PC transition question frosty Apple Notebooks 7 05-20-2004 09:48 AM

All times are GMT -4. The time now is 08:20 AM.

Powered by vBulletin
Copyright ©2000 - 2015, Jelsoft Enterprises Ltd.

Welcome to

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!

(4 digit year)

Already a member?