How to save the metadata of selected photos as a text file

by: 
Last modified: Sep 13, 2020 2:37 AM
4 871 Last modified Sep 13, 2020 2:37 AM

See this discussion on how to write an Apple Script to extract the metadata of the selected photos and write them to text file:

https://discussions.apple.com/thread/7792859?answerId=31127814022#31127814022


Here is the finished script:

(* Write Metadata tags to a file

Author: Leonie Dreschler-Fischer 

To run this workflow, select some images in Aperture,
then start the workflow by pressing the "Run Button",
or install the workflow as service in ~/Library/Services and launch it from the Services menu in Aperture,
when prompted, enter a filename for the text output
*)

on write_info(im_version, f)
	local nam, w, h, dat, dims, nl
	local res
	tell application "Aperture"
		
		set dat to ""
		set tabu to "	"
		set nl to "
"
		
		try
			set nam to (get the name of im_version as string)
			write nam to f
			write tabu to f
		end try
		
		(* get media type, mov or else *)
		try
			tell im_version
				set file_name to (get value of other tag "FileName")
			end tell
			set savedTextItemDelimiters to AppleScript's text item delimiters
			set AppleScript's text item delimiters to {"."}
			set type_media to (get last text item of file_name)
			set AppleScript's text item delimiters to savedTextItemDelimiters
			
			write type_media to f
			write tabu to f
		end try
		
		try
			set w to get width of im_version as string
			set h to get height of im_version as string
			set dims to w & "x" & h & tabu
			write dims to f
		end try
		try
			tell im_version
				set dat to (value of EXIF tag "ImageDate") as string
			end tell
			set dat to dat & tabu
			write dat to f
		end try
		try
			local thekeywords
			tell im_version
				set thekeywords to (value of IPTC tag "keywords") as string
			end tell
			set thekeywords to thekeywords & tabu
			write thekeywords to f
		end try
		try
			local rating, isflagged, ispicked
			tell im_version
				set rating to get the main rating of im_version as string
				set isflagged to get flagged of im_version as string
				set ispicked to get picked of im_version as string
			end tell
			set rating to rating & tabu & isflagged & tabu & ispicked & tabu
			write rating to f
		end try
		
		try
			local cam_make, cam_model, camera
			tell im_version
				set cam_make to (value of EXIF tag "Make") as string
				set cam_model to (value of EXIF tag "Model") as string
			end tell
			set camera to cam_make & tabu & cam_model & tabu
			write camera to f
		end try
		try
			local focal_length, aperture_value, shutter_speed, iso_value, flash_value, file_name, capture
			tell im_version
				set focal_length to (value of EXIF tag "FocalLength") as string
				set aperture_value to (value of EXIF tag "ApertureValue") as string
				set shutter_speed to (value of EXIF tag "Shutterspeed") as string
				set iso_value to (value of EXIF tag "ISOSpeedRating") as string
				set flash_value to (value of EXIF tag "Flash") as string
			end tell
			
			
			set capture to focal_length & tabu & aperture_value & tabu & shutter_speed & tabu & iso_value & tabu & flash_value
			write capture to f
		end try
		
		write nl to f
		return nam
	end tell
end write_info

on run {input, parameters}
	
	(* Write EXIF info on all selected images to a file *)
	
	if input is {} then error "Please select an image."
	
	local outputFile, item_count, im, inf
	set outputFile to choose file name with prompt "Output File name"
	set the inf to ""
	try
		open for access outputFile with write permission
		
		set the item_count to count of input
		set tabu to "	"
		set nl to "
"
		(* Table headers *)
		set first_line to "Name" & "Type" & tabu & "Dimensions" & tabu & "Date" & tabu & "Keywords" & tabu & "Ratings" & tabu & "Flagged" & tabu & "Picked" & tabu & "Camera" & tabu & "Model" & tabu & "Focal Length" & tabu & "Aperture" & tabu & "Shutter Speed" & tabu & "ISO" & tabu & "Flash" & nl
		write first_line to outputFile
		
		
		repeat with i from 1 to the item_count
			set im to item i of input
			
			set inf to write_info(im, outputFile)
			
		end repeat
		close access outputFile
		tell application "TextEdit"
			activate
			open outputFile
		end tell
	end try
	return input
end run


Embed it into an Automator service or quick action like this:

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