2011-07-27 2 views
0

방금 ​​/ Macintosh HD/라이브러리/스크립트/폴더 작업 .../폴더에서 new item alert.scpt 파일을 편집했습니다. 일부 사용 권한을 편집 한 후에 저장했지만, Run 또는 Compile을 클릭해도 아무런 변화가 없습니다.수정 된 AppleScript의 문제

일반적인 오류입니까, 아니면 누군가가 신경 쓸 필요가없는 경우 내 AppleScript에 문제가 있습니까?

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

난 그냥 그랬와 함께 새로운 스크립트를 생성 코드를 넣지 만 폴더에 항목을 추가 할 때마다 아무 일도 일어나지 않습니다. 내가 뭘 잘못하고 있는거야? 이 파일을보고 싶은지 묻는 경고 메시지가 나타납니다. –

+0

바로'--creatate the alert string' 행이 스크립트를 작성한 것과 같습니다. 따라서 코드는 최소한 포더 액션에 의해 시작되지만 코드는 의도 한대로 행동하지 않습니다. 스택 오버플로에 대한 또 다른 질문인데, 방금 물어 본 것과 관계가 없습니다. – Yuji

0

폴더 작업 처리기가 자동으로 실패하므로 오류가 있으면 스크립트가 중단됩니다. 게시 된 스크립트에서는 추가 된 항목을 전혀 검토하지 않고 정의되지 않은 변수 eachitem을 사용하고 있습니다. 또한 진술 부분에 없이 진술을 사용하면 디버깅에도 도움이되지 않는 모든 오류가 발생합니다. 나는 당신이 애플의 예제 스크립트 중 하나를 사용하고 있다는 것을 알고 있지만, 꽤 오래되었다.

폴더 작업을 사용할 때 가장 좋은 방법은 폴더 작업 처리기 외부에서 스크립트의 주요 부분을 배치하여 정상적으로 실행할 수 있도록하는 것입니다 (스크립트를 실행할 필요가 없습니다). 폴더 작업을하는 데 전념해야합니다.) - 디버깅에 도움이되며 애플릿 또는 드롭 릿을 제공 할 수도 있습니다. 테스트를 위해 폴더 작업 처리기 선언을 주석으로 처리하고 명령문을 추가하여 폴더와 파일을 가져올 수도 있습니다.

난 당신이 생각하지 않았 으면,하지만 그것은 또한 스크립트 편집기에서 실행할 수 있도록 스크립트를 재 배열의 자유를했다 :

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