我正在为我的应用程序创建一个命令行工具。它使用pkgbuild
和productbuild
创建包。它是一个launchdaemon
二进制文件。我有preinstall
和postinstall
脚本。
安装后,可能在postinstall
脚本中,我需要检测 Firefox 是否正在运行,然后提示用户他需要重新启动 Firefox。有可能这样做吗?如何?
脚本的一些摘录,它是安装后脚本的一部分。
.........
## Check if Firefox is running in the background with no tab/window open.
function restart_empty_firefox (){
echo "Restarting firefox if no tab is opened. "
firefoxRunning=$(osascript \
-e 'tell application "System Events" to set fireFoxIsRunning to ((count of (name of every process where name is "Firefox")) > 0)' \
-e 'if fireFoxIsRunning then' \
-e 'set targetApp to "Firefox"' \
-e 'tell application targetApp to count (every window whose (closeable is true))' \
-e 'else' \
-e 'return 0' \
-e 'end if')
if [ $firefoxRunning -eq 0 ]; then
echo 'Firefox is in the background with no window and so quitting ...'
osascript -e 'quit app "Firefox"'
else
##### show a dialog to the user to restart Firefox
fi
}
firefox_update # not shown here
restart_empty_firefox
.............