2012-06-27 7 views
1

기본적으로 Automator에서 폴더 작업을 만들려고합니다. 특정 폴더에 파일이 추가 될 때마다 파일 이름과 일치하는 하위 폴더가 만들어집니다 (확장자 없음) 파일을 해당 하위 폴더로 이동하십시오.AppleScript : 파일 이름에서 새 폴더를 만들고 해당 폴더로 파일을 이동하십시오.

지금까지이 사이트의 게시물 (Create new folder named with a specified file name in Automator)을 사용하여 새 폴더를 만들 스크립트를 만들었습니다. 그러나 원본 파일을 새 폴더로 옮기려면 스크립트를 수정할 수 없었습니다.

도움을 주시면 감사하겠습니다. 다음은 참조 용으로 작성한 전체 스크립트입니다.

on run {input, parameters} -- make new folders from base file names 

    set output to {} 

    repeat with anItem in the input -- step through each item in the input 

     set anItem to anItem as text 
     tell application "System Events" to tell disk item anItem 
      set theContainer to path of container 
      set {theName, theExtension} to {name, name extension} 
     end tell 
     if theExtension is in {missing value, ""} then 
      set theExtension to "" 
     else 
      set theExtension to "." & theExtension 
     end if 
     set theName to text 1 thru -((count theExtension) + 1) of theName -- the name part 

     tell application "Finder" 
      make new folder at folder theContainer with properties {name:theName} 
      set end of output to result as alias 
     end tell 
    end repeat 

    return input -- or output 
end run 

미리 감사드립니다.

답변

2

대상 폴더에이 폴더에 액션을 추가

on adding folder items to theFolder after receiving theFiles 
    repeat with aFile in theFiles 
     tell application "System Events" to set {Nm, Ex, pPath} to aFile's {name, name extension, POSIX path of container} 
     set BN to text 1 thru ((get offset of "." & Ex in Nm) - 1) of Nm 
     set thePath to (pPath & "/" & BN & "/" as text) 
     do shell script "mkdir -p " & quoted form of thePath 
     delay 0.5 
     tell application "Finder" to move aFile to POSIX file thePath 
    end repeat 
end adding folder items to 
관련 문제