Re: Scripting CLI apps
Re: Scripting CLI apps
- Subject: Re: Scripting CLI apps
- From: Christopher Nebel <email@hidden>
- Date: Tue, 21 Oct 2003 13:40:41 -0700
On Oct 20, 2003, at 7:47 AM, Axel Luttgens wrote:
Rick Davis wrote:
Can results of AppleScripts be passed to terminal command line
interface apps?
-- Construct the string containing the shell command to perform
display dialog "IP address to ping once:" default answer ""
set shellCommand to "ping -c 1 " & text returned of result
-- Execute the command within a Terminal's new window
tell application "Terminal"
do script shellCommand
end tell
Of course, depending on what you're doing, you may not need the
Terminal at all. AppleScript's Standard Additions contains a command
called "do shell script", which will simply execute the command in a
shell without involving Terminal at all. Unless you want to see the
output in a Terminal window for some reason, this is usually the way to
go. For example:
-- Get a path string
display dialog "Make director at POSIX path:"
set p to text returned of the result
-- The business end. Look Ma, no Terminal!
do shell script "mkdir -p " & quoted form of p
Notice the use of the "quoted form" property of strings. This "quotes"
the string so that the shell will interpret it as a single literal
parameter, which is important if the string contains spaces or certain
characters the shell considers interesting, like *, [, etc. If you
plan to use the shell a lot from AppleScript, you should read TN2065
<
http://developer.apple.com/technotes/tn2002/tn2065.html> at some
point.
--Chris Nebel
AppleScript Engineering
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.