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?


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" &

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.
  # Unity 3D is currently running.


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.

  • Hi, I am not a script writer but I do get crazy ideas. This script works from 3D to 2D but not the other way around. Perhaps you need two scripts. Create a second script by switching the 2D and 3D references around and see if this second script works when you are logged into 2D and want to switch to 3d. I am sorry if this is a stupid idea. Regards. – grahammechanical Aug 10 '11 at 12:25
  • @graham: What would the second script do that the first one doesn't do already? – Scott Severance Aug 11 '11 at 3:54
  • As far as I can tell, my script isn't buggy or anything. It seems to be doing what it was told to do. The problem seems to be that I'm missing a step or two. Switching the order of things won't add the missing step. – Scott Severance Aug 11 '11 at 3:54
  • This question never got a good answer, and since 11.10 removes my need for this script, I'm trying to close this question. – Scott Severance Oct 19 '11 at 0:25
  • How does 11.10 removes the need for the script? And by the way, regardless of Natty or Oneiric, you can move from 2D to 3D with a simple unity --replace. – Oxwivi Oct 27 '11 at 6:06

When you run metacity --replace, I would expect it to end the Compiz session for you. Hence, perhaps it would help if you did not call stop_3d, but just start_2d. It might be the case that you now manually kill 3D, which triggers a restart of Compiz, however, before it is restarted, 2D will launch but think 3D isn't running and, hence, not end it properly (without triggering a restart).

Just a hunch, but you never know.

| improve this answer | |
  • stop_3d is a no-op; it does nothing. start_2d seems to work OK. The problem is with stopping 2D. It's the 2D stuff that's presumably re-spawning, not compiz. – Scott Severance Aug 8 '11 at 6:12
  • See my edit above for additional details. – Scott Severance Aug 8 '11 at 8:20
  • Oh sorry, I'm blind :S Could the problem lie in the detection whether Unity 2D is running? (Sorry, it's really just basic debugging but I've got nothing better.) It might also just be a bug in Unity - does it work when you just run unity --replace from a terminal with 2D running? – Vincent Aug 9 '11 at 20:02
  • 2D detection is clearly working, else my script wouldn't work from a 3D session. And running unity --replace won't get rid of the 2D panel, dock, etc. That's why I'm trying to kill those processes, which are getting re-spawned. – Scott Severance Aug 11 '11 at 3:50
  • unity --replace should work (according to unity --help, running just unity should do the same), so I would report a bug to see if it can get fixed - should make things a lot easier. – Vincent Aug 12 '11 at 13:41

Not the answer you're looking for? Browse other questions tagged or ask your own question.