Starting GUI on specific workspace from CLI or shell script
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
+ conky -c /home/gregg/.conky/conkyrc_grey
+ firefox
+ opera
+ nautilus
+ banshee
+ conky -c /home/gregg/.conky/conkyForecast.imagebasedtemplate.conkyrc
+ transmission-gtk
+ sleep 10
Conky: /home/gregg/.conky/conkyrc_grey: 26: config file error
Conky: /home/gregg/.conky/conkyForecast.imagebasedtemplate.conkyrc: 64: config file error
Conky: desktop window (e00089) is subwindow of root window (15d)
Conky: window type - normal
Conky: drawing to created window (0x2000001)
Conky: drawing to double buffer
Conky: desktop window (e00089) is subwindow of root window (15d)
Conky: window type - normal
Conky: drawing to created window (0x3c00001)
Conky: drawing to double buffer
[Info 17:14:56.375] Running Banshee 2.0.0: [Ubuntu Natty (development branch) (linux-gnu, i686) @ 2011-04-18 16:21:33 UTC]
(firefox-bin:14145): LIBDBUSMENU-GTK-CRITICAL **: dbusmenu_menuitem_property_set_shortcut: assertion `gtk_accelerator_valid(key, modifier)' failed
+ guake
[Warn 17:15:03.991] Caught an exception - System.ApplicationException: Invalid frame dimensions (in `Hyena.Gui')
at Hyena.Widgets.AnimatedImage.ExtractFrames () [0x00000] in <filename unknown>:0
at Hyena.Widgets.AnimatedImage.Load () [0x00000] in <filename unknown>:0
at Banshee.Gui.Widgets.TaskStatusIcon..ctor () [0x00000] in <filename unknown>:0
[Info 17:15:05.798] Updating web proxy from GConf
[Info 17:15:06.285] All services are started 7.956078
[Info 17:15:20.219] nereid Client Started
[Info 17:15:20.351] GStreamer version 0.10.32.0, gapless: True, replaygain: True
[Warn 17:17:49.238] Forcefully breaking out of RCS loop b/c change in total_width less than 1.0
[Warn 17:17:52.819] Forcefully breaking out of RCS loop b/c change in total_width less than 1.0
This seems to indicate some errors and it looks like things are happening in a different order to my script, any clues on what they are and how to fix them??
Last edited by PClOStinspace; 05-22-2011 at 11:25 AM.
Reason: Show script as it is
The answer is yes, but it's not as simple as you might imagine. In a Gnome2 or Gnome3 fallback environment, you can easily switch to specific workspaces.
I use this script, called 'desktop' to select the workspace:
Code:
#!/bin/bash
#-------------------------------------------------------------------------------
#
# desktop
#
# Author: Mace Moneta, mmoneta@optonline.net
# Version: 1.1
# Created: 01/13/2010
# Modified: 10/04/2010
#
# Description: Switch to the requested desktop, in metacity or compiz
#
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# ************************** Variables **************************
#-------------------------------------------------------------------------------
# Desktop number passed?
dt=$1
if [ "$dt" == "" ]
then
echo "Error: missing desktop number"
exit
fi
#-------------------------------------------------------------------------------
# ************************* Subroutines *************************
#-------------------------------------------------------------------------------
function dsktop () {
if [ $COMPIZ -eq 1 ]
then
# The target desktop number (begins with 0)
TVPN=$(( $1 % ${NF} ))
# The X coordinate of the target viewport
TVPX=$(( ${TVPN} * ${WW} ))
# Change to the target viewport
/usr/bin/wmctrl -o ${TVPX},0
else
/usr/bin/wmctrl -s $1
fi
}
#-------------------------------------------------------------------------------
# ************************* Mainline ****************************
#-------------------------------------------------------------------------------
# Disable globbing
set -f noglob
# Is compiz running?
COMPIZ=0
window_manager="`/usr/bin/wmctrl -m | /bin/grep -i compiz`"
if [ "$window_manager" != "" ]
then
COMPIZ=1
fi
# The information about the desktop
INFO=$(/usr/bin/wmctrl -d | /bin/grep "\*")
# The width of the desktop
DW=$(echo "${INFO}" | /bin/awk '{sub(/x[0-9]+/, "", $4); print $4}')
# The width of the workarea
WW=$(echo "${INFO}" | /bin/awk '{sub(/x[0-9]+/, "", $9); print $9}')
# The number of faces on the cube
NF=$(($DW/$WW))
dsktop $dt
/bin/sleep 2
exit
You call it with 'desktop 0' to switch to the first desktop, 'desktop 1' for the second, etc.
You also have the issue of synchronizing applications launched as background tasks. For example, Firefox can take a long time to launch. As a result, you need to wait for the window to actually appear. For example:
Code:
/usr/bin/firefox "$@" &
FFPID=$!
FFWINDOW=`/usr/bin/wmctrl -l |/bin/grep "Mozilla Firefox" | /usr/bin/awk '{print $1}'`
COUNT=0
while [ "$FFWINDOW" == "" ]; do
/bin/sleep .1
FFWINDOW=`/usr/bin/wmctrl -l |/bin/grep "Mozilla Firefox" | /usr/bin/awk '{print $1}'`
if [ $((COUNT++)) -ge 100 ]; then exit ; fi
done
On a system with gnome-shell with its dynamic workspaces, all you can do it switch to the last (free) workspace, since you can't preallocate them. You can do this with, for example:
Sorry, I haven't tried Ubuntu Unity. There's no harm in trying them out. If Unity gives you preallocated workspaces, try the 'desktop' script. If it dynamically allocates them, try the wmctrl. If neither work, then Unity isn't a EWMH (Extended Window Manager Hints) compatible X Window Manager.
OK, too tired to try now but will have a go another day and see what happens.
I'll try the gnome shell script first as I believe Unity works in a similar way(?) Do i just insert that bit of code before/after the line that launches the app in my script??
Yes, if you have preallocated workspaces, you can do something like:
Code:
# application1 on first workspace
desktop 0
application1 &
# application2 on second workspace
desktop 1
application2 &
...
If it ends up switching workspaces before the application window appears, you'll need to add code similar to the Firefox example to wait for the window to appear.
Last edited by macemoneta; 05-23-2011 at 08:51 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.