Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Diatribe

macrumors 601
Original poster
Jan 8, 2004
4,258
46
Back in the motherland
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
 
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)
 
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':

--Open this script in a new Script Editor window.

set sh_whoami_ to "whoami" as string
set short_username_ to (do shell script sh_whoami_) as string
set sh_find_ to "find ~ \\( \\! -user " & short_username_ & " \\) -exec ls -l {} \\;" as string
do shell script sh_find_ with administrator privileges

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]
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.