News:

2023-03-15 Major improvements to the new Geolocation feature

Main Menu

ExifTool Service (Mac)

Started by adayzdone, August 27, 2012, 01:41:20 PM

Previous topic - Next topic

adayzdone

For anyone who is interested, here is an AppleScript that can be used in a Service for quick metadata.

http://www.johneday.com/219/exiftool-service-for-quick-metadata-access


on run {input, parameters}
    -- creates a metadata folder in the Documents folder to store results
    set thePath to POSIX path of (path to documents folder) & "metadata"
    do shell script "mkdir -p " & quoted form of POSIX path of thePath
     
    tell application "Finder"
        repeat with anItem in input
            set theLocation to POSIX path of (anItem as text)
            set {name:fileName, name extension:nameExtension} to anItem
            set baseName to text 1 thru ((get offset of "." & nameExtension in fileName) - 1) of fileName
            set destLocation to quoted form of (thePath & "/" & baseName & ".txt")
            do shell script "exiftool -a " & quoted form of theLocation & " >" & destLocation
            do shell script "open " & destLocation
        end repeat
    end tell
end run

Phil Harvey

Thanks, but I think you can simplify your script and run ExifTool just once for all input files by using -w OUTDIR/%f.txt instead of redirecting the output from separate commands.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

adayzdone

Hi Phil,

Thanks for the quick reply, and for the great tool.

Does this look better?


on run {input, parameters}
-- creates a metadata folder in the Documents folder to store results
set thePath to POSIX path of (path to documents folder) & "metadata" & "/"
do shell script "mkdir -p " & quoted form of POSIX path of thePath

set {inputFiles, outputFiles} to {{}, {}}

repeat with anItem in input
set end of inputFiles to quoted form of POSIX path of (anItem as text)
tell application "Finder" to set {name:fileName, name extension:nameExtension} to anItem
set baseName to text 1 thru ((get offset of "." & nameExtension in fileName) - 1) of fileName
set end of outputFiles to quoted form of (thePath & baseName & ".txt")
end repeat

set {TID, text item delimiters} to {text item delimiters, space}
set {inputFiles, outputFiles} to {(inputFiles as text), (outputFiles as text)}
set text item delimiters to TID

do shell script "exiftool -a " & inputFiles & " -w " & quoted form of (thePath & "%f.txt" as text) & "; open " & outputFiles

end run

Phil Harvey

Yes, better.  This should run faster since it only calls exiftool once, although the script doesn't become as simple as I had hoped since you still have to loop through the input items to quote the input file names and generate the output files for your "open" command.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).