Skip to content

Instantly share code, notes, and snippets.

@rockpapergoat
Created March 7, 2012 01:39
Show Gist options
  • Save rockpapergoat/1990335 to your computer and use it in GitHub Desktop.
Save rockpapergoat/1990335 to your computer and use it in GitHub Desktop.
getting and setting prefs from a plist in macruby
#!/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