Created
March 7, 2012 01:39
-
-
Save rockpapergoat/1990335 to your computer and use it in GitHub Desktop.
getting and setting prefs from a plist in macruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/local/bin/macruby | |
| # nb. http://stackoverflow.com/questions/8738424/macruby-how-to-create-an-app-that-can-be-configured-from-the-outside | |
| framework 'Cocoa' | |
| framework 'Foundation' | |
| def set_prefs(pref) | |
| if File.exists?(pref) | |
| @config = load_plist File.read(pref) | |
| plist = {} | |
| plist["version"] = "0.4" | |
| plist["url"] = "http://google.com" | |
| plist["menuicon"] = "blue.png" | |
| plist["abouticon"] = "logo.png" | |
| #plist["date"] = NSDate.date | |
| unless @config.isEqualToDictionary(plist) | |
| plist.writeToFile(pref, :atomically => true) | |
| end | |
| end | |
| end | |
| def get_prefs(pref) | |
| @config = load_plist File.read(pref) | |
| end | |
| def get_key(plist,key) | |
| plist[key] | |
| end | |
| pref = "/tmp/com.rockpapergoat.menu.plist" | |
| set_prefs(pref) | |
| puts get_key(get_prefs(pref),"version") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment