Anyone know why my buttons aren't working for a folder action in applscript? This is designed to launch from Automator and keep the Downloads folder clean with options to rename duplicates then move the renamed file or move duplicate to bin.
However clicking any of the buttons causes the script to stop without the file being moved.
Any tips on how to correct this?
on run {input, parameters}
tell application "Finder"
set fileToMove to item 1 of input
set fileName to name of fileToMove
set chosenFolder to POSIX path of (choose folder with prompt "Select a folder to move " & fileName & " ")
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"
set buttonReturned to display alert "Duplicate File Found" message "Would you like to move " & fileName & " to the Bin or Keep & Rename?" buttons {"Move Duplicate to Bin", "Keep & Rename", "Cancel"} default button "Keep & Rename" cancel button "Cancel"
if buttonReturned is "Move Duplicate to Bin" then
delete fileToMove
else if buttonReturned is "Keep & Rename" then
set newName to the text returned of (display dialog "Set New File name for: " & fileName & "" default answer "")
set the name of fileToMove to newName
move fileToMove to folder chosenFolder
end if
end try
end tell
do shell script "afplay /System/Library/Components/CoreAudio.component/Contents/SharedSupport/SystemSounds/system/Volume Mount.aif'"
open currentWindow
end run
When I click the respective button, I want the action to occur
ie when button move to bin, it moves the original to the bin when button button keep and rename is clicked it should ask for a new name, then rename the file to the input name and then move the renamed file
choose folderreturns instead of coercing it to a POSIX path. If you need a POSIX path somewhere else for something likedo shell script, you can coerce it then. See Aliases and Files in the AppleScript Language Guide.