Search code examples
fileapplescriptmovedirectorymacos-high-sierra

How to move folders to a new location with apple script


I don't know how to proceed to set up an apple script which moves folders with their content to a new loacation, where these folders migth already exist. If so Finder should overwrite these folders. But in the same process I have specific files, too, which should be moved to a new location. I don't get it how to make it work.

These are the files and folders I want to move and overwrite: OLDFOLDER > source, which should be overwriten with destination > NEWFOLDER

folders

  • /Volumes/Netshare/Maxon/OLDFOLDER/library/scripts
  • /Volumes/Netshare/Maxon/OLDFOLDER/Off_Plugins

folders

  • /Users/name/Library/Preferences/MAXON/OLDFOLDER/library/browser
  • /Users/name/Library/Preferences/MAXON/OLDFOLDER/prefs

documents (without ending)

  • /Users/name/Library/Preferences/MAXON/OLDFOLDER/prefs/xxx_net_80
  • /Users/name/Library/Preferences/MAXON/OLDFOLDER/prefs/xxx_net_80_version4

documents (with ending)

  • /Users/name/Library/Preferences/MAXON/OLDFOLDER/prefs/c4d_M_GLOBAL_POPUP.res

I would appreciate any help which gives a direection how to realize this. I tried some research before, but did not get ahead...

Best


Solution

  • Thanx to @wch1zpink

    I got the necessary script to work with some improvements for my case. Here is how it works, now:

    -- 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