• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Scripting CLI apps
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Scripting CLI apps


  • Subject: Re: Scripting CLI apps
  • From: Matt Zollinhofer <email@hidden>
  • Date: Mon, 20 Oct 2003 20:02:56 -0400

Axel-

Just wanted to say thanks for the VERY complete explanation. I'm new to this whole AppleScript world and so I've just been trolling this list for a little bit, and that sort of explanation is great for newbies like me.

matt

On Monday, October 20, 2003, at 10:47 AM, Axel Luttgens wrote:

Rick Davis wrote:

Heylo All,

Can results of AppleScripts be passed to terminal command line interface apps? For example instead of instructing non-technical persons on how to run createhomedir from the terminal can I use a script like:

display dialog "Create home directory for:" default answer "user shortname" buttons {"Cancel", "Create"} default button "Create"
tell application "Terminal"
createhomedir - result
end tell

As I don't want to to populate my disk with lots of user dirs, I'll take the example of pinging a machine ;-)

First, let's have a look at Terminal's dictionary to see how to execute a shell command from within that application:

do script: Run a UNIX shell script or command
do script plain text -- data to be passed to the Terminal
application as the command line
[with command plain text] -- data to be passed to the Terminal
application as the command line, deprecated, use direct parameter
[in reference] -- the window in which to execute the command

So, we know that one needs to pass the WHOLE shell command as a string (a little experiment also show that if the [in reference] part is omitted, the command would be executed in a new Terminal's window).

Then comes the construction of that string.
So, as we want some user interaction, we need the "display dialog" AppleScript command.
From the Standard Additions dictionary:

display dialog: Display a dialog box, optionally requesting user input
display dialog plain text -- the text to display in dialog box
[default answer plain text] -- the default editable text
[buttons a list of plain text] -- a list of up to three button names
[default button number or string] -- the name or number of the
default button
[with icon number or string] -- the name or ID of the icon to display
[with icon stop/note/caution] -- or one of these system icons
[giving up after integer] -- number of seconds to wait before
automatically dismissing dialog
Result: dialog reply -- a record containing the button clicked and
text entered (if any)

Huho, this one returns a "dialog reply":

Class dialog reply: Reply record for display dialog command
Properties:
button returned plain text [r/o] -- name of button chosen (empty if
giving up after was supplied and dialog timed out)
text returned plain text [r/o] -- text entered (present only if
default answer was supplied)
gave up boolean [r/o] -- did the dialog time out? (present only if
giving up after was supplied)

OK, we now may write our script (very basic, no input nor error checking):

-- 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

Well, that's just a skeleton, but it should suffice to provide the general idea.
HTH,
Axel



Just thought someone may have gone down this road already. Will break out the books and see what I can figure out.

Thanks and Have A Great Day.

Rick Davis
_______________________________________________
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.
_______________________________________________
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.

References: 
 >Re: Scripting CLI apps (From: Axel Luttgens <email@hidden>)

  • Prev by Date: do shell script
  • Next by Date: Re: do shell script
  • Previous by thread: Re: Scripting CLI apps
  • Next by thread: Re: Scripting CLI apps
  • Index(es):
    • Date
    • Thread