Desktop Settings via Script

Forum rules
Before you post please read how to get help
Post Reply
macx979
Level 1
Level 1
Posts: 2
Joined: Sat Jan 11, 2020 10:29 am

Desktop Settings via Script

Post by macx979 »

Hi,

I've been using Linux Mint for quite some time and recently updated to Tricia 19.3
In order to reduce the amount of work in case I reinstall the system or apply it on another computer of mine, I wrote a bash script to do install all needed programs, to create Startup Applications, mount Networks shares etc.
This works all fine but there is still some manual work to be done after this script finished. Mainly Desktop tweaks.

I was wondering how I could also automate these tweaks. I read about dconf but I tought it maybe easier to set up the desktop once and copy the files where these settings are located. Is that actually possible and where are these files located? Furthermore is dconf maybe the better option?

This I do manually at the moment:
- arrange both screens and change resolution

- Pin some folders in Nemo in my Home directory
- Pull some folders in Nemo to the favourite bar on the right side in Nemo

- Download and apply applets to the panel
- Add a second panel to my second screen and add applets to it

- Add programs from start menu to my panel
- create a new item in menu editor for start menu and add it to my panel

of course that's not that much of work to do manually after installation, however having these settings part of my script would be awesome.

any help is appreciated

Best
macx

User avatar
smurphos
Level 15
Level 15
Posts: 5567
Joined: Fri Sep 05, 2014 12:18 am
Location: Britisher
Contact:

Re: Desktop Settings via Script

Post by smurphos »

Hi,

Welcome to the forums. This may help... :)

Pin some folders in Nemo in my Home directory

You can use the command line tool gio to set this. The pin status is part of the files metadata stored in the gvfs backend.

Example command

Code: Select all

gio set ~/Pictures metadata::pinned-to-top true
Pull some folders in Nemo to the favourite bar on the right side in Nemo

The bookmark data is stored in the file ~/.config/gtk-3.0/bookmarks. The format for each line is

Code: Select all

file:///path/to/folder display_name
You could echo individual lines to this file with your script e.g.

Code: Select all

echo "file:///opt opt" > ~/.config/gtk-3.0/bookmarks
or write the whole file from your script in one go using tee ... (example command is writing my bookmarks file)

Code: Select all

tee ~/.config/gtk-3.0/bookmarks <<EOB
file:///mnt/backup_drive backup_drive
file:///mnt/virtualbox_images virtualbox_images
file:///home/steve/plex_server_drive Plex Drive
file:///home/steve/google_drive Google Drive
file:///home/steve/Downloads Downloads
file:///home/steve/Documents Documents
file:///home/steve/Music Music
file:///home/steve/Podcasts Podcasts
file:///home/steve/Pictures Pictures
file:///home/steve/Screenshots Screenshots
file:///home/steve/Videos Videos
file:///home/steve/Vbox_Shares Vbox_Shares
file:///home/steve/KeepPass KeepPass
file:///home/steve/Github Github
file:///home/steve/.local/bin ~/.local/bin
file:///home/steve/.local/share/nemo/actions Nemo Actions
file:///usr/share /usr/share
file:///etc /etc
EOB
Download and apply applets to the panel

You can wget the latest copy of the applet from Cinnamon Spices and then unzip it to your local applets directory.

E.g this will grab the weather applet and unzip it to the correct location

Code: Select all

cd /tmp
wget https://cinnamon-spices.linuxmint.com/files/applets/weather@mockturtl.zip
unzip -o weather@mockturtl.zip -d ~/.local/share/cinnamon/applets
cd
Applying applets to the panel is a bit more complicated and this is where dconf comes in.

The panel layouts and active applets are stored as keys in the dconf database along with a whole bunch of other Desktop Environment and some application specific settings. You could use gsettings set or dconf write to write to individual keys.

Enabled applets are stored as one long string. Here I'm using dconf read to check the current value of my enabled applets

Command

Code: Select all

