如何使用苹果脚本将文件夹移动到新位置
How to move folders to a new location with apple script
我不知道如何继续设置苹果脚本,将文件夹及其内容移动到新位置,这些文件夹可能已经存在。如果是这样,Finder 应该会覆盖这些文件夹。但在同一过程中,我也有特定文件,应该将其移动到新位置。我不明白如何让它发挥作用。
这些是我要移动和覆盖的文件和文件夹:
OLDFOLDER > 源,应该被目标覆盖 > NEWFOLDER
文件夹
- /Volumes/Netshare/Maxon/OLDFOLDER/library/scripts
- /Volumes/Netshare/Maxon/OLDFOLDER/Off_Plugins
文件夹
- /Users/name/Library/Preferences/MAXON/OLDFOLDER/library/browser
- /Users/name/Library/Preferences/MAXON/OLDFOLDER/prefs
文档(无结尾)
- /Users/name/Library/Preferences/MAXON/OLDFOLDER/prefs/xxx_net_80
- /Users/name/Library/Preferences/MAXON/OLDFOLDER/prefs/xxx_net_80_version4
文档(有结尾)
- /Users/name/Library/Preferences/MAXON/OLDFOLDER/prefs/c4d_M_GLOBAL_POPUP.res
如果能指导如何实现这一点,我将不胜感激。我之前尝试过一些研究,但没有取得进展...
最佳
这对我使用最新版本的 Sierra 很有效
-- Set The Variables To Your Folder Locations
set folderToBeMoved to (path to desktop as text) & "Folder_To_Move"
set destinationFolder to (path to desktop as text) & "New_Location"
-- Select Files You Want To Move To A Different Location
set filesToMove to choose file with prompt ¬
"Choose Files To Be Moved" invisibles false ¬
multiple selections allowed true ¬
without showing package contents
-- Move Files To Different Folder
tell application "Finder"
repeat with i from 1 to number of items in filesToMove
set this_item to item i of filesToMove
set moveFiles to move file this_item ¬
to destinationFolder ¬
with replacing
end repeat
end tell
-- Move Folder To Different Folder
tell application "Finder"
set moveFolder to move folder folderToBeMoved ¬
to destinationFolder ¬
with replacing
end tell
感谢@wch1zpink
我得到了必要的脚本来对我的案例进行一些改进。下面是它的工作原理,现在:
-- Set The Variables To Program Netshare Folder Locations
set NetsharePath to "Macintosh HD:Volumes:Netshare:Maxon:"
set NetshareFolderOrigin to NetsharePath & "19.044_RB221380"
set NetshareFolderDestination to NetsharePath & "Testfolder"
-- (path to desktop as text) & "New_Location"
set NetshareFoldersToMove to {":library:scripts", ":Off_Plugins", ":plugins"}
set NetshareSubfolderDestination to {":library", "", ""}
-- Move Netshare Folders To New Folders
tell application "Finder"
repeat with i from 1 to number of items in NetshareFoldersToMove
set folderToBeMoved to NetshareFolderOrigin & item i of NetshareFoldersToMove
set NetshareFolderDestinationCombination to NetshareFolderDestination & item i of NetshareSubfolderDestination
set netMoveFolder to move folder folderToBeMoved ¬
to NetshareDestinationFolderCombination ¬
with replacing
-- duplicate folderToBeMoved to NetshareFolderDestinationCombination
end repeat
end tell
-- Set The Variables To Preferences Folder Locations
set Username to "USER"
set PreferencesPath to "Macintosh HD:Users:" & Username & ":Library:Preferences:Maxon:"
set PreferencesFolderOriginName to "19.044_RB221380_FDCD4BE0"
set PreferencesFolderDestinationName to "Test"
set PreferencesPathOrigin to PreferencesPath & PreferencesFolderOriginName
set PreferencesPathDestination to PreferencesPath & PreferencesFolderDestinationName
set PreferencesFoldersToMove to {":_bugreports", ":bug.html", ":library:browser", ":library:layout", ":prefs:cache", ":prefs:directorycache",":prefs:c4d_M_GLOBAL_POPUP.res", ":prefs:CINEMA 4D.prf", ":prefs:shortcuttable.res", ":prefs:template.l4d", ":prefs:template.prf"}
set PreferencesSubfolderDestination to {"", "", ":library", ":library", ":prefs", ":prefs", ":prefs", ":prefs", ":prefs", ":prefs", ":prefs"}
-- Move Preferences Folders To new Folders
tell application "Finder"
repeat with i from 1 to number of items in PreferencesFoldersToMove
set prefFolderToBeMoved to PreferencesPathOrigin & item i of PreferencesFoldersToMove
set PreferencesDestinationFolderCombination to PreferencesPathDestination & item i of PreferencesSubfolderDestination
set prefMoveFolder to move folder prefFolderToBeMoved ¬
to PreferencesDestinationFolderCombination ¬
with replacing
-- duplicate prefFolderToBeMoved to PreferencesDestinationFolderCombination
end repeat
end tell
我不知道如何继续设置苹果脚本,将文件夹及其内容移动到新位置,这些文件夹可能已经存在。如果是这样,Finder 应该会覆盖这些文件夹。但在同一过程中,我也有特定文件,应该将其移动到新位置。我不明白如何让它发挥作用。
这些是我要移动和覆盖的文件和文件夹: OLDFOLDER > 源,应该被目标覆盖 > NEWFOLDER
文件夹
- /Volumes/Netshare/Maxon/OLDFOLDER/library/scripts
- /Volumes/Netshare/Maxon/OLDFOLDER/Off_Plugins
文件夹
- /Users/name/Library/Preferences/MAXON/OLDFOLDER/library/browser
- /Users/name/Library/Preferences/MAXON/OLDFOLDER/prefs
文档(无结尾)
- /Users/name/Library/Preferences/MAXON/OLDFOLDER/prefs/xxx_net_80
- /Users/name/Library/Preferences/MAXON/OLDFOLDER/prefs/xxx_net_80_version4
文档(有结尾)
- /Users/name/Library/Preferences/MAXON/OLDFOLDER/prefs/c4d_M_GLOBAL_POPUP.res
如果能指导如何实现这一点,我将不胜感激。我之前尝试过一些研究,但没有取得进展...
最佳
这对我使用最新版本的 Sierra 很有效
-- Set The Variables To Your Folder Locations
set folderToBeMoved to (path to desktop as text) & "Folder_To_Move"
set destinationFolder to (path to desktop as text) & "New_Location"
-- Select Files You Want To Move To A Different Location
set filesToMove to choose file with prompt ¬
"Choose Files To Be Moved" invisibles false ¬
multiple selections allowed true ¬
without showing package contents
-- Move Files To Different Folder
tell application "Finder"
repeat with i from 1 to number of items in filesToMove
set this_item to item i of filesToMove
set moveFiles to move file this_item ¬
to destinationFolder ¬
with replacing
end repeat
end tell
-- Move Folder To Different Folder
tell application "Finder"
set moveFolder to move folder folderToBeMoved ¬
to destinationFolder ¬
with replacing
end tell
感谢@wch1zpink
我得到了必要的脚本来对我的案例进行一些改进。下面是它的工作原理,现在:
-- Set The Variables To Program Netshare Folder Locations
set NetsharePath to "Macintosh HD:Volumes:Netshare:Maxon:"
set NetshareFolderOrigin to NetsharePath & "19.044_RB221380"
set NetshareFolderDestination to NetsharePath & "Testfolder"
-- (path to desktop as text) & "New_Location"
set NetshareFoldersToMove to {":library:scripts", ":Off_Plugins", ":plugins"}
set NetshareSubfolderDestination to {":library", "", ""}
-- Move Netshare Folders To New Folders
tell application "Finder"
repeat with i from 1 to number of items in NetshareFoldersToMove
set folderToBeMoved to NetshareFolderOrigin & item i of NetshareFoldersToMove
set NetshareFolderDestinationCombination to NetshareFolderDestination & item i of NetshareSubfolderDestination
set netMoveFolder to move folder folderToBeMoved ¬
to NetshareDestinationFolderCombination ¬
with replacing
-- duplicate folderToBeMoved to NetshareFolderDestinationCombination
end repeat
end tell
-- Set The Variables To Preferences Folder Locations
set Username to "USER"
set PreferencesPath to "Macintosh HD:Users:" & Username & ":Library:Preferences:Maxon:"
set PreferencesFolderOriginName to "19.044_RB221380_FDCD4BE0"
set PreferencesFolderDestinationName to "Test"
set PreferencesPathOrigin to PreferencesPath & PreferencesFolderOriginName
set PreferencesPathDestination to PreferencesPath & PreferencesFolderDestinationName
set PreferencesFoldersToMove to {":_bugreports", ":bug.html", ":library:browser", ":library:layout", ":prefs:cache", ":prefs:directorycache",":prefs:c4d_M_GLOBAL_POPUP.res", ":prefs:CINEMA 4D.prf", ":prefs:shortcuttable.res", ":prefs:template.l4d", ":prefs:template.prf"}
set PreferencesSubfolderDestination to {"", "", ":library", ":library", ":prefs", ":prefs", ":prefs", ":prefs", ":prefs", ":prefs", ":prefs"}
-- Move Preferences Folders To new Folders
tell application "Finder"
repeat with i from 1 to number of items in PreferencesFoldersToMove
set prefFolderToBeMoved to PreferencesPathOrigin & item i of PreferencesFoldersToMove
set PreferencesDestinationFolderCombination to PreferencesPathDestination & item i of PreferencesSubfolderDestination
set prefMoveFolder to move folder prefFolderToBeMoved ¬
to PreferencesDestinationFolderCombination ¬
with replacing
-- duplicate prefFolderToBeMoved to PreferencesDestinationFolderCombination
end repeat
end tell