1

私はAppleScriptを書きます:

  1. 2 つの特定の辞書 (File1 と File2) ファイルが存在するかどうかを確認するには/Library/Dictionaries/
  2. 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
4

1 に答える 1

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を使用しています。それ以外の場合は最初に確認しますが、これは正しく動作すると思います。

于 2012-10-17T13:56:56.040 に答える