• 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: Ignore responses from do shell script
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Ignore responses from do shell script


  • Subject: Re: Ignore responses from do shell script
  • From: Phil Stokes <email@hidden>
  • Date: Sat, 09 Jul 2016 18:59:15 +0700

I was able to achieve what I wanted thanks to Alex’s tip to re-read the do shell script doc.

The answer is to run the shell command as a background task using the “&” function.

do shell script theCommand & " &> /dev/null &"

That will kick off the shell script and return control to the AppleScript. In my case, I didn’t want the AppleScript to end there because then the user has no way of knowing when or if the shell script completes. To deal with that, I add another do shell script after the first to check when the process is complete:


# run theCommand as background task
do shell script theCommand & " &> /dev/null &"

#wait for the task to appear in the process list
delay 10

set isDone to false
repeat while isDone is false
try
# we need multiple grep's to stop grep finding its own process in ps
do shell script "ps ax | grep -v grep | grep " & theProcessName
if the result contains theProcessName then
delay 10
end if
on error
# when the task is done the shell will return an error
set isDone to true
display dialog "Your task is done!"
end try
end repeat



Best


phil

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Ignore responses from do shell script
      • From: Christopher Stone <email@hidden>
    • Re: Ignore responses from do shell script
      • From: Shane Stanley <email@hidden>
References: 
 >Ignore responses from do shell script (From: Phil Stokes <email@hidden>)
 >Re: Ignore responses from do shell script (From: Axel Luttgens <email@hidden>)

  • Prev by Date: Re: Anything new in OSX 10.12 ?
  • Next by Date: Re: Ignore responses from do shell script
  • Previous by thread: Re: Ignore responses from do shell script
  • Next by thread: Re: Ignore responses from do shell script
  • Index(es):
    • Date
    • Thread