Trouble with Script in OS 9

I have a script I got recently from someone on the Mac OsX Forum which I’m using to put copyright information in the comments field of all jpeg, tiff, and photoshop files in various folders and subfolders.

The script works great in MacOsX applescript but when I paste the script into the regular Mac OS 9 script editor I get one error.

The script is as follows:


property all_folders : {}

set commentText to text returned of (display dialog "Enter the copyright:" default answer "Copyright© 2003; Unauthorized use or reproduction prohibited by US copyright laws." buttons {"Cancel", "OK"} default button 2 with icon 1)
set the_folder to ("Western Digital HD 2:AddComments:") as alias
set all_folders to {the_folder}
my get_subfolders(the_folder)

tell application "Finder"
	repeat with i from 1 to (count of all_folders)
		set the_files to (every file of (item i of all_folders) whose name extension is in {"jpg", "psd", "tif"})
		repeat with the_file in the_files
			set comment of the_file to commentText
		end repeat
	end repeat
end tell

on get_subfolders(the_folder)
	tell application "Finder"
		try
			copy (every folder of the_folder) as alias list to the_subfolders
		on error
			try
				copy {(folder 1 of the_folder) as alias} to the_subfolders
			on error
				set the_subfolders to {}
			end try
		end try
	end tell
	repeat with i from 1 to (count of the_subfolders)
		set the_subfolder to item i of the_subfolders
		copy the_subfolder to end of all_folders
		my get_subfolders(the_subfolder)
	end repeat
end get_subfolders

The only problem is that when I do a check (or try to run the script in Mac OS 9) I get a message that indicates it’s having trouble with the term “name extension” in the line that reads, “set the_files to (every file of (item i of all_folders) whose name extension is in {“jpg”, “psd”, “tif”})”

The exact error message is “expected “,” but found identifier.” and the script checker highlights the word “extension”

Apparently the term is not used in Mac OS9 (That’s my best guess anyway).

If anyone who does Mac OS classic scripting knows why I’m having trouble with this line in Mac OS9 and not in OsX, and what I should change to make it work, I’d really appreciate hearing from you.

Please post a reply if you know.

Thanks,
ian

Yes, ‘name extension’ doesn’t appear in OS 9. Try changing whose name extension is in {“jpg”, “psd”, “tif”} to whose name ends with “.jpg” or name ends with “.psd” or name ends with “.tif”.

Nigel has it correct !
To help a little further I have modified your script to use a “subroutine” to get the 4 letter extension for each File and return it to the main portion of the script.

property all_folders : {}
global extension

set commentText to text returned of (display dialog "Enter the copyright:" default answer "Copyright© 2003; Unauthorized use or reproduction prohibited by US copyright laws." buttons {"Cancel", "OK"} default button 2 with icon 1)
set the_folder to ("Paul:AddComments:") as alias
set all_folders to {the_folder}
my get_subfolders(the_folder)

tell application "Finder"
	repeat with i from 1 to (count of all_folders)
		set the_files to (every file of (item i of all_folders))
		repeat with eachFile in the_files
			my nameExtension(eachFile)
			if extension is in {".jpg", ".psd", ".tif"} then
				set comment of eachFile to commentText
			end if
		end repeat
	end repeat
end tell

on get_subfolders(the_folder)
	tell application "Finder"
		try
			copy (every folder of the_folder) as alias list to the_subfolders
		on error
			try
				copy {(folder 1 of the_folder) as alias} to the_subfolders
			on error
				set the_subfolders to {}
			end try
		end try
	end tell
	repeat with i from 1 to (count of the_subfolders)
		set the_subfolder to item i of the_subfolders
		copy the_subfolder to end of all_folders
		my get_subfolders(the_subfolder)
	end repeat
end get_subfolders

on nameExtension(eachFile)
	tell application "Finder"
		set fileName to name of eachFile
		set j to count of characters in fileName
		set extension to characters from (j - 3) to j in fileName as text
	end tell
	return extension
end nameExtension

This way you can simply add other extensions to the extension list if needed. :rolleyes:

Actually, to simplify the script and get it working in OS 9 (and X for that matter–you could have originally stated that you needed it for both and I would have provided a cross platform solution, not an OS X-only one :wink: ), try this:

Jon

For even more simplicty and speed, I’m happy to report that even X’s Finder can do this: :slight_smile:

set commentText to text returned of (display dialog "Enter the copyright:" default answer "Copyright© 2003; Unauthorized use or reproduction prohibited by US copyright laws." buttons {"Cancel", "OK"} default button 2 with icon 1)
set the_folder to ("Paul:AddComments:") as alias

addComments(the_folder)


on addComments(theFolder)
  global commentText
  
  tell application "Finder"
    try
      set comment of every file of theFolder whose name ends with ".jpg" or name ends with ".psd" or name ends with ".tif" to commentText
    end try
    repeat with thisFolder in ((get theFolder's folders) as list)
      my addComments(thisFolder)
    end repeat
  end tell
end addComments