Strip XMP Metadata

Does anyone know how you can strip out the history info in the XMP metadata through a script? I’ve tried several things without much luck.

Thanks,
Dave

The metadata is at the top of the file and can be accessed with

set theFile to choose file
set FileData to read theFile

The result window now has the filedata in it. You can parse the data in many ways; if you want the whole history you can either use


--Get metadata
set theFile to choose file
set FileData to read theFile

--Separate the data by tag
set AppleScript's text item delimiters to "rdf:RDF"
set FileDataBlocks to text items of FileData
set AppleScript's text item delimiters to ""

--Filedatablocks is a list; the metadata is usually item 2 in the list. 
set TheHistory to text item 2 of FileDataBlocks

which starts at “Description”, the first item of the history

or


--Get metadata
set theFile to choose file
set FileData to read theFile

--Separate the data by tag
set AppleScript's text item delimiters to "<?xpacket"
set FileDataBlocks to text items of FileData
set AppleScript's text item delimiters to ""

--Filedatablocks is a list; the metadata is usually item 2 in the list. 
set TheHistory to text item 2 of FileDataBlocks

Which is “begin” to “end” and includes a little more “coded info”

If you just want a section of the History


--Get metadata
set theFile to choose file
set FileData to read theFile
set FileDataBlocks to paragraphs of FileData


--Separate metadata in blocks

set AppleScript's text item delimiters to "<"
set FileData to text items of FileData
set AppleScript's text item delimiters to ""

--***Customize here with desired data block: Description, Author, BaseURL, CreateDate,CreatorTool, Format, MetadataDate, ModifyDate, or Nickname
repeat with ThisBlock in FileData
	if ThisBlock contains "Description" then
		set Description to ThisBlock as string
		exit repeat
	end if
end repeat

--Remove xml mark-up
set copy_flag to true
set ParsedData to ""
repeat with this_char in Description
	set this_char to the contents of this_char
	if this_char is "<" then
		set the copy_flag to false
	else if this_char is ">" then
		set the copy_flag to true
	else if the copy_flag is true then
		set ParsedData to ParsedData & this_char as string
	end if
end repeat

return ParsedData

SC

This was very helpful, but still not quite what I was looking for. I actually want to remove the “History”, part of the metatdata that actually tracks when a file was opened and saved.

I’ve tried similar things to what you’ve written here, but when I replace the “History” with a line showing no history and save the file, I get an error in Photoshop that it has an unexpected end of file.

Dave