I am attempting to write a script to allow me to keep my Downloads folder clean, this is great for uni/work as files get moved to their correct folders to allow linking in apps etc.
I have a script working for if a file does not exist, it will move the file to the selected folder (prompts user for folder) and I have added an option to delete the new file if it exists if the user wants, however I want to add an option to keep both files, with the new file being renamed with a "_2" added on the end of the name for the second "_3" for the third and so on.
As far as I have it, I am prompting for a manual name change, along with that not working, I can see it adding inefficiency. This is as far as I have it:
(* Version 1.2b
Move to Bin prompt added
Fixed activate Finder
add ability to keep a duplicate *)
on run {input, parameters}
tell application "Finder"
set fileToMove to item 1 of input
set fileName to name of fileToMove
set fileExtension to name extension of fileToMove ¬
--gets extension incase file needs to be renamed
activate
set chosenFolder to POSIX file choose folder with prompt "Select a folder to move " & fileName & " "
log chosenFolder
try
move fileToMove to folder chosenFolder
-- Make sound play only on success
on error
-- Display notification with title "File Not Moved" subtitle "File with that name already exists at that location"
display alert "Duplicate File Found" message "Would you like to move " & fileToMove & " to the Bin or Keep & Rename?" buttons {"Move Duplicate to Bin", "Keep & Rename", "Cancel"} default button "Keep Both" cancel button "Cancel"
set buttonReturned to button returned of result
if buttonReturned is "Keep Both" then
display dialog "Set New File Name for: " & fileName & " " default answer fileName with icon note
set newName to result
set the name of fileToMove to newName
set the extension of fileToMove to fileExtension
move fileToMove to folder chosenFolder
do shell script "afplay /System/Library/Components/CoreAudio.component/Contents/SharedSupport/SystemSounds/system/Volume Mount.aif'"
end if
if buttonReturned is "Move Duplicate to Bin" then
-- Move the file to the trash
move fileToMove to trash
end if
end try
end tell
end run
Any other suggestions, refinements welcome