Generally, I much prefer Unity 3D over the 2D version, which is a bit broken on my machine. However, I frequently give presentations, and Compiz doesn't support multiple screens. I've been forced to log out of 3D and into 2D every time I give a presentation, then back to 3D afterwards to get a more usable desktop.
To avoid this inconvenience, I've written a script to toggle between Unity 2D and 3D without requiring a logout. Unfortunately, when I run it from 2D, I wind up with 3D running, plus the 2D panel and launcher. Both are on the screen simultaneously. I suspect that the 2D processes I'm killing are getting re-spawned somehow. Can someone help me debug my script?
#!/bin/bash
set -x
unity_2d="unity-2d-places unity-2d-launcher unity-2d-panel unity-2d-spread"
start_2d() {
metacity --replace &
for i in $unity_2d; do
"$i" &
done
}
stop_2d() {
killall $unity_2d # The lack of quotes around $unity_2d is deliberate.
}
start_3d() {
unity --replace &
}
stop_3d() {
: # no-op for now
}
if ps -u "$USER" | grep -q [m]etacity; then
# Unity 2D is currently running.
stop_2d
start_3d
else
# Unity 3D is currently running.
stop_3d
start_2d
fi
Edit
My script works when I log in to 3D. It doesn't work when I log in to 2D. So, it works for my most common use case, but the fact that it fails the other way around suggests to me that I'm doing something wrong.
unity --replace. – Oxwivi Oct 27 '11 at 6:06