Script to toggle between WM's (OB & i3 in this case)

First, please someone tell me if this is not the place to be asking these kinds of thing &/or if I am being a pain

But this seems to be the place where people (a) ‘know these things’, and (b) seem to like (or have the patience, at least) to help

I have cobbled together the very basic script to skip between OB and i3 WM’s via a reboot, which I will bind to a keybind:
(Using the results of this thread as a template)
The reason for the nextcloud bits are explained in the thread in the link above)


sed -i 's/\(exec \)openbox-session/\1i3/;t;s/\(exec \)i3/\1openbox-session/' ~/.xinitrc

{ pkill nextcloud && sleep 1; }; systemctl reboot

#{ pkill nextcloud && sleep 1; }; session-logout >/dev/null 2>&1 || pkill -15 -t

It works, which I am happy about

The last line, commented out, is my attempt (stolen from ~.local/bin/rofi_run) to avoid a full reboot and just logout

If I comment out the reboot line and uncommnent the logout line, it also works, but I have to then type ‘exit’ after logging out to get into the other WM

Is there anyway to automate this ‘exit’ bit (i.e. a kind of logout-login like a reboot?

And/or is it worth it - is there any advantage in doing a logout-login over a reboot? Everything gets killed anyway doesnt it?

The aim of this is to start moving to i3, and this helps me in this.
And I’m curious to learn stuff as ever.


1 Like

Use a symbolic link to switch might be easier. That’s how Slackware does it.


Thanks @chroot
Homework for me :smiley:

Try THIS or THAT :wink:


THIS looked a bit too scary for someone of my ‘talents’ :smiley:

So I stuck with ‘my’ simple script to sed .xinitrc and then reboot into the other WM

Then I simply added it to @natemaia 's rofi_run rather than my first idea of a keybind, after I hit the keybind by mistake and -ooops!

 				case "$(rofi -sep "|" -dmenu -i -p 'System' -width 20 -hide-scrollbar \
					-line-padding 4 -padding 20 -lines 6 <<< " Lock| Logout| Reboot| OBi3| Suspend| Shutdown")" in
					*Lock) i3lock-fancy ;;
					*Reboot) { pkill nextcloud && sleep 1; }; systemctl reboot ;;
					*OBi3) ~/.local/bin/WM_Toggle ;;
					*Shutdown) { pkill nextcloud && sleep 1; }; systemctl -i poweroff ;;
					*Suspend) systemctl suspend ;;
					*Logout) session-logout >/dev/null 2>&1 || pkill -15 -t tty"$XDG_VTNR" Xorg ;;

Well, it works at least.