dconf read /org/cinnamon/enabled-applets
Output

Code: Select all

['panel1:right:6:notifications@cinnamon.org:4', 'panel1:right:8:printers@cinnamon.org:5', 'panel1:right:9:removable-drives@cinnamon.org:6', 'panel1:right:10:keyboard@cinnamon.org:7', 'panel1:right:13:sound@cinnamon.org:10', 'panel1:right:15:power@cinnamon.org:11', 'panel1:right:16:calendar@cinnamon.org:12', 'panel1:left:1:weather@mockturtl:16', 'panel1:right:2:spices-notifier@germanfr:19', 'panel1:right:7:capture@rjanja:21', 'panel1:right:14:inhibit@cinnamon.org:23', 'panel1:right:11:blueberry@cinnamon.org:24', 'panel1:right:12:network@cinnamon.org:31', 'panel1:right:5:SpicesUpdate@claudiux:66', 'panel1:left:3:grouped-window-list@cinnamon.org:71', 'panel1:left:0:menu@cinnamon.org:72', 'panel1:right:3:xapp-status@cinnamon.org:78', 'panel1:right:4:gnote@brett-smith:79', 'panel1:right:1:systray@cinnamon.org:81', 'panel1:left:2:spacer@cinnamon.org:82']
What does the output mean? Looking at one sub-entry - 'panel1:left:1:weather@mockturtl:16' it's showing that the weather applet is on panel 1, is the 2nd applet in the left zone (0 is the first applet), and it's settings file is ~/.cinnamon/configs/weather@mockturtl/16.json

To replicate this layout from a script I could use dconf write

E.g.

Code: Select all

dconf write /org/cinnamon/enabled-applets "['panel1:right:6:notifications@cinnamon.org:4', 'panel1:right:8:printers@cinnamon.org:5', 'panel1:right:9:removable-drives@cinnamon.org:6', 'panel1:right:10:keyboard@cinnamon.org:7', 'panel1:right:13:sound@cinnamon.org:10', 'panel1:right:15:power@cinnamon.org:11', 'panel1:right:16:calendar@cinnamon.org:12', 'panel1:left:1:weather@mockturtl:16', 'panel1:right:2:spices-notifier@germanfr:19', 'panel1:right:7:capture@rjanja:21', 'panel1:right:14:inhibit@cinnamon.org:23', 'panel1:right:11:blueberry@cinnamon.org:24', 'panel1:right:12:network@cinnamon.org:31', 'panel1:right:5:SpicesUpdate@claudiux:66', 'panel1:left:3:grouped-window-list@cinnamon.org:71', 'panel1:left:0:menu@cinnamon.org:72', 'panel1:right:3:xapp-status@cinnamon.org:78', 'panel1:right:4:gnote@brett-smith:79', 'panel1:right:1:systray@cinnamon.org:81', 'panel1:left:2:spacer@cinnamon.org:82']"
You might want to consider backing up and restoring the applet config files in ~/.cinnamon/configs as-well.

Add a second panel to my second screen and add applets to it

Panel layout is also stored in dconf.

To get the current layout

Code: Select all

dconf read /org/cinnamon/panels-enabled

returns this for me

Code: Select all

['1:0:top']
Which is one panel on the top of monitor 0

To add a second panel on the left of the same monitor

Code: Select all

dconf write /org/cinnamon/panels-enabled "['1:0:top', '2:0:left']"
Add programs from start menu to my panel

