Hello everyone,
I teach code courses and I need to change scenes frequently in OBS: every time I switch to one of the two windows I want to show to my students.
I started by defining keyboard shortcuts, but it's very quickly painful (I change windows every 1-2 minutes) and I sometimes forget to press the keys.
I didn't find this feature in OBS, so I made a small script for my use case (live coding). I hope it will be useful to someone :)
I teach code courses and I need to change scenes frequently in OBS: every time I switch to one of the two windows I want to show to my students.
I started by defining keyboard shortcuts, but it's very quickly painful (I change windows every 1-2 minutes) and I sometimes forget to press the keys.
I didn't find this feature in OBS, so I made a small script for my use case (live coding). I hope it will be useful to someone :)
Bash:
#!/bin/sh
set -e
set -u
mode=""
while true; do
newmode="other"
keys=""
if xdotool getwindowfocus getwindowname |grep -q Konsole ; then
newmode="konsole"
keys="ctrl+shift+F1"
fi
if xdotool getwindowfocus getwindowname |grep -q Chromium ; then
newmode="browser"
keys="ctrl+shift+F2"
fi
if [ "$newmode" != "$mode" ] && [ "$newmode" != "other" ]; then
echo ">> Switching to $newmode"
obswindow_id="$(xdotool search --name '.*OBS.*')"
activewindow="$(xdotool getactivewindow)"
xdotool windowactivate --sync "$obswindow_id" key "$keys"
xdotool windowactivate "$activewindow"
mode="$newmode"
fi
sleep 0.5
done