I have a big directory of jpegs. i started adding “tags” to them using spotlight comments. now i want to convert the spotlight comments to IPTC metadata keywords. I managed to do this using Automator and Photoshop CS3, but I would like the IPTC keywords to be separated, instead of run together like a sentence. So basically I need to replace any spaces in the comments with semicolons. I have been combing the web and these forums and found some scripts that got me close, but I am new to Applescript and I can’t quite get anything to work.
This one seems closest to working. It will successfully get the comments of all the files in a folder and pass them to the function replace_chars, which works on its own in a separate applescript file with preset strings to replace spaces with semicolons. But I get an error on that function.
set Fldr to choose folder
tell application "Finder"
	set Pics to files of entire contents of Fldr -- digs down through enclosed folders
	set tKinds to {"GIF document", "GIF Image", "JPEG document", "JPEG Image", "PNG document", "TIFF document", "TIFF Image", "Adobe Photoshop JPEG file"} -- should include your photos
	repeat with onePic in Pics -- iterate through the pics
		if kind of onePic is in tKinds then
			set Cmt to comment of onePic -- get the comment from the Finder
			tell AppleScript
                        set the newCmt to replace_chars(Cmt, " ", ";")
			end tell
                        set comment of onePic to newCmt
		end if
	end repeat
end tell
on replace_chars(this_text, search_string, replacement_string)
		set AppleScript's text item delimiters to the search_string
		set the item_list to every text item of this_text
		set AppleScript's text item delimiters to the replacement_string
		set this_text to the item_list as string
		set AppleScript's text item delimiters to ""
	return this_text
end replace_chars
At first I was getting the error “Finder got an error: Can’t continue replace_chars.”
I figured the function was getting passed to the Finder instead of Applescript so I tried the tell AppleScript command. then I got the error: “«script AppleScript» doesn’t understand the replace_chars message.”
As an alternative to replace_chars, I found this method of split and join, which has not worked for me either
-- split the string into a list by some separator
to split of aString by sep
	local aList, delims
	tell AppleScript
		set delims to text item delimiters
		set text item delimiters to sep
		set aList to text items of aString
		set text item delimiters to delims
	end tell
	return aList
end split
-- join a list into a string with some separator
to join of aList by sep
	local aString, delims
	tell AppleScript
		set delims to text item delimiters
		set text item delimiters to sep
		set aString to aList as string
		set text item delimiters to delims
	end tell
	return aString
end join
AppleScript: 1.10.7
Browser: Firefox 2.0.0.6
Operating System: Mac OS X (10.4)

 heap:
 heap: