• 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: best approach?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: best approach?


  • Subject: Re: best approach?
  • From: Shane Stanley <email@hidden>
  • Date: Tue, 08 Dec 2015 13:06:27 +1100

On 8 Dec 2015, at 12:31 PM, Dee Dee <email@hidden> wrote:

For example, if I have an applescript send a command to the app and the applescript times out (because the app has become unresponsive), is it possible to have applescript then test to see if the app is unresponsive and if so, to quit it, then restart the app?

Sure. You trap the timeout error in a try block, and then you have a choice of using do shell script and killall, or something like the following (10.9 and up, in a script library in 10.9):

use scripting additions
use framework "Foundation"
use framework "AppKit"

my forceQuitAppID:"com.apple.mail"

on forceQuitAppID:theID
set theApp to (current application's NSRunningApplication's runningApplicationsWithBundleIdentifier:theID)'s firstObject()
set theURL to theApp's bundleURL()
theApp's forceTerminate()
delay 0.5
current application's NSWorkspace's sharedWorkspace()'s openURL:theURL
end forceQuitAppID:


-- 
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>

 _______________________________________________
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: best approach?
      • From: 2551 <email@hidden>
References: 
 >best approach? (From: Dee Dee <email@hidden>)

  • Prev by Date: best approach?
  • Next by Date: Re: best approach?
  • Previous by thread: best approach?
  • Next by thread: Re: best approach?
  • Index(es):
    • Date
    • Thread