-1

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

Hirschferkel
  • 291
  • 4
  • 20

2 Answers2

1

This works for me using the latest version of 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
  • 3,026
  • 1
  • 8
  • 19
  • Great, thanks! I will try to adapt it. When I have a fixed list of files I would just replace filesToMove with a list, right? Like: set filesToMove to {"file1", "file2", "file3"} And for path (path to desktop as text) I would replace it with e.g. "Volumes:WhateverDirectory:WhereverFolder:" for a different path than the relative desktop path, right? – Hirschferkel Feb 10 '18 at 13:02
  • The answer is YES To your question of using a fixed list of files... As long as your filelist does not contain posix path formatting as per your examples in your question... /Users/name/Library/Preferences/ for Finder To be able to process these items, HFS formatting needs to be used... "Macintosh HD:Users:Name:Library:Preferences" – wch1zpink Feb 11 '18 at 15:27
0

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
Hirschferkel
  • 291
  • 4
  • 20