• 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: Waiting for script to exit
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Waiting for script to exit


  • Subject: Re: Waiting for script to exit
  • From: Andrew Oliver <email@hidden>
  • Date: Sun, 22 May 2005 14:06:45 -0700

On 5/21/05 5:59 PM, "Christopher Brown" <email@hidden> wrote:

> Hi,
>   I've been writing a small applescript to run a refactoring (simply done by
> running a shell command), and then reload the document in SubEthaEdit. 
> However, the open command runs before the shell script has exited.  Is there
> any way to force the commands to run in sequence?
>
> set refacCommand2 to "echo \"" & refacCommand & " " & docPath & " " &
> refacArgs & "\" | " & refacPath & refacBinary & " >> /Library/Logs/HaRe.log"
> tell application "Terminal" to do shell script refacCommand2
>
> tell application "SubEthaEdit" to open the first text document

First, don't use terminal.app for any of this. It isn't necessary. You're
using 'do shell script' which is a built-in command that does not require
any specific target.

That said, 'do shell script' should wait until the command finishes before
continuing. I'm not sure why it doesn't in this case. Of course, since we
can't see the contents of your variables it's quite possible that there's
something in those that's causing this behaviour.

The second solution since that doesn't seem to work is to have the shell
script return the pid of the process. You can then check for that process id
to detect when the process terminates:

 set refacCommand2 to "echo \"" & refacCommand & " " & docPath & " " &
refacArgs & "\" | " & refacPath & refacBinary & " >> /Library/Logs/HaRe.log
& echo $!" -- Note the '& echo $!' at the end

 set thePID to do shell script refacCommand2

Now thePID will contain the pid of the refacBinary process so you can poll
the process table until it's cleared:

 set isRunning to true
 repeat until isRunning is false
   if (do shell script "ps -p " & thePID) does not contain thePID then
      set isRunning to false
   else
     delay 5 -- check again in 5 seconds
   end if
 end repeat

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Waiting for script to exit (From: Christopher Brown <email@hidden>)

  • Prev by Date: Font Book Examples
  • Next by Date: Re: Waiting for script to exit
  • Previous by thread: Re: Working with big lists
  • Next by thread: Re: Waiting for script to exit
  • Index(es):
    • Date
    • Thread