Scripting Additions

An example of incorporating scripting additions to extract the embedded caption data in an image.

NREL-captioned-001

Choose a captioned image file.

choose file --> alias "Macintosh HD:Users:otto:Desktop:NREL-captioned-001.jpg"

Get the file information record for a chosen image file.

info for (choose file) --> {name:"NREL-captioned-001.jpg", creation date:date "Friday, December 23, 2016 at 2:32:16 PM", modification date:date "Friday, December 23, 2016 at 2:32:22 PM", size:1752223, folder:false, alias:false, package folder:false, visible:true, extension hidden:false, name extension:"jpg", displayed name:"NREL-captioned-001.jpg", default application:alias "Macintosh HD:Applications:Preview.app:", kind:"JPEG image", file type:"", file creator:"", type identifier:"public.jpeg", locked:false, busy status:false, short version:"", long version:""}

Using the path to scripting addition to control which folder is displayed by default in the choose dialog.

info for (choose file default location (path to pictures folder)

Limit the possible selection of the type of file.

set aFile to (choose file of type "public.jpeg") --> alias "Macintosh HD:Users:otto:Desktop:NREL-captioned-001.jpg"

Use the UNIX command line to extract metadata data.

AppleScript Do Shell Script Tech Note

set aPath to POSIX path of (choose file of type "public.jpeg") --> "/Users/otto/Desktop/NREL-captioned-001.jpg" do shell script "mdls -raw -name kMDItemDescription " & quoted form of aPath --> "Grey Mountain on the Navajo Reservation, north of Flagstaff, and east of Cameron, Arizona. This southwest corner of the Navajo Nation Reservation has been identified as the best wind resource site in Arizona."

Convert to a sub-routine.

on extractImageDescription(thisFile) set aPath to the POSIX path of thisFile set queryResult to ¬ do shell script "mdls -raw -name kMDItemDescription " & quoted form of aPath if queryResult is "(null)" then return missing value else return queryResult end if end extractImageDescription
set aFile to (choose file of type "public.jpeg" default location (path to desktop folder)) extractImageDescription(aFile) on extractImageDescription(thisFile) set aPath to the POSIX path of thisFile set queryResult to ¬ do shell script "mdls -raw -name kMDItemDescription " & quoted form of aPath if queryResult is "(null)" then return missing value else return queryResult end if end extractImageDescription
UNDER CONSTRUCTION

This webpage is in the process of being developed. Any content may change and may not be accurate or complete at this time.

DISCLAIMER