2011-07-27 11 views
0

/MacintoshのHD /ライブラリ/スクリプト/フォルダアクション... /フォルダにnew item alert.scptというファイルを編集しました。私はいくつかの権限を編集した後にそれを保存することができましたが、RunまたはCompileをクリックすると何も起こりません。編集したリンスクリプトの問題

これは一般的なエラーですか、または誰かが気にしない場合は私のappleescriptに問題がありますか?

property Docs : "Macintosh HD:Users:Max:Downloads:Docs" 
property Music : "Macintosh HD:Users:Max:Downloads:Music" 
property Videos : "Macintosh HD:Users:Max:Downloads:Videos" 
property Images : "Macintosh HD:Users:Max:Downloads:Images" 
property Profiles : "Macintosh HD:Users:Max:Downloads:iPhone:Profiles" 
property Zips : "Macintosh HD:Users:Max:Downloads:Zips" 
property PSDs : "Macintosh HD:Users:Max:Downloads:PSDs" 

on adding folder items to this_folder after receiving added_items 
    try 
     tell application "Finder" 
      --get the name of the folder 
      set the folder_name to the name of this_folder 
      if (name of eachitem ends with ".png") then 
       move eachitem to folder Images 
      end if 
      if (name of eachitem ends with ".JPEG") then 
       move eachitem to folder Images 
      end if 
      if (name of eachitem ends with ".gif") then 
       move eachitem to folder Images 
      end if 
      if (name of eachitem ends with ".jpg") then 
       move eachitem to folder Images 
      end if 
      if (name of eachitem ends with ".jpeg") then 
       move eachitem to folder Images 
      end if 
      if (name of eachitem ends with ".PNG") then 
       move eachitem to folder Images 
      end if 
      if (name of eachitem ends with ".mov") then 
       move eachitem to folder Videos 
      end if 
      if (name of eachitem ends with ".avi") then 
       move eachitem to folder Videos 
      end if 
      if (name of eachitem ends with ".wma") then 
       move eachitem to folder Videos 
      end if 
      if (name of eachitem ends with ".m4v") then 
       move eachitem to folder Videos 
      end if 
      if (name of eachitem ends with ".mp4") then 
       move eachitem to folder Music 
      end if 
      if (name of eachitem ends with ".mp3") then 
       move eachitem to folder Music 
      end if 
      if (name of eachitem ends with ".wav") then 
       move eachitem to folder Music 
      end if 
      if (name of eachitem ends with ".wma") then 
       move eachitem to folder Music 
      end if 
      if (name of eachitem ends with ".pdf") then 
       move eachitem to folder Docs 
      end if 
      if (name of eachitem ends with ".doc") then 
       move eachitem to folder Docs 
      end if 
      if (name of eachitem ends with ".docx") then 
       move eachitem to folder Docs 
      end if 
      if (name of eachitem ends with ".pages") then 
       move eachitem to folder Docs 
      end if 
      if (name of eachitem ends with ".ppt") then 
       move eachitem to folder Docs 
      end if 
      if (name of eachitem ends with ".pptx") then 
       move eachitem to folder Docs 
      end if 
      if (name of eachitem ends with ".mobileprovision") then 
       move eachitem to folder Profiles 
      end if 
      if (name of eachitem ends with ".zip") then 
       move eachitem to folder Zips 
      end if 
      if (name of eachitem ends with ".psd") then 
       move eachitem to folder PSDs 
      end if 


     end tell 

     -- find out how many new items have been placed in the folder 
     set the item_count to the number of items in the added_items 
     --create the alert string 
     set alert_message to ("Folder Actions Alert:" & return & return) as Unicode text 
     if the item_count is greater than 1 then 
      set alert_message to alert_message & (the item_count as text) & " new items have " 
     else 
      set alert_message to alert_message & "One new item has " 
     end if 
     set alert_message to alert_message & "been placed in folder " & «data utxt201C» & the folder_name & «data utxt201D» & "." 
     set the alert_message to (the alert_message & return & return & "Would you like to view the added items?") 

     display dialog the alert_message buttons {"Yes", "No"} default button 2 with icon 1 giving up after dialog_timeout 
     set the user_choice to the button returned of the result 

     if user_choice is "Yes" then 
      tell application "Finder" 
       --go to the desktop 
       activate 
       --open the folder 
       open this_folder 
       --select the items 
       reveal the added_items 
      end tell 
     end if 
    end try 
end adding folder items to 

答えて

0

フォルダアクションスクリプトは直接実行されていません。これらのフォルダのコンテキストメニューから任意の数のフォルダに関連付けられます。

次に、そのフォルダの内容が変更されると、スクリプトがトリガされ、on adding folder items toハンドラが実行されます。

