qlpreview
version 0.2
Requires Mac OS X 10.5 or higher
HAMSoft Engineering allows free use of this code and/or software in its "as is" condition. HAMSoft Engineering disclaims any liability of any kind for any damages whatsoever resulting from the use of this code and/or software. If you find it useful please consider making a donation to help HAMSoft Engineering stay in business.
download the compiled command line tool
download the source code project
download the version history
Use this command line tool to get either the regular file icon or the preview image as seen in QuickLook for a file in jpg, png, or tif format. This project uses some techniques derived from code written by Matt Gemmel. Matt's code called NSImage+QuickLook is at http://mattgemmell.com/source.
Version 0.2 has several upgrades from the 0.1 version. Thanks for these upgrades goes to Colorhythm, makers of the Prismpoint™ System. Colorythm will be using these upgrades in a future product.
Usage:
qlpreview -imageType jpg/png/tif -JPEGimageQuality theQuality -maxWidth imageWidth -maxHeight imageHeight -asIcon yes/no -inPath /path/to/file -outPath /path/to/file -preferFileIcon yes/no -generatePreviewOnly yes/no
The input variables explained:
[-imageType "jpg, png, or tif"] the output image format either jpg, png, or tif
[-JPEGimageQuality "0 through 100"] only applicable when the "imageType" is jpg. Defines the amount of compression used. Must be a value between 0 and 100, 0-max compression and 100-no compression.
[-maxWidth "width in pixels"] the maximum width of the output image
[-maxHeight "width in pixels"] the maximum height of the output image
[-asIcon "yes or no"] when yes the output image is rendered as an icon with a border, shadow, page curl etc.
[-inPath "path"] the path to the file that you want the image
[-outPath "path"] a path for the saved image
[-preferFileIcon "yes or no"] when yes only the file icon is returned even if a preview image exists
[-generatePreviewOnly "yes or no"] when yes only the quicklook preview image is returned. If the preview can't be found then nothing is returned.
Example usage of the tool with applescript: property qlpreviewPath : missing value -- leave this alone, you will be prompted to locate it if needed -- variables, Note: all variables need to be strings set imageType to "png" --> jpg, png, or tif set JPEGimageQuality to "90" --> only applicable when the "imageType" is jpg. Defines the amount of compression used. Must be a value between 0 and 100, 0-max compression and 100-no compression. set maxWidth to "512" --> the maxWidth in pixels of the preview image set maxHeight to "512" --> the maxHeight in pixels of the preview image set asIcon to "no" --> do you want a pretty icon format? set preferFileIcon to "no" -- when yes the file icon is returned even if the preview image exists set generatePreviewOnly to "no" -- when yes then if a preview image can't be found then no image is generated -- get the path to qlpreview if needed try alias qlpreviewPath on error set qlpreviewPath to (choose file with prompt "Please select the unix exe qlpreview..." without invisibles) as text end try -- opening message set m to "This will give you an image file (jpg, png, or tif) containing the Quicklook Preview of a selected file." & return & return & "Current Parameters are:" & return & " Image Type: " & imageType & return & " JPEG Image Quality: " & JPEGimageQuality & return & " maxWidth: " & maxWidth & return & " maxHeight: " & maxHeight & return & " As Icon: " & asIcon & return & " Prefer File Icon: " & preferFileIcon & return & " Generate Preview Only: " & generatePreviewOnly tell me activate set tempVar to display dialog m buttons {"Quit", "Modify Parameters", "Continue"} default button 3 cancel button "Quit" with icon note end tell set br to button returned of tempVar if br is "Modify Parameters" then -- check system version and set the applescript editor aplication appropriately try set sysver to system version of (system info) if sysver is less than "10.6" then set applescriptEditor to "Script Editor" else set applescriptEditor to "AppleScript Editor" end if on error set applescriptEditor to "Script Editor" end try -- open the script set myPath to path to me tell application applescriptEditor activate open myPath end tell else -- get the file you want the preview image of set inPath to choose file with prompt "Choose the file you want the image of:" without invisibles -- where do you want the image saved set inPathName to item 1 of (getName_andExtension(inPath)) tell application "Finder" to set inPathContainerFolder to container of inPath set outPath to choose file name with prompt "Where do you want the output image file saved:" default name (inPathName & "." & imageType) default location (inPathContainerFolder as alias) -- setup the shell command set cmd to quoted form of POSIX path of qlpreviewPath & space & "-imageType" & space & imageType & space & "-JPEGimageQuality" & space & JPEGimageQuality & space & "-maxWidth" & space & maxWidth & space & "-maxHeight" & space & maxHeight & space & "-asIcon" & space & asIcon & space & "-inPath" & space & quoted form of POSIX path of inPath & space & "-outPath" & space & quoted form of POSIX path of outPath & space & "-preferFileIcon" & space & preferFileIcon & space & "-generatePreviewOnly" & space & generatePreviewOnly -- run it! try do shell script cmd on error theError number errorNumber tell me activate display dialog "There was an error:" & return & return & theError & return & return & "Error Number: " & errorNumber as text buttons {"OK"} default button 1 with icon stop end tell end try end if (*=========== SUBROUTINES ============*) on getName_andExtension(f) set f to f as Unicode text set {name:Nm, name extension:Ex} to info for file f if Ex is missing value then set Ex to "" if Ex is not "" then set Nm to text 1 thru ((count Nm) - (count Ex) - 1) of Nm set Ex to "." & Ex end if return {Nm, Ex} end getName_andExtension
Open this Script in your Editor
