How can I install a Gsettings Schema without root privileges?
You can copy and compile your Gsettings Schemas to a user-writable directory:
$ cp com.companyname.appname ~/schemas/
$ glib-compile-schemas ~/schemas/
The tricky bit is to configure the application to use that particular directory. There are two ways to do this:
-
With the
GSETTINGS_SCHEMA_DIR
environment variable:$ GSETTINGS_SCHEMA_DIR=~/schemas/ ./example.py
-
Or using GSettingsSchemaSource and GSettingSchema objects:
If you have access to the source code of your program, you can modify it to load compiled schemas from any directory. Here's how would do it in Python, although you could do this in any programming language with GObject introspection:
schema_source = Gio.SettingsSchemaSource.new_from_directory( os.path.expanduser("~/schemas"), Gio.SettingsSchemaSource.get_default(), False, ) schema = schema_source.lookup('com.companyname.appname', False) settings = Gio.Settings.new_full(schema, None, None) settings.set_boolean('mybool', True)
References:
- C API documentation for GSettingsSchema and GSettingsSchemaSource
- Introductory blog post about GSettings in Python
Related videos on Youtube
Day
Updated on September 18, 2022Comments
-
Day over 1 year
Hello I'm trying to play a sound in java the code looks like this:
public void playSound(String sound) { try { InputStream in = new FileInputStream(new File(sound)); AudioStream audio = new AudioStream(in); AudioPlayer.player.start(audio); } catch (Exception e) {} }
I imported sun.audio*; however get an error:
Access restriction: The type 'AudioPlayer' is not API (restriction on required library 'C:\Program Files\Java\jre7\lib\rt.jar')
-
Brian over 9 yearsSee also stackoverflow.com/questions/860187/…
-
Modus Tollens over 9 yearsSee also stackoverflow.com/a/22032338
-
-
MadProgrammer over 9 yearsNit pick: You really don't need the frame, it's just clutter, but having said that, there's no reason to extend from
JFrame
as you're adding no new functionality to the class and you should be be ensuring that the UI is constructed within the context of the Event Dispatching Thread. See Initial Threads for more details -
Day over 9 yearsThank you so much! This works really great, and because of the way it works I can have multiple sounds over lapping each other (like music and sound effects)
-
TroniPM over 7 years2016 and this code still works in java 8 (only one that worked for me, btw). PS: ONLY works with .wav extension (do not try to use mp3).
-
Pietro Battiston almost 7 yearsDo you also know how to check if a given schema is already installed (and do the above only if it is not)?
-
ntc2 over 5 yearsAccording to these docs you can also add the directory containing the
glib-2.0/schemas
directory to theXDG_DATA_DIRS
environment variable. -
Dhruv Erry almost 4 yearsThis works perfectly. Is there a way to control the volume?