Apple Script Question

Discussion in 'Mac Apps and Mac App Store' started by Diatribe, May 16, 2004.

  1. Diatribe macrumors 601

    Diatribe

    Joined:
    Jan 8, 2004
    Location:
    Back in the motherland
    #1
    Hi,

    I was just wondering how you build a script that incorporates the execution of a Terminal command line. I'm just a total newb when it comes to stuff like this.
    Any help is highly appreciated... :D
     
  2. sageenos macrumors member

    Joined:
    Jan 5, 2002
    Location:
    South Carolina
    #2
    tell application "Terminal"
    do script "echo Hello World!"
    end tell

    -- use the do script command with a string value
     
  3. Diatribe thread starter macrumors 601

    Diatribe

    Joined:
    Jan 8, 2004
    Location:
    Back in the motherland
    #3
    Thanks a lot. I works flawlessly. :D
    Just one more question. How do you let the script close the Terminal window AFTER the process is done, or the Terminal itself for that matter. (Haven't figured out yet which I'd prefer)
     
  4. MarkDouma macrumors newbie

    Joined:
    May 16, 2004
    Location:
    Grand Rapids, Michigan, USA
    #4
    Actually, you might say there are 2 ways of accessing the shell from AppleScript.

    'do script' and using the Terminal application to present you with the running shell command is one option.

    The other option is to use the 'do shell script' of Standard Additions, which works for OS X 10.1.2 or later.

    The following script is an example of a 'do shell script':

    If you're using Panther, the link should open up in Script Editor, then just press the green "Play" button and enter your password when prompted.

    (Note regarding this particular script:
    I recently used the "Restore" tab of Panther's Disk Utility (which uses the 'asr' Apple Software Restore tool) to clone the 7 partitions of one 80 GB to another 80 GB. The end result left many files and folders on my user partition which were owned by root, and which I didn't have access to, until I fixed the permissions on them myself.)

    You can use the following AppleScript to check for any files in your home folder that have ownership that isn't your own. (Note, I'm using 'sudo'—that's what 'with administrator privileges' equates to—to be able to search inside of any root-owned folders that might ordinarily cause access denied errors.)

    Also, the following page is a must read: http://developer.apple.com/technotes/tn2002/tn2065.html

    Hope this helps....
    -------------------------
    [This script was automatically tagged for color coded syntax by Convert Script to Markup Code]
     

Share This Page