我目前在Gjs上構建了一個簡單的應用程序,它將更改我的gnome-shell的背景圖像。有關如何使用gsettings
-tool可以完成的解決方案可以在here找到。無法用GSettings更改dconf-entry
由於我想圍繞它構建一個桌面應用程序,因此我想通過使用Gio的GSettings
-class來更改org.gnome.desktop.background.picture-uri
-key。但使用set_X()
-method不會更改密鑰的值。
這是我的代碼更改gsettings值:
var gio = imports.gi.Gio;
// Get the GSettings-object for the background-schema:
var background = new gio.Settings({schema: "org.gnome.desktop.background"});
// Read the current Background-Image:
print("Current Background-Image: "+background.get_string("picture-uri"));
if (background.is_writable("picture-uri")){
// Set a new Background-Image (should show up immediately):
if (background.set_string("picture-uri", "file:///path/to/some/pic.jpg")){
print("Success!");
}
else throw "Couldn't set the key!";
} else throw "The key is not writable";
讀值不按預期方式工作, - 方法返回true
和set_string()
- 方法也返回true
的is_writable()
。
我檢查過我沒有處於「延遲應用」模式,並且該鍵有字符串GVariantType
,所以set_string()
-方法應該可以工作。
使用正常的gsettings
命令行工具(如鏈接文章中所述)工作得很好。
我找不出什麼問題,有沒有地方可以查找日誌或什麼?
自昨天以來,我一直在爲這個問題而頭痛,並且很高興終於找到了解決方案。謝謝! – Serrano 2013-09-02 17:00:17