How can I install a Gsettings Schema without root privileges?

18,991

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:

Share:
18,991

Related videos on Youtube

Day
Author by

Day

Updated on September 18, 2022

Comments

  • Day
    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')

  • MadProgrammer
    MadProgrammer over 9 years
    Nit 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
    Day over 9 years
    Thank 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
    TroniPM over 7 years
    2016 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
    Pietro Battiston almost 7 years
    Do you also know how to check if a given schema is already installed (and do the above only if it is not)?
  • ntc2
    ntc2 over 5 years
    According to these docs you can also add the directory containing the glib-2.0/schemas directory to the XDG_DATA_DIRS environment variable.
  • Dhruv Erry
    Dhruv Erry almost 4 years
    This works perfectly. Is there a way to control the volume?