私はAppleScriptを書きます:
- 2 つの特定の辞書 (File1 と File2) ファイルが存在するかどうかを確認するには
/Library/Dictionaries/
- 2 つのファイルのいずれかが存在する場合は、そのファイルともう一方のファイルを完全に削除します。
スクリプトは AppleScript Editor で正常に動作します。次に、スクリプトをアプリとして保存してテストすると、アプリも問題なく動作します。AppleScript Editor のスクリプトと保存されたアプリの両方が、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