Changing File extensions script not working

I tried using the following script I found in a past post to do a simple file extension find and replace, but I got the following error:

Finder got an error: Can’t set name extension of every file of alias “MacintoshHD:Users:test:Desktop:Scans:5 1985:” whose name extension = “psd” to “jpg”.

Any Ideas why this would be?

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

Hi thriftinkid,

If you take a look at the Finder’s AppleScript dictionary, you can see that the property «name extension» is read-only.

If you want to the modify the name extension of the files, you will have to change their whole name instead of the name extension only.

So you will need to strip the found extension from the file name, create a new file name with the new extension and rename the file with this newly created file name.

Happy Scripting!