我想知道在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. 排序動態拉文件
- 2. Pyro和文件排序
- 3. 排序和uniq csv文件
- 4. 索引列表和排序文件和文件夾排除PHP
- 5. 刪除和移動文件
- 6. cx_Freeze和移動文件
- 7. 移動庫和頭文件
- 8. 用特定名稱移動所有文件(排序)WINDOWS 8
- 9. 如何移動文件夾和文件?
- 10. Powershell移動文件和文件夾
- 11. 排序文件排序
- 12. jQuery UI:可排序和可拖動的排序和排序
- 13. perl中排序和uniq文本文件
- 14. 排序文件
- 15. 排序文件
- 16. 排序文件
- 17. 排序文件
- 18. 排序文件?
- 19. 排序文件
- 20. Searchkick - 動態排序和排序
- 21. 移動文件
- 22. 移動文件
- 23. 移動文件
- 24. 移動文件
- 25. jquery的拖動和排序無插件
- 26. 從http鏈接解析信息,移動和重新排序文件進行分類文件夾
- 27. 文件和文件夾迭代器,默認排序順序。
- 28. Python入門程序:移動文件
- 29. 程序無法移動文件
- 30. 程序在文件移動時終止