我写了一个AppleScript:
/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
答案 0 :(得分:0)
试试这个:
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 "Terminal" to activate
tell application "System Events"
keystroke ("sudo chmod 777 " & theOtherFile1) as string
display dialog "Click the button after you've typed the root password into Terminal." buttons {"OK"}
keystroke return
keystroke ("chmod 777 " & theOtherFile2) as string
display dialog "Click the button after you've typed the root password into Terminal." buttons {"OK"}
end tell
do shell script "rm -rf /Library/Dictionaries/File1.dictionary"
do shell script "rm -rf /Library/Dictionaries/File2.dictionary"
这应该可以解决问题。 我现在正在使用PC,否则我先检查,但我认为这将正常运行。