Kludgy OBS scene switcher for linux
posted on: Tuesday, 27 December 2016 @ 12:36pm inEdited 2017 Jan 7: made the scripts slightly more reliable (not relying on window ids) but they will now get extremely confused if there’s more than one instance of Blender open
Because I’m not smart enough to get the MacOS version of the Automatic Scene Switching plugin for OBS Studio, I gumbied an easy manual one with bash scripts.
So there’s some scenes set up in OBS like so:
Set shortcuts for the scenes in OBS settings like so:
Mine are set to super (apparently, sometimes it’s called meta) and the number row keys 1, 2 and 3.
Now we make some bash scripts (I chuck mine in /usr/local/bin
) with a slightly modified half a switcheroo script:
obs-blender-main.sh
#!/bin/bash
# map cintiq stylus to primary display which will move the mouse cursor
xsetwacom set "Wacom ISDv5 307 Pen stylus" MapToOutput HEAD-0
xsetwacom set "Wacom ISDv5 307 Pen eraser" MapToOutput HEAD-0
xsetwacom set "Wacom ISDv5 309 Finger touch" MapToOutput HEAD-0
# send the number to a text file to help the switcher
echo "0" > ~/.wacom-mapping
# focus the window on the main screen (which in my case generally seems to be the
# second one in the stack) and rename it so OBS can see it
xdotool search --class blender windowactivate %2 set_window --name "Blender (top)"
# move OBS and picarto dash to cintiq
wmctrl -r "OBS 0.16.2 (linux)" -t 1
wmctrl -r "OBS 0.16.2 (linux)" -e 0,3587,1360,-1,-1
wmctrl -a "OBS 0.16.2 (linux)"
wmctrl -r "Picarto.TV - Dashboard" -t 1
wmctrl -r "Picarto.TV - Dashboard" -e 0,2622,1369,-1,-1
wmctrl -a "Picarto.TV - Dashboard"
wmctrl -a "Blender (top)"
obs-blender-cintiq.sh
#!/bin/bash
# map cintiq stylus to cintiq which will move the mouse cursor
xsetwacom set "Wacom ISDv5 307 Pen stylus" MapToOutput HEAD-1
xsetwacom set "Wacom ISDv5 307 Pen eraser" MapToOutput HEAD-1
xsetwacom set "Wacom ISDv5 309 Finger touch" MapToOutput HEAD-1
# switcheroo.sh helper
echo "1" > ~/.wacom-mapping
# move OBS and picarto dashboard back to main screen
wmctrl -r "OBS 0.16.2 (linux)" -t 1
wmctrl -r "OBS 0.16.2 (linux)" -e 0,160,55,829,671
wmctrl -a "OBS 0.16.2 (linux)"
wmctrl -r "Picarto.TV - Dashboard" -t 1
wmctrl -r "Picarto.TV - Dashboard" -e 0,148,580,-1,-1
wmctrl -a "Picarto.TV - Dashboard"
xdotool search --class blender windowactivate %1
Then make keyboard shortcuts to run the scripts. I use KDE Plasma 5 so it’s in System Settings > Shortcuts > Custom shortcuts
. In this case you make a new “global shortcut” for a “command/url” with the trigger being the same shortcuts/hotkeys used for OBS.
It’s also conveniently quicker to switch this way and not too much of a muscle memory shift from the normal screen switch (my hotkey is meta+z) even when not streaming. The window title change is purely so OBS can differentiate the windows as Blender calls them the same thing so in my case while OBS correctly realises there are two Blender windows, it will only ever display the first one for both of them as it does it by title. The title change can be done on either window and they can be called whatever, I did it on the top screen purely because it was the first script I wrote.
Note: because it’s using the window id rather than title it will only work for the first instance of Blender. If you start another instance of Blender and then quit the first instance, the screen switcher will work but not the window activation. But because it’s using the window id it will also always grab the correct window rather than the first window it encounters with a matching string. There is apparently a way to look for windows in specific areas but I wanted something quick and easy and for my purposes it didn’t need to be super flexible and able to cover all possible options.
This work by bek (ryivhnn) is licensed under a Creative Commons Attribution 4.0 International License