I have two scripts that open and close an app; let's say it's the builtin
Calculator.app. The "start" script uses
/usr/bin/open to launch the app, then a one-line AppleScript to set the app's visibility to
This is the entirety of the "stop" script:
#!/bin/bash osascript -e 'tell app "Calculator" to quit'
I am running these scripts from a LaunchDaemon that calls them at certain fixed times of the week.
The strange behavior I'm seeing is that sometimes, after the "stop" script runs, the app's Dock icon retains its little dot (suggesting it's still running). However:
- right-clicking the Dock icon shows "Application not responding"
- force-quitting via the Dock icon's menu does nothing
psdoes not show any Calculator process running
And, most bafflingly, trying to launch Calculator again (via
open, via Spotlight, or by double-clicking its icon) produces a modal dialog that says The application "Calculator" is not open anymore.
lsof shows these entries that might be related:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME Spotlight 443 jteach 54r DIR 1,4 102 28977573 /Applications/Calculator.app Notificat 476 jteach txt REG 1,4 37933 29214948 /System/Library/Frameworks/NotificationCenter.framework/PlugIns/com.apple.ncplugin.calculator.appex/Contents/Resources/Assets.car Notificat 476 jteach 8r REG 1,4 37933 29214948 /System/Library/Frameworks/NotificationCenter.framework/PlugIns/com.apple.ncplugin.calculator.appex/Contents/Resources/Assets.car
- Why might my "stop" script be failing to make the app exit cleanly?
- Short of rebooting, is there a way I can get the app out of this zombie state?
- How can I alter my script to be sure that the app quits properly?