2010-07-28 7 views
1

Je me demandais si il y avait un moyen dans Automator d'utiliser le code Applescript pour obtenir l'extension d'un fichier, et si elle est égale à une extension spécifique (par exemple .pdf ou .rtf) déplacer vers un dossier spécifique Pour cette extension (par exemple, if (extension == pdf) { move to folder "~/PDF Files" } else if (extension == rtf) { move to folder "~/Rich Text Files" })Automator/Applescript Fichier de tri et de déménagement

Répondre

3

Voici un applescript. Puisque votre demande était simple, je l'ai juste écrit pour vous. Notez comment j'obtiens l'extension de fichier avec le sous-programme "getNameAndExtension (F)". Normalement, vous pouvez obtenir l'extension de fichier à partir du Finder (appelé extension de nom) mais j'ai trouvé que le Finder n'est pas toujours fiable, donc j'utilise toujours ce sous-programme. Ce sous-programme a toujours été fiable.

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

Je ne suis pas chez Apple en ce moment, donc je ne peux pas jouer avec Automator et le comprendre. Mais si vous pouvez le faire en basculant le finder en vue de liste, triez par type, puis sélectionnez des blocs de fichiers du même type et faites-les glisser dans le bon dossier.