Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Applications / Mac Applications / February 2005



Tip: Looking for answers? Try searching our database.

Automate Launch & Close of App on a Schedule

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rin - 08 Feb 2005 20:27 GMT
What's the easiest way to automate closing an application at a specific
time, then opening it again several hours later? AppleScript?
QuickKeys?  We need to close certain things overnight so they can be
backed up, then open them again before we get in in the morning.
Specs: G3 running OS 9.0.4
Jerry Kindall - 09 Feb 2005 03:40 GMT
> What's the easiest way to automate closing an application at a specific
> time, then opening it again several hours later? AppleScript?
> QuickKeys?  We need to close certain things overnight so they can be
> backed up, then open them again before we get in in the morning.

I'd suggest an AppleScript, which can then be triggered by Mac OS X's
built-in cron daemon.  Something like the one below should work:

-- quit the applications safely, allowing them to cleanup
tell application "Foo" to quit
tell application "Bar" to quit
tell application "Baz" to quit

-- wait a minute to give the apps a chance to quit
delay 60

-- quit any apps that didn't quit successfully the UNIX way
do shell script "killall 'Foo'"
do shell script "killall 'Bar'"
do shell script "killall 'Baz'"

-- wait a bit longer
delay 15

-- kill any hangers-on with extreme prejudice
do shell script "killall -9 'Foo'"
do shell script "killall -9 'Bar'"
do shell script "killall -9 'Baz'"

That should do it.

Signature

Jerry Kindall, Seattle, WA                <http://www.jerrykindall.com/>

       Send only plain text messages under 32K to the Reply-To address.
       This mailbox is filtered aggressively to thwart spam and viruses.

Dave Hinz - 09 Feb 2005 04:26 GMT
> -- quit the applications safely, allowing them to cleanup
> tell application "Foo" to quit
>
> -- wait a minute to give the apps a chance to quit
> delay 60

You just wrote a race condition.  Why not wait until the quit
command finishes, instead?

> -- quit any apps that didn't quit successfully the UNIX way
> -- kill any hangers-on with extreme prejudice

Aaaaahrgh!  Why not just send 'em a TERM signal, and make sure
they really died?  Get rid of all the "just in case" wait
statements, and test for what should happen?

> That should do it.

Well, yeah, unless something goes wrong. I'd prefer to test and
trigger, rather than "wait and hope and kill".

Runs faster that way, too...
Jerry Kindall - 09 Feb 2005 07:45 GMT
> > -- quit the applications safely, allowing them to cleanup
> > tell application "Foo" to quit
[quoted text clipped - 4 lines]
> You just wrote a race condition.  Why not wait until the quit
> command finishes, instead?

Is this a trick question?  If you wait "until the quit command
finishes," you're never going to give up and decide it's not going to
quit.  The way it works is, you give 'em plenty of opportunity to quit
cleanly.  If they don't, you make them quit.

Any app that doesn't respond _for_an_entire_minute_ when you tell it to
quit is hung, almost by definition.  Or else it is waiting, like stupid
iChat, for user permission to quit, wihch it's never going to get
because there's nobody in front of the terminal.

> > -- quit any apps that didn't quit successfully the UNIX way
> > -- kill any hangers-on with extreme prejudice
>  
> Aaaaahrgh!  Why not just send 'em a TERM signal, and make sure
> they really died?  Get rid of all the "just in case" wait
> statements, and test for what should happen?

Well, what are you going to do if it didn't happen?  Tell it again to
do what it didn't do the last time you told it?  How would that help?

The nice thing about the killall is that it's a no-op if the app did
quit properly (asuming the names are sufficiently unique).  It saves
the complicated if statements and whatnot.  I was trying to keep the
script simple enough so that, you know, the original poster could adapt
it to his needs without having to understand _too_ much AppleScript.
That's the same reason I didn't use a list with all the app names in it
and a loop to go through them.

Signature

Jerry Kindall, Seattle, WA                <http://www.jerrykindall.com/>

       Send only plain text messages under 32K to the Reply-To address.
       This mailbox is filtered aggressively to thwart spam and viruses.

Rin - 09 Feb 2005 14:40 GMT
Wow, this is great, thanks. Two problems -- we're running OS 9, and I
have no clue how to use AppleScript (I have a book, though, and I can
write databases, so I'll probably get it). Jerry, is this going to work
with OS 9?

I'm sure you'll hear from me again, with whining when I don't get it
right.

> > > -- quit the applications safely, allowing them to cleanup
> > > tell application "Foo" to quit
[quoted text clipped - 38 lines]
>         Send only plain text messages under 32K to the Reply-To address.
>         This mailbox is filtered aggressively to thwart spam and viruses.
Jerry Kindall - 09 Feb 2005 17:14 GMT
> Wow, this is great, thanks. Two problems -- we're running OS 9, and I
> have no clue how to use AppleScript (I have a book, though, and I can
> write databases, so I'll probably get it). Jerry, is this going to work
> with OS 9?

Well, you can't use the lines with the "kill" commands, which makes
Dave's critique of it moot.  Those are UNIX shell commands and they
only work on Mac OS X.  But the tell application "Foo" to quit stuff
will work.  It's just that if an application is hung, or wants user
input before it quits, it won't be quit.

Signature

Jerry Kindall, Seattle, WA                <http://www.jerrykindall.com/>

       Send only plain text messages under 32K to the Reply-To address.
       This mailbox is filtered aggressively to thwart spam and viruses.

Rin - 10 Feb 2005 14:45 GMT
Thanks for the help!

> > Wow, this is great, thanks. Two problems -- we're running OS 9, and I
> > have no clue how to use AppleScript (I have a book, though, and I can
[quoted text clipped - 12 lines]
>         Send only plain text messages under 32K to the Reply-To address.
>         This mailbox is filtered aggressively to thwart spam and viruses.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.