Results 1 to 2 of 2
  1. #1


    Member Since
    Jan 28, 2012
    Posts
    10
    Basic AppleScript w/Terminal Question
    Hello,
    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?

  2. #2

    Mark FX's Avatar
    Member Since
    Aug 13, 2011
    Location
    West Sussex, UK
    Posts
    190
    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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. basic terminal commands not working
    By ent_matt in forum OS X - Operating System
    Replies: 12
    Last Post: 07-28-2011, 02:56 PM
  2. Terminal vs. Applescript
    By tgaleza in forum OS X - Operating System
    Replies: 2
    Last Post: 09-25-2009, 10:08 AM
  3. Need some basic terminal commands...
    By maxf in forum OS X - Development and Darwin
    Replies: 3
    Last Post: 07-22-2007, 01:46 AM
  4. Basic Terminal Automation
    By Voix in forum OS X - Development and Darwin
    Replies: 3
    Last Post: 10-17-2006, 03:20 AM
  5. Terminal and Applescript
    By bigpixl in forum OS X - Development and Darwin
    Replies: 0
    Last Post: 08-09-2005, 12:34 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •