目标:将文件夹中的所有文件和文件移动到目标文件夹,并维护文件结构[文件和命名文件夹]。对于相册中的音乐文件很重要。
功能:使用串行/连续移动操作将SmartFolder [named]中列出的所有文件移动到destinationFolder,并维护SmartFolder中列出的相同文件结构和dataFiles副本。
密钥:获取所有文件以进行传输。正常CMD + A,CMD + C,CMD + V挂起计算机并且传输不会启动。将每个dataObject移动到destinationPath的AppleScript就是全部。
事实:如何引用对象[文件,文件夹]及其正确的引用格式和接受的路径语法; path或POSIX,以及别名的使用。基本操作。我运行AppleScript将filePath移动到pathDestination,否则成功,并且很高兴知道路径引用的形式化语法。
tell application "Finder"
move allFiles to destinationFolder
// recursive/repeat code to loop through all listed files and folder
end tell
参考:Applescript, show all files with tag [从'smartfolder'容器中移动/选择列出的文件作为活动窗口和displayLists。这是一个alt。解决方案,因为AppleScript不会将SmartFolder作为对象引用,也不会动态调用SmartFolder对象的listProperty,除非通过未知或非引用方法或命令调用。
由于你的主要问题,据我所知,似乎正在处理AppleScript中的SmartFolders,正如你所说的那样 - 不能被引用为文件夹对象,这个小片段可能会有所帮助:
set SmartFolder to "/Users/CK/My Smart Folder.savedSearch"
tell application "System Events" to get value of property list file SmartFolder
set {[Scope], Query} to {SearchScopes, RawQuery} of RawQueryDict of result
set AppleScript's text item delimiters to tab
set Command to {"mdfind -onlyin", ¬
quoted form of Scope as text, ¬
quoted form of Query as text} as text
set SearchResults to paragraphs of (do shell script Command)
--> returns a list of posix files
--> e.g. {"/Users/CK/Downloads/This is file one.txt", ...}
这将返回与搜索条件匹配的文件的POSIX路径列表。
我建议使用系统事件而不是Finder来处理大量文件。它还可以处理posix路径,而无需手动将它们强制转换为别名或其他任何东西。因此,给定posix路径,例如使用上面的代码片段在列表中返回的路径,您只需执行以下操作:
set myfile to item 1 of SearchResults
tell application "System Events" to move myfile to "/Users/CK/Desktop"
在不知道智能文件夹包含的更多详细信息的情况下(因为有些搜索可以轻松返回文件夹以及该文件夹的内容,当您通过搜索结果获取AppleScript时必须记住该文件夹),我可以'给你更多。但是,你说你的主要问题是无法处理SmartFolders而不知道如何引用文件/文件夹。
这适用于我使用最新版本的Sierra。
将property moveToNewFolder
to的值设置为您选择的目标文件夹
此脚本创建“从列表中选择”对话框,允许您选择驻留在系统上的任何智能文件夹。然后,它会将所选智能文件夹中的所有这些文件和文件夹移动到您设置的目标文件夹。
property savedSearches : (path to home folder as string) & "Library" & ":Saved Searches"
property savedSearchesSubFolders : {}
property namesOfSavedSearchesSubFolders : {}
property selectedSearchFolder : ""
property selectedSearchFolderPath : missing value
property moveTheseItems : missing value
property moveToNewFolder : (path to desktop as text) & "untitled folder" -- change this value to your preferred destination folder
tell application "Finder"
activate
delay 0.1 -- may need to adjust delay time value
open savedSearches
delay 0.1 -- may need to adjust delay time value
reveal savedSearches
delay 0.1 -- may need to adjust delay time value
select savedSearches
delay 0.1 -- may need to adjust delay time value
set current view of Finder window 1 to column view
delay 0.1 -- may need to adjust delay time value
tell its Finder window (POSIX path of savedSearches)
delay 0.1 -- may need to adjust delay time value
set savedSearchesSubFolders to items
set namesOfSavedSearchesSubFolders to name of items
-- Allows to choose any smart folder from a list of all smart folders
set selectedSearchFolder to choose from list namesOfSavedSearchesSubFolders ¬
with title ¬
"Smart Search Folders" with prompt ¬
"Choose Your Folder" OK button name ¬
"OK" cancel button name "CANCEL"
set selectedSearchFolder to selectedSearchFolder as text
set selectedSearchFolderPath to savedSearches & ":" & selectedSearchFolder
set selectedSearchFolderPath to selectedSearchFolderPath as string
end tell
delay 0.2 -- may need to adjust delay time value
select selectedSearchFolderPath
tell Finder window 1
set defaultView to current view
set current view to list view
delay 0.1 -- may need to adjust delay time value
set current view to defaultView
delay 0.5 -- may need to adjust delay time value
tell application "System Events"
key code 0 using command down
end tell
end tell
set moveTheseItems to selection
end tell
tell application "Finder"
set resultObject to move moveTheseItems ¬
to moveToNewFolder ¬
with replacing
end tell