我写了一个 AppleScript:
- 检查两个特定的字典(File1 和 File2)文件是否退出
/Library/Dictionaries/
- 如果两个文件中的任何一个存在,则完全删除该文件和另一个
该脚本在 AppleScript 编辑器中运行良好。然后我将脚本保存为应用程序,对其进行测试,该应用程序也可以正常工作。我的意思是 AppleScript 编辑器中的脚本和保存的应用程序都检测并从/Library/Dictionaries/
.
然而,在 PackageMaker Post Action 中,调用时,应用程序既不会删除 File1 也不会删除 File2,尽管它会检测到它们,甚至会显示对话框消息(请参见下面的代码行)。
这是代码:
tell application "System Events"
if exists (application process "Dictionary") then
tell application "Dictionary" to quit
end if
end tell
try
set theOtherFile1 to POSIX file "/Library/Dictionaries/File1.dictionary"
set theOtherFile2 to POSIX file "/Library/Dictionaries/File2.dictionary"
tell application "Finder"
if exists file theOtherFile1 then
display dialog "File1/File2 exits. Do you want to remove it?" with title "Note" buttons {"No", "Yes"} default button "Yes"
if the button returned of the result is "No" then
delay 2
else
do shell script "rm -R /Library/Dictionaries/File1.dictionary" with administrator privileges
do shell script "rm -R /Library/Dictionaries/File2.dictionary" with administrator privileges
end if
end if
end tell
end try
delay 5
tell application "Dictionary" to activate