Я пишу AppleScript:
- чтобы проверить, выходят ли файлы двух конкретных словарей (File1 и File2) в
/Library/Dictionaries/
- если какой-либо из двух файлов выйдет, полностью удалите этот файл, а другой
Скрипт отлично работает в редакторе AppleScript. Затем я сохраняю скрипт как приложение, тестирую его, и приложение также работает нормально. Я имею в виду, что и скрипт в редакторе AppleScript, и сохраненное приложение обнаруживают и удаляют файлы File1 и File2 из /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