• 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: Multiline commands in do shell script
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Multiline commands in do shell script


  • Subject: Re: Multiline commands in do shell script
  • From: Graff <email@hidden>
  • Date: Tue, 03 Feb 2004 13:20:52 -0500

You can do multiple commands in one shell line by separating the commands with a semicolon. In the shell environment that the "do shell script command" uses (the environment is called sh) you can't follow a background symbol (&) with a semicolon (;) because they are both command separators, so you wouldn't need a semicolon after you background something. For example:

This works, it moves to ~/Desktop and lists the Desktop directory:
cd ~/Desktop; ls

This works, it moves to ~/Desktop in the background and lists the current directory:
cd ~/Desktop & ls

This does not work in bash or sh, but it works in csh or tcsh. It does the same thing as just having a & between the commands. This messed me up mightily since I am familiar with tcsh and I didn't know why it was failing in AppleScript:
cd ~/Desktop &; ls

So your command would look like this:
do shell script "do shell script "mDNS -B _ssh._tcp local. &> ~/Desktop/mDNSService.txt & killall mDNS"

However, this kills the mDNS application immediately and it doesn't have a chance to do anything. You might want to put a sleep command in there to give it a second to work:
do shell script "do shell script "mDNS -B _ssh._tcp local. &> ~/Desktop/mDNSService.txt & sleep 5; killall mDNS"

For more information on the "do shell script" command, see Apple's web page on it:
<http://developer.apple.com/technotes/tn2002/tn2065.html>

- Ken

On Feb 3, 2004, at 11:09 AM, John C. Welch wrote:

So I need to deal with a command that never exits, (mDNS to be precise) and
do shell script.

Because of the way mDNS works, even if I run it as this:

mDNS -B _ssh._tcp local. > ~/Desktop/mDNSService.txt &

I never return from the do shell script step. What I'd like to do is just
create a three - line shell script and run that, but have it live only in
the script itself...something like

do shell script "#!/bin/sh
mDNS -B _ssh._tcp local. > ~/Desktop/mDNSService.txt &
killall mDNS"

I know there's something stupid I'm missing here, but I can't quite figure
it out.
_______________________________________________
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.

  • Follow-Ups:
    • Re: Multiline commands in do shell script
      • From: Graff <email@hidden>
References: 
 >Multiline commands in do shell script (From: "John C. Welch" <email@hidden>)

  • Prev by Date: Re: Applescript can't tell time?
  • Next by Date: Re: Applescript can't tell time?
  • Previous by thread: Re: Multiline commands in do shell script
  • Next by thread: Re: Multiline commands in do shell script
  • Index(es):
    • Date
    • Thread