Hi there,
I know this is pretty easy but I’m making a bit of hash of it, one of those days I think.
I’m trying to rename a file named like this Fred Bloggs - CS to this XYZ-Bloggs_Fred-CS using the name that is already there.
This is the code so far:-
tell application "Finder"
set x to get selection as text
end tell
set AppleScript's text item delimiters to ":"
set fname to x as text
set yy to (text items 1 thru -2) of fname
--display dialog yy as text
set AppleScript's text item delimiters to ":"
set filename to last text item of x
set AppleScript's text item delimiters to " "
set newFilename to "XYZ-" & (text item 2 of filename) & "_" & (text item 1 of filename) & "-" & (text item 4 of filename) as text
display dialog x as text
display dialog newFilename
set name of x to newFilename
When I run this all works fine apart from the last line - the renaming. I get an error 'Can’t set name of “this file” to “XYZ-Bloggs_Fred-CS” '.
Please can someone point me in the right direction.
Thanks in advance,
Nick