Hello everyone, I absolutely love KM, but I don’t know much about coding. As of right now, I have an action that moves files from Finder & Path Finder to a specific folder. However, if there’s a file in that folder with the same name, it doesn’t ask to replace or merge. Is there any way I can add the ability to automatically overwrite the file or merge? Sorry, probably day 1 basics, but I have to plead ignorance!
This is my macro as of now. If I could have it replace the file in that folder that'd be great. When I say "merge" I mean if there's another file in folder with the same name, it keeps both but gives the new or the old file a unique suffix or something like that. Deleting the file that's in the folder with the same name is probably the easiest method. Thanks for your help!
Sorry about that – I didn’t set a good enough reminder.
This AppleScript when run from an Execute an AppleScript action will move the selected items in EITHER the Finder or Path Finder to the designated location.
IF there is a COLLISION the destination item(s) will be REPLACED.
I know you prefer to rename collisions, but that is much more complicated.
When I do collision-control I usually employ a date-based serial number for the sake of simplicity.
I can add a routine to do that if you like.
-Chris
------------------------------------------------------------------------------
# Auth: Christopher Stone <scriptmeister@thestoneforge.com>
# dCre: 2017/02/15 18:30
# dMod: 2017/02/15 19:16
# Appl: Finder, Path Finder, System Events
# Task: Move selected items in the Finder OR Path Finder to a designated folder with REPLACING.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Finder, @Path_Finder, @System_Events, @Move, @Selection, @Designated
------------------------------------------------------------------------------
--» User Settings
------------------------------------------------------------------------------
# POSIX Path – preferably tilde-based POSIX Path if possible.
------------------------------------------------------------------------------
set destinationFolderPath to "~/test_directory/Destination_Directory/"
------------------------------------------------------------------------------
--» Main
------------------------------------------------------------------------------
set destinationFolderAlias to makeAlias(destinationFolderPath)
set appName to getFrontmostAppName()
if appName = "Finder" then
set itemList to getFinderSelectionAsAliasList()
else if appName = "Path Finder" then
set itemList to getPathFinderSelectionAsAliasList()
end if
if itemList ≠ {} then
tell application "Finder"
move itemList to destinationFolderAlias with replacing
end tell
end if
------------------------------------------------------------------------------
--» HANDLERS
------------------------------------------------------------------------------
on getFinderSelectionAsAliasList()
tell application "Finder"
set finderSelectionList to selection as alias list
if length of finderSelectionList = 0 then error "No files were selected in the Finder!"
return finderSelectionList
end tell
end getFinderSelectionAsAliasList
------------------------------------------------------------------------------
on getFrontmostAppName()
set frontAppAlias to path to frontmost application
set {oldTIDS, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {":", ".app:"}}
set frontAppName to item -2 of (text items of (frontAppAlias as text))
set AppleScript's text item delimiters to oldTIDS
return frontAppName
end getFrontmostAppName
------------------------------------------------------------------------------
on getPathFinderSelectionAsAliasList()
tell application "Path Finder"
set pfSelectionList to selection
if pfSelectionList ≠ missing value then
repeat with i in pfSelectionList
set (contents of i) to POSIX path of (contents of i)
end repeat
else
error "Nothing is selected in Path Finder!"
end if
end tell
repeat with i in pfSelectionList
set (contents of i) to alias POSIX file (contents of i)
end repeat
return pfSelectionList
end getPathFinderSelectionAsAliasList
------------------------------------------------------------------------------
on makeAlias(posixPathStr)
tell application "System Events"
set posixPathStr to POSIX path of disk item posixPathStr
end tell
return alias POSIX file posixPathStr
end makeAlias
------------------------------------------------------------------------------
This is great! Is it possible to add the date / time to the end of the file or folder if there’s a file or folder named the same thing in the folder I’m moving it to? If not no big deal at all. Sometimes I just don’t want to replace something necessarily but I need both to be in that folder. Does that make sense? Either way THANK YOU for your help!