• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Reading IPTC and EXIF information from photos
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Reading IPTC and EXIF information from photos


  • Subject: Re: Reading IPTC and EXIF information from photos
  • From: Christopher Stone <email@hidden>
  • Date: Tue, 11 Oct 2011 14:15:48 -0500

On Oct 10, 2011, at 11:36, Jan Erik Moström wrote:
I've searched a bit and most info I've found either suggest the use of 'ExifTool' or 'mdls' which is called using a shell script. Other suggestions involve some application like GraphicConverter.

I would like to make a script that depends on as few external apps/scripts as possible. In other words, I would like to avoid the use of ExifTool or GraphicConverter.

Is there some other way of getting the IPTC/EXIF info other than 'mdls', is there for example a scripting addition that would get the info for me?
______________________________________________________________________

Hey Jan,

If you're willing to go to an osax why not use ExifTool?  And for that matter what's wrong with 'mdls'?  It works, and it's built in to the system.  It is a little tedious to parse out the data, but it's not hard.

For my own use I'd employ the Satimage.osax to do the parsing, as it's quite a bit faster than shelling out to Perl - even so the following script is reasonably quick.

(As Wayne mentioned he and I have been talking off-list, and this can be made more efficient if a few of the bugs can be worked out.)

It does seem to me that the ExifTool provides output that is easier to parse than mdls'.

--
Best Regards,
Chris


------------------------------------------------------------------------------------------------


try
  # Obtain the Finder selection
  tell application "Finder"
    set sel to selection as alias list
    if sel ≠ {} then
      set fSel to first item of sel
    end if
  end tell

  

  set posixPath to quoted form of POSIX path of fSel

  

  set cmd to "mdls -name kMDItemKeywords " & posixPath
  set kMDItemKeywords to do shell script cmd without altering line endings
  set kMDItemKeywords to do shell script "perl -ne 's/^ +//g; print' <<< " & ¬
    quoted form of kMDItemKeywords without altering line endings
  set kMDItemKeywords to do shell script "perl -0777 -wlne 'if (m/[^\\(]+\\(\\s*([^)]+)/ims) {print \"$1\"}' <<< " & ¬
    quoted form of kMDItemKeywords without altering line endings
  set kMDItemKeywords to do shell script "perl -wnle 's/\"//g; print' <<< " & ¬
    quoted form of kMDItemKeywords without altering line endings
  set kMDItemKeywords to do shell script "perl -0777 -wnle 's/\\s+\\Z//g; print' <<< " & ¬
    quoted form of kMDItemKeywords without altering line endings
  set kMDItemKeywords to paragraphs of kMDItemKeywords

  

  set cmd to "mdls \\
  -name kMDItemDescription \\
  -name kMDItemFSCreationDate \\
  -name kMDItemHeadline \\
  -name kMDItemPixelHeight \\
  -name kMDItemPixelWidth \\
  -name kMDItemTitle " & posixPath

  

  set infoReco to do shell script cmd without altering line endings
  set infoReco to do shell script "perl -wnle 's/\"//g; print' <<< " & ¬
    quoted form of infoReco without altering line endings
  set infoReco to do shell script "perl -0777 -wnle 's/[()]//g; print' <<< " & ¬
    quoted form of infoReco without altering line endings
  set infoReco to do shell script "perl -0777 -wnle 's/\\s+\\Z//g; print' <<< " & ¬
    quoted form of infoReco without altering line endings

  

  set infoReco to paragraphs of infoReco
  set AppleScript's text item delimiters to "= "
  repeat with i in infoReco
    set contents of i to text item 2 of i
  end repeat

  

  set kMDItemDescription to item 1 of infoReco
  set kMDItemFSCreationDate to item 2 of infoReco
  set kMDItemHeadline to item 3 of infoReco
  set kMDItemPixelHeight to item 4 of infoReco
  set kMDItemPixelWidth to item 5 of infoReco
  set kMDItemTitle to item 6 of infoReco

  

on error errMsg number errNum
  set {cr, sep} to {return, "------------------------------------------"}
  set e to sep & cr & "Error: " & errMsg & cr & sep & cr & "Error Number: " & errNum & cr & sep
  beep
  display dialog e
end try

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Reading IPTC and EXIF information from photos
      • From: Jan Erik Moström <email@hidden>
    • Re: Reading IPTC and EXIF information from photos
      • From: wayne melrose <email@hidden>
References: 
 >Reading IPTC and EXIF information from photos (From: Jan Erik Moström <email@hidden>)

  • Prev by Date: Re: Reading IPTC and EXIF information from photos
  • Next by Date: Re: Reading IPTC and EXIF information from photos
  • Previous by thread: Re: Reading IPTC and EXIF information from photos
  • Next by thread: Re: Reading IPTC and EXIF information from photos
  • Index(es):
    • Date
    • Thread