scripting adobe's xmp-data (question about "reading" files from as)

the following script successfully parses adobe xmp-data from an image file:

set myFolder to read (choose file)
set theContents to myFolder
property captionBeginning : “xmlns:dc=‘http://purl.org/dc/elements/1.1/’>
dc:formatimage/jpeg</dc:format>
dc:title
rdf:Alt
<rdf:li xml:lang=‘x-default’>”
property captionEnd : “</rdf:li>
</rdf:Alt>
</dc:title>”
set originalDelimiters to AppleScript’s text item delimiters
set AppleScript’s text item delimiters to {captionBeginning}
set theItems to text items 2 thru (count of text items of theContents) of theContents
set captionArray to {}
set AppleScript’s text item delimiters to {captionEnd}
repeat with nextItem in theItems
set captionArray to captionArray & first text item of nextItem
end repeat
set AppleScript’s text item delimiters to originalDelimiters
display dialog captionArray

property photoBeginning : “</rdf:li>
</rdf:Alt>
</dc:title>
dc:creator
rdf:Seq
rdf:li
property photoEnd : “</rdf:li>
</rdf:Seq>
</dc:creator>
</rdf:Description>”
set originalDelimiters to AppleScript’s text item delimiters
set AppleScript’s text item delimiters to {photoBeginning}
set theItems to text items 2 thru (count of text items of theContents) of theContents
set photoArray to {}
set AppleScript’s text item delimiters to {photoEnd}
repeat with nextItem in theItems
set photoArray to photoArray & first text item of nextItem
end repeat
set AppleScript’s text item delimiters to originalDelimiters
display dialog "©2007 " & photoArray

i think i originally found the bulk of this script on this forum! a couple modifications and this script has already saved me from hours of painful typographical work. i’m having trouble, however, with altering one of the command lines. i’d like to have the script read a variable or file path, but the “read” command only seems to work with file prompts.

what i’d like to do isn’t too dramatic. i just want to change:

“set myFolder to read (choose file)” to “set myFolder to read (myVariable)”.

with this change i get the following error message:
Can’t make “comp2:users:gregd:desktop:test_image.jpg” into a file.

the script which returns the error message is below:

set myVariable to “comp2:users:gregd:desktop:test-image.jpg”
set myFolder to read (myVariable)
set theContents to myFolder

property captionBeginning : “xmlns:dc=‘http://purl.org/dc/elements/1.1/’>
dc:formatimage/jpeg</dc:format>
dc:title
rdf:Alt
<rdf:li xml:lang=‘x-default’>”
property captionEnd : “</rdf:li>
</rdf:Alt>
</dc:title>”
set originalDelimiters to AppleScript’s text item delimiters
set AppleScript’s text item delimiters to {captionBeginning}
set theItems to text items 2 thru (count of text items of theContents) of theContents
set captionArray to {}
set AppleScript’s text item delimiters to {captionEnd}
repeat with nextItem in theItems
set captionArray to captionArray & first text item of nextItem
end repeat
set AppleScript’s text item delimiters to originalDelimiters
display dialog captionArray

property photoBeginning : “</rdf:li>
</rdf:Alt>
</dc:title>
dc:creator
rdf:Seq
rdf:li
property photoEnd : “</rdf:li>
</rdf:Seq>
</dc:creator>
</rdf:Description>”
set originalDelimiters to AppleScript’s text item delimiters
set AppleScript’s text item delimiters to {photoBeginning}
set theItems to text items 2 thru (count of text items of theContents) of theContents
set photoArray to {}
set AppleScript’s text item delimiters to {photoEnd}
repeat with nextItem in theItems
set photoArray to photoArray & first text item of nextItem
end repeat
set AppleScript’s text item delimiters to originalDelimiters
display dialog "©2007 " & photoArray

if anyone has any ideas, it would be a great help!

:slight_smile:

Read expects a file, and you’re giving it a string. Give it hint so it coerces to a file spec correctly…

set myVariable to “comp2:users:gregd:desktop:test-image.jpg” as alias

thanks for the idea! you’ve really helped end my frustration!

the mystery is solved… but a new one unfolds…

after adding “as alias” to my filepath, i get a new error:

“Could not identify the element type of the Count command.”
referring to this line:
set theItems to text items 1 thru (count of text items of theContents) of theContents

do you happen to know what sorts of element types there are for the Count command? the applescript finder dictionary is unclear.

Hmmm… it looks right.

Maybe it’s getting confused. You could try

set theItems to text items 2 thru (count of (text items of theContents)) of theContents

You can use negative number to reference list items starting from the end of the list.

set theItems to text items 2 thru -1 of theContents

I think -1 gets you the last item. Or maybe the next to the last. Better check that.

Saying:
set theTextItems to text items of theContents
set theCount to count of theTextItems
set theItems to items 2 thru theCount of theTextItems

…is really long winded, but you can log the vars and see what’s going on a little better.