Xfce Forum

Sub domains
 

You are not logged in.

#1 2014-02-05 17:15:02

pandageek
Member
Registered: 2014-02-05
Posts: 3

how to make a script to modify xfce4 panel?

Hello!

I want to know how to modify the panel (or create another one if it's easier), setting launchers and options, in command line.

I found the xfconf-query command but i've no idea how to use it and i don't understand the documentation  http://docs.xfce.org/xfce/xfconf/xfconf-query

I hope you can help me!

Thanks

Offline

#2 2014-02-06 13:18:28

wtsch
Member
Registered: 2010-06-09
Posts: 27

Re: how to make a script to modify xfce4 panel?

Why? Different settings for different users?

Offline

#3 2014-02-06 13:54:12

ToZ
Moderator
From: Toronto, Canada
Registered: 2011-06-02
Posts: 2,984

Re: how to make a script to modify xfce4 panel?

Setting options is easy. You can either look at the Settings Editor to see a graphic display of the configuration tree, or for xfce4-panels:

To view the panel IDs:

xfconf-query -c xfce4-panel -p /panels

To view the settings for a specific ID (in my case. panel-1):

xfconf-query -c xfce4-panel -p /panels/panel-1 -lv

To change one of the non-array settings (ie enable autohide):

xfconf-query -c xfce4-panel -p /panels/panel-1/autohide -s true

...and to disable it again:

xfconf-query -c xfce4-panel -p /panels/panel-1/autohide -s false

Working with array values is tougher because I don't think xfconf allows you to manipulate individual elements of the array. And since creating a new panel or a launcher requires array manipulation, it may not be possible. You might be able to create a wrapper function to read, store and re-write the array values (as a complete set), but I've never tested this.


How To Ask For Help           Xfce FAQ                            Xfce Release Information
The Xfce Community          Xfce Tips and Tricks

Offline

#4 2014-02-06 16:57:34

pandageek
Member
Registered: 2014-02-05
Posts: 3

Re: how to make a script to modify xfce4 panel?

thanks it works great!

where can i find the list of option to modify (like height, width, color, shortcurts,...)?

Offline

#5 2014-02-06 18:36:10

ToZ
Moderator
From: Toronto, Canada
Registered: 2011-06-02
Posts: 2,984

Re: how to make a script to modify xfce4 panel?

pandageek wrote:

thanks it works great!

where can i find the list of option to modify (like height, width, color, shortcurts,...)?

I'm not sure I understand, but if you're asking which properties are available for modification, look at the Settings Editor (found in the Settings Manager or by running "xfce4-settings-editor").


How To Ask For Help           Xfce FAQ                            Xfce Release Information
The Xfce Community          Xfce Tips and Tricks

Offline

#6 2014-02-06 20:07:55

pandageek
Member
Registered: 2014-02-05
Posts: 3

Re: how to make a script to modify xfce4 panel?

Thanks!
i can modify what i want exept one thing :
How can i add a launcher?

Last edited by pandageek (2014-02-06 20:25:50)

Offline

#7 2014-02-06 20:43:52

ToZ
Moderator
From: Toronto, Canada
Registered: 2011-06-02
Posts: 2,984

Re: how to make a script to modify xfce4 panel?

As I explained earlier, it won't be easy (impossible?) because you need to manipulate array values (see panel-1/plugin-ids) and as far as I know, xfconf-query can't manipulate individual elements of an array (I might be wrong, but I can't find any info on how to do this). Thinking out loud, you may be able to create a wrapper function to read, store and re-write the array as a complete set, but these are uncharted waters (don't know if its possible).

As for what needs to be done, I would guess an array element would need to be added to /panel-Y/plugin-ids that corresponds to an entry in /plugins/plugin-XX of which the items array property points a desktop file in ~/.config/xfce4/panel/launcher-XX (where Y is a panel ID and where XX is a unique numeric value).


How To Ask For Help           Xfce FAQ                            Xfce Release Information
The Xfce Community          Xfce Tips and Tricks

Offline

#8 2014-02-07 02:20:45

MountainDewManiac
Member
From: USA police-state welfare-state
Registered: 2013-03-24
Posts: 770

Re: how to make a script to modify xfce4 panel?

It's not a "command line" solution, but can't you just find the app you want in your desktop menu, drag (a representation of) it from there to the desktop, and then on to the panel you wish to place the launcher on?

Regards,
MDM


Mountain Dew Maniac

How to Ask for Help <=== Click on this link

Offline

#9 2014-02-07 17:10:56

ToZ
Moderator
From: Toronto, Canada
Registered: 2011-06-02
Posts: 2,984

Re: how to make a script to modify xfce4 panel?

DISCLAIMER: Be very careful with this code. If possible, test on spare system or in a vm. This works on my test system (in this case fedora), but I can't vouch for others. You have been warned.

Here are some steps for manually adding the abiword launcher to the bottom panel.

Informational

# list all panel properties

xfconf-query -c xfce4-panel -p /panels -lv

# list panel IDs

xfconf-query -c xfce4-panel -p /panels | grep -v "Value is an\|^$"

# list all panel plugins info (going to model after existing launcher plugin)

xfconf-query -c xfce4-panel -p /plugins -lv

Add launcher to panel-2

# 1. determine launcher id number to use - must be unique. (using 16). Determine the id of the panel to add to - must exist (using 2).

# 2. create the launcher directory (~/.config/xfce4/panel/launcher-xx)

mkdir ~/.config/xfce4/panel/launcher-16

# 3. copy launcher's .desktop file into that folder

cp /usr/share/applications/abiword.desktop ~/.config/xfce4/panel/launcher-16

# 4. create the plugin xfconf entry
# 4a. create the plugin group

xfconf-query -c xfce4-panel -p /plugins/plugin-16 -t string -s "launcher" --create

# 4b. create the plugin items property

xfconf-query -c xfce4-panel -p /plugins/plugin-16/items -t string -s "abiword.desktop" -a --create

# 5. add the new plugin ID to the existing panel array of plugins
# 5a. list the current contents of the array (make note of results for future use)

xfconf-query -c xfce4-panel -p /panels/panel-2/plugin-ids| grep -v "Value is an\|^$"

# 5b. delete the plugin-ids array

xfconf-query -c xfce4-panel -p /panels/panel-2/plugin-ids -rR

# 5c. re-create the array using the old existing ids + the new id, placing them in the order they are to be displayed (inserting 16)

xfconf-query -c xfce4-panel -p /panels/panel-2/plugin-ids -t int -s 7 -t int -s 8 -t int -s 9 -t int -s 16 -t int -s 10 -t int -s 11 -t int -s 12 -t int -s 13 -t int -s 14 --create

# 6. restart xfce4-panel

xfce4-panel -r

How To Ask For Help           Xfce FAQ                            Xfce Release Information
The Xfce Community          Xfce Tips and Tricks

Offline

#10 2016-09-25 15:37:33

luvr
Member
From: Boom ("Tomorrowland"), Belgium
Registered: 2016-09-25
Posts: 3

Re: how to make a script to modify xfce4 panel?

ToZ wrote:

# 3. copy launcher's .desktop file into that folder

cp /usr/share/applications/abiword.desktop ~/.config/xfce4/panel/launcher-16

Not sure if I'm supposed to resurrect an old thread such as this one, but here's a little Perl script to create a typical ".desktop" file for an XFCE launcher item:

#!/usr/bin/perl

use Glib ;

$x_xfce_source = $ARGV [ 0 ] ;
$x_xfce_dest   = $ARGV [ 1 ] ;

$keyfile =  Glib::KeyFile -> new ;
$keyfile -> load_from_file ( $x_xfce_source , 'G_KEY_FILE_NONE' ) ;
$keyfile -> set_string     ( 'Desktop Entry', 'X-XFCE-Source'   , Glib -> filename_to_uri ( $x_xfce_source , undef ) ) ;

open  OUTPUT_FILE , '>' . $x_xfce_dest ;
print OUTPUT_FILE $keyfile -> to_data  ;
close OUTPUT_FILE ;

It requires two command-line arguments:

  1. The full path to the source ".desktop" file, e.g., /usr/share/applications/abiword.desktop;

  2. The full path to the destination file, e.g., ~/.config/xfce4/panel/launcher-16/147481732321.desktop.

By the way, I have recently developed a Bash script that sets up the XFCE panels for me. If anyone is interested, I won't mind posting it here.

Offline

#11 Yesterday 00:54:11

ToZ
Moderator
From: Toronto, Canada
Registered: 2011-06-02
Posts: 2,984

Re: how to make a script to modify xfce4 panel?

Thanks for posting the script - I'm sure it will be helpful

luvr wrote:

By the way, I have recently developed a Bash script that sets up the XFCE panels for me. If anyone is interested, I won't mind posting it here.

Feel free to post it - I'm sure it will be useful to someone and this will be a good reference place for it.

BTW, welcome to the forum.


How To Ask For Help           Xfce FAQ                            Xfce Release Information
The Xfce Community          Xfce Tips and Tricks

Offline

#12 Yesterday 17:23:21

luvr
Member
From: Boom ("Tomorrowland"), Belgium
Registered: 2016-09-25
Posts: 3

Re: how to make a script to modify xfce4 panel?

If you want to develop a shell script to set up your Xfce panels, then you will obviously have to understand how you can access the Xfce configuration from the command line. In this post, I will explain what I learned in order to write such a script.

The “Xfconf” Configuration Storage System

The configuration of the Xfce desktop—including the panels—is maintained by the Xfconf storage system. As the Xfce documentation describes it:

Xfconf is a hierarchical (tree-like) configuration system where the immediate child nodes of the root are called “channels”. All settings beneath the channel nodes are called “properties”.

Querying the “Xfconf” Configuration Storage System

To access the Xfconf configuration data from the command line, you can run the “xfconf-query” utility. In its simplest form, the xfconf-query command will list the Xfconf channels—e.g.:

$ xfconf-query --list

The output from this command will look something like this:

Channels:
  thunar-volman
  xsettings
  displays
  ristretto
  thunar
  xfce4-desktop
  xfce4-power-manager
  xfce4-mixer
  xfce4-session
  xfce4-panel
  xfce4-appfinder
  xfce4-keyboard-shortcuts
  xfce4-settings-editor
  xfwm4
  keyboards

If you want to access the panel settings, then you can list the contents of the “xfce4-panel” channel:

$ xfconf-query --channel 'xfce4-panel' --list

This command will list all properties that the Xfconf system maintains about the panels and the plugins that you added to them.

To view the value of one specific property, you can specify it on the “xfconf-query” command line—e.g.:

$ xfconf-query --channel 'xfce4-panel' --property '/panels'

Assuming that you are using a dual-panel setup, the output will, then, look like the following:

Value is an array with 2 items:

1
2

Note: The actual panel ids may be different. Under Xubuntu, for instance, panel ids apparently start counting from 0, instead of 1, by default.

You can also list all subproperties of a specific property, like so:

$ xfconf-query --channel 'xfce4-panel' --property '/panels' --list

If you want to obtain not only the names, but also the values of the listed properties, then you can request verbose output:

$ xfconf-query --channel 'xfce4-panel' --property '/panels' --list --verbose

Some values may be displayed as “<<UNSUPPORTED>>”; these are array values, which will get displayed only if you query their specific properties—e.g.:

$ xfconf-query --channel 'xfce4-panel' --property '/panels/panel-1/plugin-ids'

Setting Properties in the “Xfconf” Configuration Storage System

Perhaps contrary to what its name implies, the xfconf-query command can also update values in the Xfconf system. Furthermore, it can optionally create a property if it does not yet exist.

To set a single-valued (i.e., non-array) property, you will have to specify both its type and its value. Three types are supported:

  • “bool”—A boolean value, either “true” or “false”;

  • “int”—An integer value;

  • “string”—A character string.

Of course, the value to which you want to set a property will have to match its type.

As an example, you may decide that you want to modify the size of your first panel (i.e., for a horizontal panel, its height, or, for a vertical panel, its width). First, you may want to find out what its current size is:

$ xfconf-query --channel 'xfce4-panel' --property '/panels/panel-1/size'

The following command will, then, modify the panel size to 32:

$ xfconf-query --channel 'xfce4-panel' --property '/panels/panel-1/size' --type int --set 32

The above command will happily update an existing property, but it will refuse to create one that does not yet exist. If you want to make sure that the property will be set, even if it is a new one, then you will have to specify the “--create” option:

$ xfconf-query --channel 'xfce4-panel' --property '/panels/panel-1/size' --create --type int --set 32

To set an array property, you will have to repeat the “--type” and “--set” options for each successive array element. There is no option to remove an element from an array, or to add an element to it; you will have to set the entire array from scratch whenever you want to modify it in any way.

For instance, if you want to add a panel, then you will first have to query the currently active panel ids:

$ xfconf-query --channel 'xfce4-panel' --property '/panels'

Value is an array with 2 items:

1
2

The following command will, then, add a third panel to your setup:

$ xfconf-query --channel 'xfce4-panel' --property '/panels' --type int --set 1 --type int --set 2 --type int --set 3

Even though the new panel will not show up on your desktop, it will have been added to the “/panels” array. To actually display the new panel, you can restart the running panel instance:

$ xfce4-panel --restart

Note that, in order to set up an array, you will have to specify at least two values; if you enter only one value, then the xfconf-query command will create a single-valued property instead. If you ever need to create an array with just a single value, then you will have to use the “--force-array” option—e.g., to request just a single panel:

$ xfconf-query --channel 'xfce4-panel' --property '/panels' --force-array --type int --set 1

Note: The --force-array option is supported, but entirely optional, if you specify multiple values on an array assignment.

Deleting Properties from the “Xfconf” Configuration Storage System

If you created a third panel, as discussed above, and subsequently updated the “/panels” array to remove the new panel again, then any of its properties will remain present in the Xfconf system—as the following command will demonstrate:

$ xfconf-query --channel 'xfce4-panel' --property '/panels/panel-3' --list

Unless you made any modifications to its setup, only the “/panels/panel-3/position” property will be listed.

To delete the value of a property, you can run the xfconf-query command with the “--reset” option—e.g.:

$ xfconf-query --channel 'xfce4-panel' --property '/panels/panel-3/position' --reset

Additionally, if you want to delete a property, and all properties beneath it, then you can add the “--recursive” option to the command:

$ xfconf-query --channel 'xfce4-panel' --property '/panels/panel-3' --reset --recursive

Closing Notes

Once you understand how you can access the “Xfconf” system from the command line, you are ready to study the types of plugins that can be added to the Xfce panels, and the methods to configure them. Some plugins, such as the Clock or the Separator, will keep their configuration entirely within the “Xfconf” storage hierarchy, while other plugins, such as the Network Monitor or the Weather Update, store their settings in external resource files. In addition, the Launcher plugin is a special case, in that it uses “.desktop” files to determine which items it will provide.

Offline

Board footer

Powered by FluxBB