为什么这个预安装脚本只是部分运行?

时间:2012-09-08 17:21:21

标签: terminal applescript packagemaker osascript

我使用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应用程序,如果用户选择取消,则强制退出安装程序。

但是,在安装过程中调用时,它只是部分运行:它关闭了Dictionary应用程序,但是当选择“取消”按钮时绕过强制退出安装程序。请注意,我已完成chmod 755 preinstall个文件。

我错过了什么?我做错了什么?你能帮忙吗?

非常感谢。

0 个答案:

没有答案