我使用 PackageMaker 创建安装包。以下是我preinstall script
要被调用的Installer
:
#!/bin/sh
/usr/bin/osascript <<EOF
tell application "System Events"
if exists (application process "Dictionary") then
tell application "Dictionary" to quit
end if
end tell
set theFolder to (path to library folder as text) & "Dictionaries:"
set fileNames to {"dict1.dictionary", "dict2.dictionary", "dict3.dictionary", "dict_n.dictionary"}
set dict to {}
repeat with aFile in fileNames
tell application "Finder"
if exists file (theFolder & aFile as text) then set end of dict to aFile & return
end tell
end repeat
try
tell application "System Events"
if dict ≠ {} then display alert "You have XYZ installed" message "Choose 'Upgrade' to install the new version or 'Cancel' if you want to stay with the current version." & return & dict buttons {"Cancel", "Upgrade"} default button "Upgrade"
if the button returned of the result is "Cancel" then
tell current application
set app_name to "Installer"
set the_pid to (do shell script "ps ax | grep " & (quoted form of app_name) & " | grep -v grep | awk '{print $1}'")
if the_pid is not "" then do shell script ("kill -9 " & the_pid)
end tell
end if
end tell
end try
EOF
该脚本在 AppleScript 编辑器和终端中运行良好,即如果字典应用程序正在运行,它会关闭它,如果用户选择取消,它会强制退出安装程序。
但是,在安装过程中调用时,它只是部分运行:它关闭 Dictionary 应用程序,但在选择取消按钮时绕过强制退出安装程序。请注意,我已经完成chmod 755
了preinstall
文件。
我错过了什么?我做错了什么?你能帮忙吗?
非常感谢。