我想知道在Automator中是否有方法使用Applescript代码来获取文件的扩展名,并且如果它等于特定的扩展名(例如.pdf
或.rtf
)移动到特定的文件夹对于该扩展(例如if (extension == pdf) { move to folder "~/PDF Files" } else if (extension == rtf) { move to folder "~/Rich Text Files" }
)Automator/Applescript文件排序和移动
1
A
回答
3
这是一个applescript。既然你的要求很简单,我就为你写了。请注意我如何使用子例程“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
0
我现在不在我的苹果,所以我不能玩Automator和弄清楚。但是,如果您可以通过将查找器切换到列表视图来执行此操作,请按类型进行排序,然后选择相同类型的文件块并将它们拖到正确的文件夹中。
相关问题
- 1. Pyro和文件排序
- 2. 排序和uniq csv文件
- 3. cx_Freeze和移动文件
- 4. 移动库和头文件
- 5. Powershell移动文件和文件夹
- 6. 排序文件
- 7. 排序文件
- 8. 排序文件?
- 9. 排序文件
- 10. 移动文件
- 11. 移动文件
- 12. 移动文件
- 13. Searchkick - 动态排序和排序
- 14. 从http链接解析信息,移动和重新排序文件进行分类文件夹
- 15. 程序在文件移动时终止
- 16. Python入门程序:移动文件
- 17. Mootools可排序 - 向上/向下移动
- 18. 拖放Javascript可移动标记排序?
- 19. 恢复mootools可排序移动
- 20. 李在排序列表中移动
- 21. 排序表,但使一列不移动
- 22. 排序文件内容和文件大小4GB和RAM 2 GB
- 23. Linux grep和排序日志文件
- 24. 分组和排序的文件在python
- 25. 读取,合并和排序.csv文件
- 26. 读取文件和排序标志着
- 27. 如何排序和文件夹
- 28. c#加载csv文件和排序列
- 29. NetBeans和Mercurial - 移动/删除文件和文件夹
- 30. tcl排序文件