Why won't it rename

with the help of Jean-Baptiste LE STANG
i have got this much to work except for
set name of this_item to shortName & “H.tif”

why won’t it change the file name?

maybe i have benn goin about it all wrong

I am trying to run a script that does some stuff in Photoshop and saves these images in 3 location but in one of thew locations i need the file to end with H.tif instead of W.tif this is where the attached script would come in
sounds simple but it has kept me up at night thinking of how do make it happen

tell application "Finder"
	set cf to folder "Macintosh HD1:Users:jbradfield:Desktop:Move to Graphics:" --as alias
	set {nameList, dateList} to {name, modification date} of every file of cf
	set myOffset to my getOldestFile(dateList)
	set this_item to item myOffset of nameList
	set this_item to ((cf as string) & this_item) --as alias
	
	set this_info to info for file this_item
	set the current_name to the name of this_info
	set character_count to the number of characters in current_name
	set shortName to characters 1 thru (character_count - 5) of current_name as string
	if current_name ends with "W.tif" then
		
		set name of this_item to shortName & "H.tif"
	end if
	display dialog this_item
	
end tell

on getOldestFile(dateList)
	set oldestDate to item 1 of dateList
	set offsetoldestDate to 1
	repeat with x from 1 to count dateList
		if (item x of dateList) > oldestDate then set {oldestDate, offsetoldestDate} to {(item x of dateList), x}
	end repeat
	return offsetoldestDate
end getOldestFile

again thanks to all who help us so much

Hi Joe,

I’m not sure if it will work.

I have found that assigning values works better when I do the following.

Your code:

set name of this_item to shortName & "H.tif" 

My suggestion:

set name of this_item to (shortName & "H.tif" )

Best Regards,

Han Solo

Correct me if I’m wrong (I haven’t actually run the script), but you first say:

set this_item to ((cf as string) & this_item) 

followed by :

set name of this_item to shortName & "H.tif" 

The first line sets “this_item” to a string.

Then you try to set ‘name’ of a string to a new string. No wonder it doesn’t rename the file - this_item no longer refers to the file.

Instead you can try 'set name of file this_item to shortName & “H.tif”, or keep the file itself in the variable, instead of just it’s name.

It looks like you might be running into an issue concerning a file’s ‘displayed name’ versus its ‘name’. One includes the file extension and one doesn’t. This can cause problems when naming files. There are several file properties available from the Finder that can be used to work around this. To see all of the properties that are available for a file, run this and look at the result window in your script editor.

set thisFile to choose file
tell application "Finder" to set fileProps to properties of thisFile

thanks to all the script works

but (there is always a but huh :lol: )
i was thinking would it be better to run this name change thing as a folder action (on adding items to)
the script just seems to clumsy to me

any input?