Clipboard and parsing the Results of a script

Hi folks. I am not having success with the following scripts. As separate scripts, they work just fine. (The first one was grabbed online and is not mine) I can not figure a way to parse the results of the first script and use it for the second part of the script. I have tried telling the finder to set the clipboard to the result in the midst of the first script but the script shows an error that I can not set the clipboard to (all the data is shown).

I have tried every way I can think of to do this. I am not very accomplished at the nuances of Appescripting so if someone can see how to do this, I would appreciate hearing about it. IT seems to me that if the result of a script is XXXX, I should be able to set a variable to XXXX and use it in the next script. Or, set the clipboard to XXXX and use the clipboard results in the next script. But, obviously I am not catching on to how this is done with AS.

Please? And, thank you.

Lb

 tell application "iMagine Photo"
	set thisFile to choose file with prompt "Choose an image file containing exif data:" without invisibles
	set thisImporter to import graphic thisFile
	set exifInfo to the exif data of thisImporter
	close thisImporter
	exifInfo
end tell


tell application "Tex-Edit Plus"
	activate
	select window 1
	select contents of window 1
	paste exifInfo
	replace window 1 looking for "{{" replacing with ""
	replace window 1 looking for "\"}, {exif type:" replacing with "^c"
	replace window 1 looking for "exif unicode:\"" replacing with ""
	replace window 1 looking for "exif " replacing with ""
	replace window 1 looking for "int:" replacing with ""
	replace window 1 looking for "type:" replacing with ""
	select contents of window 1
	set capitalization of selection to word caps
end tell

exifInfo is a list of lists and records looking like this (for a photo grabbed at random).

{{exif type:info, exif unicode:"                               "}, {exif type:exif make, exif unicode:"SONY"}, {exif type:exif model, exif unicode:"DSC-P200"}, {exif type:exif creation date, exif unicode:"2005:07:30 15:13:36"}, {exif type:orientation, exif int:1, exif unicode:"Normal"}, {exif type:exposure time in seconds, exif float:0.00800000038, exif unicode:"1/125"}, {exif type:aperture fNum, exif float:5.599999904633, exif unicode:"56/10"}, {exif type:exposure program, exif int:2, exif unicode:"Programmed auto"}, {exif type:ISO film speed, exif int:100, exif unicode:"100"}, {exif type:capture date, exif unicode:"2005:07:30 15:13:36"}, {exif type:exposure bias EV, exif float:0.0, exif unicode:"0/167772160"}, {exif type:metering mode, exif int:5, exif unicode:"Matrix"}, {exif type:light source, exif int:0, exif unicode:"Auto"}, {exif type:flash, exif int:13, exif unicode:"Unknown"}, {exif type:focal length mm, exif float:7.900000095367, exif unicode:"79/10"}, {exif type:capture width in pixels, exif int:128, exif unicode:"128"}, {exif type:capture height in pixels, exif int:148, exif unicode:"148"}}

What do you want to do to it? (It’s not at all clear to me how TextEdit gets into the picture or what it’s supposed to do with exif which is not in it).

Further, your best bet is to filter out what you want directly in the AppleScript without involving TextEdit unless there’s some very good reason for this.

Hi, Lb.

The crucial challenge here is converting the data into text. This isn’t a trivial operation ” unless one is prepared to cheat a little. :wink:

As Adam suggested, the parsing and text manipulation operations could also be achieved using AppleScript.

Here’s an example:


property search_list : {"}, {", return & " exif ", "\"", " a", " b", " c", " d", " e", " f", " g", " h", " i", " j", " k", " l", " m", " n", " o", " p", " q", " r", " s", " t", " u", " v", " w", " x", " y", " z", return & space, " Mm"}

property replace_list : {return & space, return & space, "", " A", " B", " C", " D", " E", " F", " G", " H", " I", " J", " K", " L", " M", " N", " O", " P", " Q", " R", " S", " T", " U", " V", " W", " X", " Y", " Z", return, " mm"}