したがって、スクリプトを添付するフォルダを右クリックし、Set folder actionメニュー項目を選択するだけです。

また、システム提供のファイルを上書きする必要はありません。カスタマイズしたバージョンを自分のホームディレクトリに保存して、任意のフォルダに添付することができます。

+0

私はちょうどそれをしたとして新しいスクリプトを作成しました私はフォルダに項目を追加するたびに、何も起こりません。私が間違って何をしているのか?私はちょうど私がこのファイルを見たいかどうか尋ねる警告を得る。あなたのスクリプトは、行の後に '警告STRING'がやっている--create正確に何 –

+0

。したがって、あなたのコードは少なくともフォンダのアクションによって起動されますが、あなたのコードはあなたがやろうとしていることをしていません。私はそれはあなただけ求めているものの独立したスタックオーバーフロー上の別の質問、する必要があります推測します... – Yuji

0

フォルダーアクションハンドラーが自動的に失敗するため、エラーが発生するとスクリプトは中止されます。あなたの投稿されたスクリプトでは、追加された項目を一切通らず、未定義の変数 - eachitemを使用しています。 の文を使用してエラー()を実行すると、デバッグに役立たないすべてのエラーが発生します。私はあなたがアップルのサンプルスクリプトの1つを使用していることを知っていますが、それはかなり古いです。

私はそれはまた、(スクリプトがする必要はありません正常に実行できるようにフォルダアクションを使用して最善のアプローチは、フォルダアクションハンドラの外にスクリプトの主要部分(複数可)を置くことであることを見つけましたフォルダアクションに専念する) - これはデバッグに役立ち、アプレットまたはドロップレットを与えることもできます。テストのために、フォルダアクションハンドラの宣言をコメントアウトし、ステートメントを追加してフォルダとファイルを取得することもできます。

私はあなたが気にしないことを望むが、私はそれがまた、スクリプトエディタから実行することができるように、スクリプトを再配置の自由を取った:

property Docs : "Macintosh HD:Users:Max:Downloads:Docs" 
property Music : "Macintosh HD:Users:Max:Downloads:Music" 
property Videos : "Macintosh HD:Users:Max:Downloads:Videos" 
property Images : "Macintosh HD:Users:Max:Downloads:Images" 
property Profiles : "Macintosh HD:Users:Max:Downloads:iPhone:Profiles" 
property Zips : "Macintosh HD:Users:Max:Downloads:Zips" 
property PSDs : "Macintosh HD:Users:Max:Downloads:PSDs" 

property dialogTimeout : 10 


on run -- script run as an application or from the Script Editor 
    set someFiles to (choose file with multiple selections allowed) -- manually get some files 
    tell application "Finder" to set containingFolder to (container of first item of someFiles) as alias 
    doStuff(containingFolder, someFiles) 
end run 


on adding folder items to this_folder after receiving added_items -- folder action handler 
    doStuff(this_folder, added_items) 
end adding folder items to 


on doStuff(theFolder, theStuff) -- do stuff with file items in a folder 
    set numberOfItems to (count theStuff) 
    tell application "Finder" 
     set folderName to name of theFolder 
     repeat with anItem in theStuff 
      if name extension of anItem is in {"png", "jpg", "jpeg", "gif"} then 
       move anItem to folder Images 
      else if name extension of anItem is in {"mov", "avi", "wma", "m4v"} then 
       move anItem to folder Videos 
      else if name extension of anItem is in {"mp4", "mp3", "wav", "wma"} then 
       move anItem to folder Music 
      else if name extension of anItem is in {"pdf", "doc", "docx", "pages", "ppt", "pptx"} then 
       move anItem to folder Docs 
      else if name extension of anItem is in {"mobileprovision"} then 
       move anItem to folder Profiles 
      else if name extension of anItem is in {"zip"} then 
       move anItem to folder Zips 
      else if name extension of anItem is in {"psd"} then 
       move anItem to folder PSDs 
      else 
       -- no match, so leave it 
      end if 
     end repeat 
    end tell 

    -- create the alert string 
    set alertText to ("Folder Actions Alert:" & return & return) as Unicode text 
    if numberOfItems is greater than 1 then 
     set alertText to alertText & numberOfItems & " new items have " 
     set plural to "s" 
    else 
     set alertText to alertText & "One new item has " 
     set plural to "" 
    end if 
    set alertText to alertText & "been added to the folder " & «data utxt201C» & folderName & «data utxt201D» & "." 
    set alertText to alertText & return & return & "Would you like to view the added item" & plural & "?" 

    display dialog alertText buttons {"Yes", "No"} default button 2 with icon 1 giving up after dialogTimeout 

    if (button returned of the result) is "Yes" then tell application "Finder" 
     activate 
     -- open theFolder 
     reveal theStuff 
    end tell 
end doStuff 
関連する問題