2010-07-28 3 views
1

Automators에서 AppleScript 코드를 사용하여 파일의 확장자를 얻는 방법이 있는지 궁금 해서요. 특정 확장명 (예 : .pdf 또는 .rtf)이 특정 폴더로 이동하면 (예 : if (extension == pdf) { move to folder "~/PDF Files" } else if (extension == rtf) { move to folder "~/Rich Text Files" })Automator/Applescript 파일 정렬 및 이동

답변

3

다음은 applescript입니다. 귀하의 요청이 간단했기 때문에 나는 그것을 당신을 위해 썼습니다. "getNameAndExtension (F)"서브 루틴을 사용하여 파일 확장명을 얻는 방법에 유의하십시오. 일반적으로 Finder (이름 확장명)에서 파일 확장명을 가져올 수 있지만 파인더가 항상 신뢰할 수있는 것은 아니므로 항상이 서브 루틴을 사용합니다. 그 서브 루틴은 항상 신뢰할 만했습니다.

set homeFolder to path to home folder as text 
set rtfFolderName to "Rich Text Files" 
set pdfFolderName to "PDF Files" 

-- choose the files 
set theFiles to choose file with prompt "Choose RTF or PDF files to move into your home folder" with multiple selections allowed 

-- make sure the folders exist 
tell application "Finder" 
    if not (exists folder (homeFolder & rtfFolderName)) then 
     make new folder at folder homeFolder with properties {name:rtfFolderName} 
    end if 
    if not (exists folder (homeFolder & pdfFolderName)) then 
     make new folder at folder homeFolder with properties {name:pdfFolderName} 
    end if 
end tell 

-- move the files 
repeat with aFile in theFiles 
    set fileExtension to item 2 of getNameAndExtension(aFile) 
    if fileExtension is "rtf" then 
     tell application "Finder" 
      move aFile to folder (homeFolder & rtfFolderName) 
     end tell 
    else if fileExtension is "pdf" then 
     tell application "Finder" 
      move aFile to folder (homeFolder & pdfFolderName) 
     end tell 
    end if 
end repeat 



(*=============== SUBROUTINES ===============*) 
on getNameAndExtension(F) 
    set F to F as Unicode text 
    set {name:Nm, name extension:Ex} to info for file F without size 
    if Ex is missing value then set Ex to "" 
    if Ex is not "" then 
     set Nm to text 1 thru ((count Nm) - (count Ex) - 1) of Nm 
    end if 
    return {Nm, Ex} 
end getNameAndExtension 
0

나는 지금 내 애플이 아니기 때문에 Automator를 가지고 놀 수는 없다. 그러나 Finder를 목록보기로 전환하여 유형별로 정렬 한 다음 동일한 유형의 파일 블록을 선택하고 올바른 폴더로 드래그하면됩니다.