Rename, reduce a file name

From a Mac OS X machine, I’m triyng to reduce the name of files greater than 27 characters to move it to Mac OS 9.
I’m unable to give the file the new name.
Here is my script

Thank you for helping

on verifie_deplace_fichier(these_items)
	try
		repeat with i from 1 to count these_items
			set this_item to item i of these_items
			set this_item to (source_folder & ":" & this_item) as alias
			set the item_info to the info for this_item
			set the character_count to the (number of characters of the name of item_info) as integer
			set file_name to (characters of (name of item_info as text) as text)
			set suffixe to ".txt"
					if character_count > 27 then
						copy (characters 1 through 27 of file_name as string) & suffixe to mod_file_name
						tell application "Finder"
							set the name of this_item to (source_folder & ":" & mod_file_name)
							move this_item to the target_folder with replacing
						end tell
					else
						tell application "Finder"
							duplicate this_item to the target_folder with replacing
							move this_item to the done_folder with replacing
						end tell
						log_data("Le fichier «" & name of item_info & "» est de format texte. & return) of me
					end if
				end if
			end if
		end repeat
	end try
end verifie_deplace_fichier

Where you set the name of this item, don’t include “source_folder & “:” &” in the name.

--on verifie_deplace_fichier(these_items)
try
	repeat with i from 1 to count these_items
		set this_item to item i of these_items
		set this_item to (source_folder & ":" & this_item) as alias
		set the item_info to the info for this_item
		set the character_count to the (number of characters of the name of item_info) as integer
		set file_name to (characters of (name of item_info as text) as text)
		set suffixe to ".txt"
		if character_count > 27 then
			copy (characters 1 through 27 of file_name as string) & suffixe to mod_file_name
			tell application "Finder"
				set the name of this_item to (mod_file_name)
				move this_item to the target_folder with replacing
			end tell
		else
			tell application "Finder"
				duplicate this_item to the target_folder with replacing
				move this_item to the done_folder with replacing
			end tell
			log_data("Le fichier «" & name of item_info & "» est de format texte." & return) of me
		end if
	end repeat
end try
--end verifie_deplace_fichier

It is working just fine.
Thank You for your help :slight_smile:

Hi,

I wrote once a similar script, which is independent from the name extension.
This is a merged version of mine and yours

on verifie_deplace_fichier(these_items) -- these_items is list of aliases or file specifiers or HFS paths
	try
		repeat with oneItem in these_items
			set {name:Nm, name extension:Ex} to info for (oneItem as alias)
			if Ex is missing value then set Ex to ""
			if Ex is not "" then set Nm to text 1 thru ((count Nm) - (count Ex) - 1) of Nm
			if (count Nm) > 31 then
				set mod_file_name to text 1 thru (31 - (count Ex)) of Nm & "." & Ex
				tell application "Finder"
					set name of contents of oneItem to mod_file_name
					move this_item to the target_folder with replacing
				end tell
			else
				tell application "Finder"
					duplicate this_item to the target_folder with replacing
					move this_item to the done_folder with replacing
				end tell
				log_data("Le fichier «" & name of item_info & "» est de format texte." & return) of me
			end if
		end repeat
	end try
end verifie_deplace_fichier