我想知道 Automator 中是否有一种方法可以使用 Applescript 代码来获取文件的扩展名,以及它是否等于特定扩展名(例如.pdf
或.rtf
)移动到该扩展名的特定文件夹(例如if (extension == pdf) { move to folder "~/PDF Files" } else if (extension == rtf) { move to folder "~/Rich Text Files" }
)
问问题
3506 次
2 回答
3
这是一个苹果脚本。由于您的要求很简单,我只是为您写了它。请注意我如何使用子例程“getNameAndExtension(F)”获取文件扩展名。通常您可以从 Finder 中获取文件扩展名(称为扩展名),但我发现 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
于 2010-07-29T12:30:41.290 回答
0
我现在不在我的苹果公司,所以我不能玩 Automator 并弄清楚它。但是,如果您可以通过将查找器切换到列表视图来执行此操作,请按类型排序,然后选择相同类型的文件块并将它们拖到正确的文件夹中。
于 2010-07-28T18:16:58.663 回答