I write an AppleScript:
- to check if two specific dictionaries (File1 and File2) files exit in
/Library/Dictionaries/
- if either of the two files exits, then completely delete that file and the other
The script works fine in AppleScript Editor. I then save the script as an app, test it, and the app also works just fine. I mean both the script in AppleScript Editor and the saved app detect and remove both File1 and File2 from /Library/Dictionaries/
.
However in PackageMaker Post Action, when called, the app removes neither File1 nor File2 although it detects them and even shows the dialog message (see code line below).
Here is the code:
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