Lately a fellow Mac user contacted me and kindly asked, if it would be possible to automatically switch the currently used printer preset in the print dialog. Working in the graphics industry, he necessarily needs to use specific printer settings for his print jobs, that are all saved in various printer presets.
So I did some research on the topic and quickly found this helpful article on Mac OS X Hints, that describes how to easily switch printer presets in Mac OS X by manipulating a preferences file using the «do shell script» command.
After having a closer look at the «com.apple.print.custompresets.plist» file in my own preferences folder, I wrote a simple sample script which lets you choose a printer preset from a list and then sets this printer preset as the currently used printer preset:
The script contains two AppleScript functions:
1. One for getting a list of all available printer presets (getcustompresetnames)
2. for setting the currently used printer preset (setcurpresetname)
It was successfully tested on Mac OS X 10.5.2, but may also work on earlier incarnations of our beloved operating system.
-- created: 21.03.2008
property mytitle : "Set printer preset"
-- I let the user select a printer preset to be set as the current printer preset
on run
-- getting a list of available printer presets
set custompresetnames to my getcustompresetnames()
-- no printer presets found :(
if custompresetnames is {} then
tell me
activate
display dialog "Sorry, we could not find any printer preset names." buttons {"OK"} default button 1 with icon stop with title mytitle
end tell
-- printer presets found
else
choose from list custompresetnames with prompt "Please choose a printer preset:" with title mytitle without multiple selections allowed and empty selection allowed
set choice to result
if choice is not false then
set presetname to item 1 of choice
-- settings the printer preset
my setcurpresetname(presetname)
end if
end if
end run
-- I am returning all preset names available in the print dialog
-- (in case the corresponding preferences file does not yet exist
-- or no preset names are listed, I will return an empty list)
on getcustompresetnames()
set custompresetnames to {}
set prefsfolderpath to POSIX path of ((path to preferences folder from user domain) as Unicode text)
set prefsfilepath to prefsfolderpath & "com.apple.print.custompresets.plist"
try
tell application "System Events"
set fileobj to property list file prefsfilepath
set custompresetnames to value of property list item "com.apple.print.customPresetNames" of contents of fileobj
end tell
end try
return custompresetnames
end getcustompresetnames
-- I am switching the current printer preset to the given preset name
on setcurpresetname(presetname)
set cmd to "defaults write com.apple.print.custompresets com.apple.print.lastPresetPref -string " & quoted form of presetname
set cmd to cmd as «class utf8»
do shell script cmd
end setcurpresetname