Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Get Last text item of line?

This is what I have so far.



I'm trying to get the last text item of each line. How can I do this please?


set metadata to paragraphs of "Keywords : Pastel Drop Earring

Headline : ES20ER02545MU2SV

UserComment : 21"


set AppleScript'stext item delimiters to {":"}

set thekeywords to 2nd text item of metadata

set theheadline to 3rd text item of metadata

set theusercomment to last text item of metadata




logthekeywords

logtheheadline

logtheusercomment

Mac Pro, OS X Mavericks (10.9)

Posted on Jan 16, 2014 3:17 AM

Reply
5 replies

Jan 16, 2014 4:01 AM in response to MattJayC

I'm still struggling with this,


I have it working on its own script.


set thefile to "/Users/StudioD/Desktop/DaisyAndEve_WK21_PSD 15.37.55/ES20ER02545MU2SV.psd"


set metadata to (do shell script "/usr/bin/exiftool -s -q -keywords -headline -usercomment " & quoted form of POSIX path of thefile) as text

logmetadata

set AppleScript'stext item delimiters to {":", return, tab, linefeed}

set test to every text item of metadata




Result:

{"Keywords ", " Pastel Drop Earring", "Headline ", " ES20ER02545MU2SV", "UserComment ", " 21"}


This is what I expect, however when I place it in the script. I cannot separate them?


tell current application


do shell script "/usr/bin/exiftool -s -q -keywords -headline -usercomment '/Users/StudioD/Desktop/DaisyAndEve_WK21_PSD 15.37.55/ES20NW03156BK2BD.psd'"


--> "Keywords : Black Beaded multirow Necklace

Headline : ES20NW03156BK2BD

UserComment : 21"


(*Keywords , Black Beaded multirow Necklace, Headline , ES20NW03156BK2BD, UserComment , 21*)



Can anyone solve where I am going wrong?



Jan 16, 2014 7:06 AM in response to MattJayC

I think instead of trying to parse this in Appescript you are better off using the power of exiftool to format the output in a way that will be easier to handle in the script/


If you add a -s2 to the exiftool command line you will only get the value of the tag rather then both he tagname and the value.


That is by doing this (notice the -s2 added to exittool command)


set thefile to "/Users/frank/Desktop/Screen Shot 2014-01-15 at 14.24.09 .png"


set metadata to (do shell script "/usr/bin/exiftool -s2 -s -q -keywords -headline -usercomment " & quoted form of POSIX path of thefile) as text

logmetadata

set AppleScript'stext item delimiters to {return}

set test to every text item of metadata

you get


tell current application


do shell script "/usr/bin/exiftool -s2 -s -q -keywords -headline -usercomment '/Users/frank/Desktop/Screen Shot 2014-01-15 at 14.24.09 .png'"


--> "New Keyword

New Headline

New UserComment"


(*New Keyword

New Headline

New UserComment*)

end tell

Result:

{"New Keyword", "New Headline", "New UserComment"}

Notice the result is is a simple list of the contents of the tags.


Now


item 1 of test is New Keyword and item 2 is New Headline, etc


regards

Get Last text item of line?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.