Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

wesg

macrumors regular
Original poster
Jan 2, 2008
211
0
Toronto, ON
This seems like a rather easy task, but I've searched with Google through this forum and others, and have yet to find a solution.

I want to rename the files I've selected in Finder, and have successfully found the replacement text, but no matter what I do, i can't make applescript rename the file. I've gotten the POSIX path, and use the text
Code:
set name of pathItem to renameFile
to do the renaming, but I get nothing. Do I need to include the path and extension? In this case, pathItem is the path to the file, as in Macintosh HD/Users/.../Desktop/... and renameFile is exactly the same, except for the new name.

What can I do differently?
 
Your problem is probably in that you're not telling the Finder to do what you need done, as a result, Applescript's own file management dictionary is being used, which cannot rename files. This works, though it could be trimmed significantly:

Code:
tell application "Finder"
	set fileAlias to (choose file)
	set filePath to fileAlias as text
	set TID to AppleScript's text item delimiters
	set AppleScript's text item delimiters to ":"
	set fileName to last text item of filePath
	set AppleScript's text item delimiters to "."
	set fileNamePart1 to text item 1 of fileName
	set fileNamePart2 to text item 2 of fileName
	set fileName to fileNamePart1 & "001" & "." & fileNamePart2
	set AppleScript's text item delimiters to TID
	set name of fileAlias to fileName
end tell

Last line also works as:

Code:
	set properties of fileAlias to {name:fileName}

mt
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.