to |search & replace text| from t
	repeat with i from 1 to count search_list
		set text item delimiters to my search_list's item i
		set t to t's text items
		set text item delimiters to my replace_list's item i
		set t to t as string
	end repeat
end |search & replace text|

on |text conversion| from l
	try
		l's t
	on error t
	end try
	set text item delimiters to "{"
	set t to t's text from text item 2 to -1
	set text item delimiters to "}"
	|search & replace text| from return & space & text 1 thru -2 of t's text 2 thru text item -2
end |text conversion|

to |parse text| from r
	script s
		property l : r
	end script
	set c to count s's l
	repeat with i from 1 to c
		set s's l's item i to s's l's item i as list
	end repeat
	set d to text item delimiters
	set s's l to rest of (|text conversion| from s's l)'s paragraphs
	set text item delimiters to ", "
	repeat with i from 1 to c
		tell s's l's item i to if text item -1 is text item -2 then
			set s's l's item i to text item 1 & ": " & text from text item 2 to text item -2
		else
			set s's l's item i to text item 1 & ": " & text from text item 2 to -1
		end if
	end repeat
	set text item delimiters to return
	set t to s's l as string
	set text item delimiters to d
	t
end |parse text|

to |get exif text| from f
	tell application "iMagine Photo" to tell (import graphic f)
		set exif_data to exif data
		close
	end tell
	if (count exif_data) is 0 then display dialog "No exif data was detected." buttons {"Cancel"} default button 1 with icon 1
	|parse text| from exif_data
end |get exif text|

set exif_text to |get exif text| from choose file of type {"public.image"} with prompt "Choose an image file containing exif data:" without invisibles

tell application "TextEdit"
	activate
	make document with properties {text:exif_text}
end tell

Hi, all.

levelbest’s using Tex-Edit Plus, not TextEdit.

Another approach, since iMagine Photo can coerce its own ‘exif type’ values to text, would be as follows. (I don’t have Tex-Edit Plus, so I’m taking levelbest’s code for this on trust.):

tell application "iMagine Photo"
	set thisFile to choose file with prompt "Choose an image file containing exif data:" without invisibles
	set thisImporter to import graphic thisFile
	set exifInfo to the exif data of thisImporter
	close thisImporter
	
	repeat with theseData in exifInfo
		-- Concatenate dummy properties to the exifInfo record and get its values.
		set {exif type:exifType, exif int:exifInt, exif float:exifFloat, exif unicode:exifUnicode} to (theseData & {exif int:missing value, exif float:missing value})
		-- Format each line according to whether or not there are 'exif int' or 'exif float' values.
		set exifType to (exifType as Unicode text) & ": "
		if (exifInt is not missing value) then
			set theseData's contents to exifType & exifInt & ", " & exifUnicode
		else if (exifFloat is not missing value) then
			set theseData's contents to exifType & exifFloat & ", " & exifUnicode
		else
			set theseData's contents to exifType & exifUnicode
		end if
	end repeat
	
	set astid to AppleScript's text item delimiters
	set AppleScript's text item delimiters to return -- or does "^c" mean ASCII character 12?
	set exifInfo to exifInfo as Unicode text
	set AppleScript's text item delimiters to "exif "
	set exifInfo to exifInfo's text items
	set AppleScript's text item delimiters to ""
	set exifInfo to exifInfo as Unicode text -- or 'as string' if Tex-Edit Plus requires it.
	set AppleScript's text item delimiters to astid
end tell

tell application "Tex-Edit Plus"
	activate
	select window 1
	select contents of window 1
	paste exifInfo
	select contents of window 1
	set capitalization of selection to word caps
end tell

I was aware of that, Mr. G. ” but, as levelbest mentions in his GraphicConverter Set IPTC Coment topic, he was merely using Tex-Edit Plus “to parse the data into a useful column of information”. Since the intention of my example was simply to demonstrate a parsing approach in AppleScript, I deliberately used a more limited alternative to TE+, just to display the results. :slight_smile:

No, it’s definitely CR/ASCII character 13.