Workspace contents at startup -- Ubuntu 15.04 Mate

I like to run with at least six workspaces, with each one running a different mix. Three with Chrome, and the rest with programmes such as Gimp, Fotoxx, Bluefish, and Libre.

Pluma, Monitor, Yakuake (don’t like Tilda) on all workspaces.

But I have to set them all up anew at every reboot.

Is there a way to make Mate start up with the same stuff in each workspace every time?

Are there config files somewhere that can be edited to control this kind of thing?

2 Likes

This is a great question and I would love to know the answer as well!

There’s probably any number of GUIs that will do something like this, such as gDevilspie, by searching on “ubuntu automatically start programs in workspace” but by the time you figure out the configuration and/or write the rules, to me is easier to just write a simple shell script in a text editor, change its permissions to make it executable, and create an entry in Start Up Applications to call it (/home/me/myscript.sh)

#!/bin/bash
wmctrl -s 0 #Workspace 1
pluma &
sleep 2
firefox &
sleep 2
wmctrl -s 1 #Workspace 2
pluma &
sleep 2
firefox &
sleep 2
wmctrl -s 2 #Workspace 3
pluma &
sleep 2
firefox &
sleep 2
wmctrl -s 3 #Workspace 4
pluma &
sleep 2
firefox &
sleep 2
wmctrl -s 0 #Return to Workspace 1

1 Like

Thank you very much, Gravy. That gets me started, though there’s more to do, such as starting things like the monitor and Caja visible on all workspaces, and placing each Chrome window, with its tabs, in the right workspace. I’ll start digging.

I just ran across this. It might help.

Thank you, Unkle. I’ll have a look at that after I find out why this doesn’t work . . .

I’ve put this script in /etc/init.d and symlinked it in /etc/rc0.d and rc6.d (which are for shutdown and reboot).

#!/bin/bash
# WY 2015-05-22 Run at shutdown or reboot to save workspace status. Runs from /etc/init.d
#               Symlink to /etc/init.d is in /etc/rc0.d and rc6.d

wmctrl -l | sort > /home/weyland/0-lenb/exec/K99aa-shutdown.save

exit 0

The script filename is K99aa-shutdown. It is set as executable.

The machine reboots OK, but nothing gets saved. What am I doing wrong?

Are you sure it even gets executed? The ‘99’ priority tells it to run after K11halt, and that calls halt -f (forced).

I wondered about that, and did try K01 first. But that didn’t work either. (Halt is K09 on my system.)

See THIS, dated May 2015. It says “The name of your script must begin with K99 to run at the right time.” Not sure I believe that. I’ll try both K01 and K99 from now on. Can’t hurt. I hope.

I suspect there’s something Linux doesn’t like about my script, even though it runs OK manually. Still digging.

Maybe see if there is anything in /var/log/syslog…I’m using systemd and when it tries to run wmctrl it says cannot open display.

No mention at all of wmctrl in my syslog files.

Is there a way for me to see if my script is ever executed?

Systemd appears in the Monitor Processes list, so I’m guessing that init.d and the other .d files are not used.

I gather from THIS that systemd is controlled in a much different way, which isn’t exactly clear to me. Not sure if I want to make the effort to delve into it yet.

I thought it would be a trivial task to automatically run a script at shutdown or reboot. Far from it, it seems.

(If only I could run VM/CMS on this machine, all my troubles would be over. Happy days.)

Setting it up in systemd isn't bad. Part of the trick is designating when it should run (my example may be able to go prior to local-fs-pre.target).

Create the service file:

Create the script:

Use systemctl to enable:

I think part of the trouble is wmctrl is a funny animal since it has to do with X, the display, etc. I don't seem to be able to export DISPLAY so that it can work with the display. Maybe local-fs-pre.target is too soon to run it, I don't know.

If you can get away with your script just running at startup, use the Startup Applications. I remember trying that with wmctrl and it worked.

Here's a thought on the shutdown though:
Create a shell script with something like this:
wmctrl -l > /home/youruserhere/a.log
mate-session-save --shutdown-dialog

Then create your own shutdown launcher that calls that script, and use that to shutdown.

Thank you. What a palaver! I’ll give it a go.

Running wmctrl at startup is not an option, because there are three Chrome windows that have to be put in the right workspaces, which can’t be done until they’ve started. Chrome never starts up properly without manual encouragement, so the instances aren’t there after startup. Chrome starts, but only one instance, with only one tab.

(No doubt there’s a way to make Chrome behave, which I would be interested in knowing. It knows what to restart, but it doesn’t do it without a click. Same with Firefox. No doubt I’m missing something very obvious. Maybe a “clean” Chrome shutdown should be part of my mythical shutdown script.)