Easier way to access the OSX defaults system through Python and Ruby? -


recently have become fan of storing various settings used testing scripts in osx defaults system allows me keep various scripts in git , push them github without worrying leaving passwords/settings/etc hardcoded script.

when writing shell script using simple bash commands, easy enough use backticks call defaults binary read preferences , if there error reading preference, script stops execution , can see error , fix it. when try similar thing in python or ruby tends little more annoying since have additional work check return code of defaults see if there error.

i have been attempting search via google off , on library use osx defaults system ends being difficult when "defaults" part of query string.

i thought of trying read plist files directly seems plist libraries have found (such built in python one) able read xml ones (not binary ones) problem if ever set defaults program since convert binary plist.

recently while trying search python library changed search terms using nsuserdefaults (i have forgotten exact term) found python library called userdefaults developed older version of osx (10.2) older version of python (2.3) , have not had luck in getting compile on osx 10.6 , python 2.6

ideally find library make easy read (and bonus write to) osx defaults system in way similar following python psudo code.

from some.library.defaults import defaults settings = defaults('com.example.app') print settings['setting_key'] 

since starting use ruby more, find ruby library similar functionality.

it may have 'give up' , write own simple library around defaults binary thought wouldn't hurt try query others see if there existing solution.

you´ll want use pyobjc: have @ this article @ mactech.com (in specific: scroll down "accessing plists via python"). , this article oreilly on pyobjc. run this, example:

from foundation import * standarduserdefaults = nsuserdefaults.standarduserdefaults() persistentdomains = standarduserdefaults.persistentdomainnames() persistentdomains.objectatindex_(14) adomain = standarduserdefaults.persistentdomainforname_(persistentdomains[14]) adomain.keys() 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -