Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: shell script - duplex printing prefs



On Mar 31, 2007, at 1:39 PM, Axel Luttgens wrote:

Assuming a preset "Test" already exists, you could do something like this:

tell application "System Events"
tell property list file (path of file "com.apple.print.custompresets.plist" of preferences folder)
-- Set duplexing of preset "Test" to wanted value.
set value of property list item "com.apple.print.PrintSettings.PMDuplexing" of property list item "com.apple.print.preset.settings" of property list item "Test" to 2
-- Make sure preset "Test" is selected.
set value of property list item "com.apple.print.lastPresetPref" to "Test"
end tell
end tell

This may work with your file "com.apple.print.custompresets.plist", but it will NOT work on mine. A command such as ...


tell application "System Events"
	set value of property list item "x" of property list file "y"
end tell

will work without error only if property list item "x" already exists in property list file "y". If it does not exist, then "System Events" will error without warning (in other words, your script mysteriously dies). My copy of "com.apple.print.custompresets.plist" contains only the value "com.apple.print.lastPresetPref" = "Standard" and will therefore crash this script.

This is why you need to read the value of the entire plist file into a record; then concatenate new items to the record; then set new values; then write the entire record back to the plist file.

Knowing the rules for concatenating records properly is a necessity.

_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/applescript-users/email@hidden
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden
References: 
 >shell script - duplex printing prefs (From: Nick Hearn <email@hidden>)
 >Re: shell script - duplex printing prefs (From: Axel Luttgens <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.