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

Ignore responses from do shell script


  • Subject: Ignore responses from do shell script
  • From: Luther Fuller <email@hidden>
  • Date: Sat, 09 Jul 2016 12:27:29 -0500

If I understand the question correctly, it asks "What does my script do while waiting for a lengthly 'do shell script' to complete?"
I have a 'do shell script' that burns a dvd. Yes, that does take awhile. I wanted my script to play music until burning had completed.
Here's how I did that ...

My main script ends with this ...

-- begin burning to the disk
"drutil -drive " & driveNr & " burn -verify " & (quoted form of (POSIX path of dropItem))
set burnpid to do shell script the result & " &> /dev/null & echo $!"
-- play music until burn completed
my playUntilComplete(burnpid)
end main -------------------------------------------

And the music is played by this handler ...

on playUntilComplete(mainPID)
--
-- The code here finds a random audio file and
-- saves an alias to the file in the variable 'soundAlias'
-- You don't need to be confused by that.
--
set soundPath to (quoted form of (POSIX path of soundAlias))
set soundpid to do shell script "afplay " & soundPath & " &> /dev/null & echo $!" -- start the music
repeat
delay 1
try
do shell script "ps -p " & mainPID
if not (the result contains mainPID) then error -- here is where you exit the loop when the lengthly 'do shell script' finishes !!!
on error
exit repeat
end try
try
do shell script "ps -p " & soundpid
on error
set soundpid to do shell script "afplay " & soundPath & " &> /dev/null & echo $!" -- restart the music (loop)
end try
end repeat
try
do shell script "kill " & soundpid -- kill the music
end try
end playUntilComplete -------------------------------

I am not recommending that you play music while waiting for completion,
but you can write a 'doSomethingUntilComplete' handler that fits your situation.




 _______________________________________________
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: 2551phil <email@hidden>
References: 
 >Ignore responses from do shell script (From: Phil Stokes <email@hidden>)

  • Prev by Date: Re: Ignore responses from do shell script
  • 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