Assuming use of the grouped window list this is most easily done by backing up and restoring the entire config file for your grouped window list - ~/.cinnamon/configs/grouped-window-list@cinnamon.org/*.json

Create a new item in menu editor for start menu and add it to my panel

You can write a desktop file for the menu entry to ~/.local/share/applications using the tee method outlined above.

An example desktop file for an extra menu entry for the terminal application htop.

Code: Select all

cat ~/.local/share/applications/Htop.desktop
Output

Code: Select all

[Desktop Entry]
Name=Htop
Exec=htop
Comment=
Terminal=true
Icon=htop
Type=Application
Categories=Utility;
Arrange both screens and change resolution

You may be able to write the file ~/.config/monitors.xml using the tee method outlined above. Hardware specific differences may cause an issue. I.m not sure....

Example content of the file (this is for a single laptop display only)

Code: Select all

cat ~/.config/monitors.xml

Code: Select all

<monitors version="1">
  <configuration>
      <clone>no</clone>
      <output name="eDP-1">
          <vendor>BOE</vendor>
          <product>0x0819</product>
          <serial>0x00000000</serial>
          <width>1920</width>
          <height>1080</height>
          <rate>60</rate>
          <x>0</x>
          <y>0</y>
          <rotation>normal</rotation>
          <reflect_x>no</reflect_x>
          <reflect_y>no</reflect_y>
          <primary>yes</primary>
      </output>
      <output name="HDMI-1">
      </output>
      <output name="DP-1">
      </output>
      <output name="HDMI-2">
      </output>
  </configuration>
</monitors>
For custom Nemo actions, useful scripts for the Cinnamon desktop, and Cinnamox themes visit my Github pages.

macx979
Level 1
Level 1
Posts: 2
Joined: Sat Jan 11, 2020 10:29 am

Re: Desktop Settings via Script

Post by macx979 »

Damn it,

that's by far the best answer I got on a forum since ages. :D
Great detailed explanation and everything works like charm. Thank you very much :!:

two more questions:
Is there a command to add a panel to my second screen?
And how can I change the font size in terminal?

Best
macx

User avatar
smurphos
Level 15
Level 15
Posts: 5567
Joined: Fri Sep 05, 2014 12:18 am
Location: Britisher
Contact:

Re: Desktop Settings via Script

Post by smurphos »

macx979 wrote:
Sun Jan 12, 2020 11:41 am
that's by far the best answer I got on a forum since ages. :D
Great detailed explanation and everything works like charm. Thank you very much :!:

two more questions:
Is there a command to add a panel to my second screen?
And how can I change the font size in terminal?
No worries you are welcome.

For the font size in the terminal you can set the systems monospace font size e.g.

Code: Select all

dconf write /org/gnome/desktop/interface/monospace-font-name "'Monospace 12'"
For the panel on the 2nd screen it should just be a case of referencing that screen in the dconf key /org/cinnamon/panels-enabled e.g. for a top panel on both monitors.

Code: Select all

dconf write /org/cinnamon/panels-enabled "['1:0:top', '2:1:top]"
I can't test the latter command as I don't have a second screen to hand at the minute.

A few other hints you might find helpful..

Dconf-editor is a GUI app that allows you to explore and amend the dconf database. You may find it a useful way of exploring what settings are stored there. apt install dconf-editor in a terminal to install.

You can also use the command below left running in a terminal to watch the dconf database for changes as you change settings via the normal GUI. This is a good way of idetifying relevant keys.

Code: Select all

dconf watch /
Finally it is possible to backup and restore the dconf database in full or in part. Beware if you are going to use this to restore in your script it is best run whilst not logged in to the GUI. E,g access a TTY from the login screen with Ctrl-Alt-F1, login there and run the script.

The command to backup the whole dconf database to a text file called my_dconf_backup is

Code: Select all

dconf dump / > my_dconf_backup
to restore

Code: Select all

dconf load / < my_dconf_backup
You can narrow this down to a subset of keys E.g just to do the keys under /org/cinnamon/

Code: Select all

dconf dump /org/cinnamon/ > my_cinnamon_dconf_backup

Code: Select all

dconf load /org/cinnamon/ < my_cinnamon_dconf_backup
You can peruse the text files created this way with a text editor to review the content.
For custom Nemo actions, useful scripts for the Cinnamon desktop, and Cinnamox themes visit my Github pages.

Post Reply

Return to “Scripts & Bash”