Skip to content

Instantly share code, notes, and snippets.

@swbuehler
Created January 13, 2014 20:17
Show Gist options
  • Save swbuehler/8407295 to your computer and use it in GitHub Desktop.
Save swbuehler/8407295 to your computer and use it in GitHub Desktop.
Parse filename and add keywords to PDF file (sample) using exiftool
tell application "Finder"
set theFolder to alias "Mac mini:Users:steven:SkyDrive:Receipts"
set thePDFs to every file in theFolder
repeat with eachPDF in thePDFs
try
set theFileName to the name of eachPDF
set theDate to (text 6 thru 7 of theFileName) & "/" & (text 9 thru 10 of theFileName) & "/" & (text 1 thru 4 of theFileName)
set theVendor to text 19 thru ((offset of "$" in theFileName) - 2) of theFileName
set theAmount to text (offset of "$" in theFileName) thru ((offset of ".pdf" in theFileName) - 1) of theFileName
set theKeywords to (quote & "vendor=" & theVendor & ", date=" & theDate & ", amount=\\" & theAmount & quote) as text
set thePOSIXFileName to ("/Users/steven/SkyDrive/Receipts/" & theFileName) as Unicode text
set runCmd to (do shell script "/usr/bin/exiftool " & the quoted form of thePOSIXFileName & " -keywords=" & theKeywords)
end try
end repeat
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment