Can anyone tell me how to modify this Applescript to work for OS X?
It is supposed to let you change the file extension of a group of files in a folder.
i.e. I want to change a folder of .jpg’s to .jpeg’s
But when I run it I keep getting this error:
Apple Script Error
Finder got an error: Can’t set name of selection to “abc123.jpeg”
set thePath to choose folder with prompt “Select folder to rename files in:”
set ext to display dialog “Extension to Replace:” default answer “”
set ext to text returned of ext
set extNew to display dialog “Replace With:” default answer “”
set extNew to text returned of extNew
tell application “Finder”
try
set the datlist to ¬
((every file in thePath whose name ends with ext) as alias) ¬
as list – set name criteria
on error number -1700 from f
set datlist to f as list
end try
repeat with dat in datlist --list of alias references to the files
select file dat
set workingName to the name of dat as text
set theOffset to offset of ext in workingName
set chopped to characters 1 through (theOffset - 1) of workingName
set newName to chopped & extNew as text
set name of selection to newName
end repeat
end tell
set thePath to choose folder with prompt "Select folder to rename files in:"
set ext to text returned of (display dialog "Extension to Replace:" default answer "")
set extNew to text returned of (display dialog "Replace With:" default answer "")
tell application "Finder"
try
set the datlist to files of thePath whose name extension is ext
end try
repeat with dat in datlist
set ext_length to count (get name extension of dat)
try
set name of dat to ((text 1 thru -(ext_length + 1) of (get name of dat)) & extNew)
on error e
display dialog e
end try
end repeat
end tell
set thePath to choose folder with prompt "Select folder to rename files in:"
set ext to text returned of (display dialog "Extension to Replace:" default answer "")
set extNew to text returned of (display dialog "Replace With:" default answer "")
tell application "Finder" to set name extension of (files of thePath whose name extension is ext) to extNew