Skip to content

Instantly share code, notes, and snippets.

@swbuehler
Created September 15, 2015 17:14
Show Gist options
  • Select an option

  • Save swbuehler/78b5c858aef6a2490052 to your computer and use it in GitHub Desktop.

Select an option

Save swbuehler/78b5c858aef6a2490052 to your computer and use it in GitHub Desktop.
Add QR Code to multipage TIFF files containing the full path to the filename.
tell application "Finder"
set theFiles to the selection
repeat with thisFile in theFiles
try
(* get path and filename information from UNIX *)
set theExtension to the name extension of thisFile
set thePath to the POSIX path of (folder of thisFile as string)
set theFilename to the POSIX path of (thisFile as string)
set theBaseName to (do shell script "/bin/bash -c \"basename " & theFilename & " ." & theExtension & "\"")
set theURLEncodedFilename to (do shell script "/usr/bin/python -c 'import sys, urllib; print urllib.quote(sys.argv[1])' " & quoted form of theFilename)
(* split file into multiple tiffs *)
do shell script "cd " & the quoted form of thePath & ";/usr/local/bin/tiffsplit " & the quoted form of theFilename
(* Add QR Code to first page of the split tif file *)
do shell script "cd " & the quoted form of thePath & "; /usr/bin/curl -s \"https://chart.googleapis.com/chart?cht=qr&chs=200x200&chl=" & theURLEncodedFilename & "\" | /usr/local/bin/convert ./xaaa.tif - -gravity northeast -composite ./xaaa.tif"
(* Join the pages back to a single tif *)
do shell script "cd " & the quoted form of thePath & "; /usr/local/bin/convert -adjoin xa* -compress group4 " & the quoted form of theFilename
do shell script "cd " & the quoted form of thePath & "; rm x*.tif"
end try
end repeat
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment