• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Help required with Shell Script please...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help required with Shell Script please...


  • Subject: Re: Help required with Shell Script please...
  • From: Axel Luttgens <email@hidden>
  • Date: Sat, 31 Mar 2007 14:16:37 +0200

On 30/03/07 15:21, Nick Hearn wrote:

Hi Luther,

Thanks for the help.
I did ask someone with some unix experience and they helped me along the way.
I ended up with this:-


do shell script "defaults read com.apple.print.customPresets | grep customPresetNames

If I execute that it returns this:-
\"com.apple.print.customPresetNames\" = (\"a4 duplex\", test1);

from which I can get the preset names.

I've also tried your code which works, thanks for that. Gonna have a further tinker with it to extract the preset names only.


Extending Luther's suggestion, it could anyway appear that System Events' Property List Suite woud be better suited to your needs.

Command "defaults" has a lot of limitations.
One of these limitations clearly appears in the above: it is a textual interface for accessing complex data structures; its output thus often needs heavy parsing for just fetching some value of interest.
Another limitation is that it allows to access top-level properties only.


So, this one-liner should provide you with the names of the custom print presets:

tell application "System Events" to get value of property list item "com.apple.print.customPresetNames" of property list file (path of file "com.apple.print.custompresets.plist" of preferences folder)

Note that the returned value is a nice AppleScript list of strings (because the corresponding property in the plist is an array of strings): no parsing needed anymore.

Here follows a commented and heavily decomposed version of the one-liner; it is also extended so as to outline how to access sub-properties:

   tell application "System Events"

-- Assuming we are interested in the logged in user's plist,
-- let's get that plist's path.
set PropertyListPath to path of file "com.apple.print.custompresets.plist" of preferences folder
-- Get a reference to that plist.
set PropertyList to property list file PropertyListPath


       -- The plist may now be accessed as a collection of property
       -- list items.
       tell PropertyList

-- This assumes at least one custom preset has been defined;
-- should then return a list of strings.
set PresetNames to value of property list item "com.apple.print.customPresetNames"


-- If the goal was just to get those names, we are done.
-- But one may dig deeper in the plist's structure too...
-- Let's get a reference to the first preset.
set FirstPreset to property list item (item 1 of PresetNames)
-- Let's get a reference to the corresponding settings.
set FirstPresetSettings to property list item "com.apple.print.preset.settings" of FirstPreset
-- Let's fetch the value of one of those settings.
set FirstPresetCopies to value of property list item "com.apple.print.PrintSettings.PMCopies" of FirstPresetSettings


           -- In the above, values have only been read from the plist.
           -- But one could also set values, in which case they would
           -- be written back to the plist file.

       end tell

   end tell


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

This email sent to email@hidden
References: 
 >Help required with Shell Script please... (From: Nick Hearn <email@hidden>)
 >Re: Help required with Shell Script please... (From: Luther Fuller <email@hidden>)
 >Re: Help required with Shell Script please... (From: Nick Hearn <email@hidden>)

  • Prev by Date: Re: Keystroke in AppleScript
  • Next by Date: Re: Keystroke in AppleScript
  • Previous by thread: Re: Help required with Shell Script please...
  • Next by thread: Selecting existing mail account
  • Index(es):
    • Date
    • Thread