【发布时间】:2012-06-17 11:44:18
【问题描述】:
我写了一个 AppleScript:
- 检查两个特定字典(File1 和 File2)文件是否存在于
/Library/Dictionaries/中 - 如果两个文件中的任何一个存在,则完全删除该文件和另一个
脚本在 AppleScript 编辑器中运行良好。然后我将脚本保存为应用程序,对其进行测试,该应用程序也可以正常工作。我的意思是 AppleScript 编辑器中的脚本和保存的应用程序都从/Library/Dictionaries/ 中检测并删除 File1 和 File2。
但是,在 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
【问题讨论】:
-
是退出 Dictionary.app,还是脚本根本没有运行?
-
谢谢。从 AppleScript 编辑器运行时,该脚本运行良好。我将此脚本保存到应用程序中,直接启动(单击)时,该应用程序也可以正常工作。但是,当 PackageMaker Post Action 调用此应用程序时,它似乎正在运行,但不会删除 File1 和/或 File2。奇怪的是,它关闭 Dictionary.app,显示 File1/File2 存在的对话框,然后重新启动 Dictionary.app 但无法删除 File1/File2。