• 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: Application Bundle won't quit at Shutdown
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Application Bundle won't quit at Shutdown


  • Subject: Re: Application Bundle won't quit at Shutdown
  • From: email@hidden
  • Date: Mon, 14 Dec 2009 14:51:53 -0800

There is something very hokey with your script's design if you feel a need to 'kill' it. You wouldn't happen to have an infinite loop with a 'delay' command, by any chance? If so, it'll permanently block your app's main event loop, preventing it from handling incoming events (e.g. quit), and you need to replace it with an 'idle' handler, which won't.

Here's the script so that everyone can see what I'm trying to accomplish:

global gScriptName

tell application "Finder"
-- Get this scripts name for the 'on quit' handler below.
set scriptPath to path to me
set scriptNameFull to name of file scriptPath as text


-- Get name of this script, minus the extension
if (offset of "." in scriptNameFull) > 0 then
set gScriptName to (text items 1 thru -2 of scriptNameFull) as string
end if
end tell


tell application "System Events"
tell process gScriptName
keystroke "h" using command down -- Hide this script in the Dock
end tell
end tell

tell application "Mail"
activate
delay 10 -- wait for Mail to redraw the screen before checking for new mail (to prevent possible crash?)
check for new mail
set theMinimumInterval to 0
set theAccountList to ¬
{¬
{account "info" of application "Mail", 15}, ¬
{account "AdSense" of application "Mail", 90}, ¬
{account "PayPal" of application "Mail", 60}, ¬
                           -- other Mail accounts listed here
}

set theCount to 0
repeat with eachAccount in theAccountList
set theInterval to item 2 of eachAccount
if theInterval ≠ 0 then
set theCount to theCount + 1
if (theCount > 1) then
set theMinimumInterval to my gcd(theInterval, theMinimumInterval)
else
set theMinimumInterval to (theInterval as integer)
end if
end if
end repeat
if theMinimumInterval = 0 then
display dialog "No accounts have been set to check (values greater than 0)."
return
end if
set theMinuteCount to 0
repeat
delay (theMinimumInterval * 60)
set theMinuteCount to theMinuteCount + theMinimumInterval
repeat with eachAccount in theAccountList
set theAccount to item 1 of eachAccount
set theInterval to item 2 of eachAccount
if theInterval ≠ 0 then
set theMod to theMinuteCount mod theInterval
if (theMod = 0) then
check for new mail for theAccount
end if
end if
end repeat
end repeat
end tell



on gcd(a, b)
repeat until b = 0
set x to b
set b to a mod b
set a to x
end repeat
return a
end gcd

on quit
try
set theCommand to "ps axuww | grep '" & gScriptName & "' | grep -v grep | awk '{ print $2 }'"
set myPID to do shell script theCommand
do shell script "kill " & myPID
continue quit
end try
end quit

Without the 'on quit' do shell script code, this script is not able to be quit using Cmd-Q.

If there's a better way to accomplish what I'm after, I'm all ears.

Thanks again,
Ted
 _______________________________________________
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: Application Bundle won't quit at Shutdown
      • From: Yvan KOENIG <email@hidden>
    • Re: Application Bundle won't quit at Shutdown
      • From: "Stockly, Ed" <email@hidden>
References: 
 >Re: Application Bundle won't quit at Shutdown (From: has <email@hidden>)

  • Prev by Date: Re: Application Bundle won't quit at Shutdown
  • Next by Date: Re: Application Bundle won't quit at Shutdown
  • Previous by thread: Re: Application Bundle won't quit at Shutdown
  • Next by thread: Re: Application Bundle won't quit at Shutdown
  • Index(es):
    • Date
    • Thread