LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 05-22-2011, 11:10 AM   #1
PClOStinspace
Member
 
Registered: Jun 2008
Location: Bracknell, UK
Distribution: Ubuntu 13.10 Saucy
Posts: 152

Rep: Reputation: 19
Starting GUI on specific workspace from CLI or shell script


Is it possible to launch an app via CLI or a shell script and tell it to open on a specific workspace??

I am trying to write a script that will launch several apps after boot/login and place them each on different workspaces.

The script looks like:-
Code:
#!/bin/sh

sleep 10 && guake &
nautilus &
transmission-gtk &
firefox &
opera &
banshee &
conky -c /home/gregg/.conky/conkyForecast.imagebasedtemplate.conkyrc &
conky -c /home/gregg/.conky/conkyrc_grey
exit
so far.

It seems to be doing what I want, if I run:-
Code:
$ bash -x ./startuptasks.sh
the output looks like:-
Code:
+ 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
 
Old 05-23-2011, 06:00 PM   #2
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 332Reputation: 332Reputation: 332Reputation: 332
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:

Code:
/usr/bin/wmctrl -s `/usr/bin/wmctrl -d | /usr/bin/tail -n1 | /bin/awk '{print $1}'`
/bin/sleep 1
 
Old 05-23-2011, 08:06 PM   #3
PClOStinspace
Member
 
Registered: Jun 2008
Location: Bracknell, UK
Distribution: Ubuntu 13.10 Saucy
Posts: 152

Original Poster
Rep: Reputation: 19
I am using Unity on Ubuntu 11.04, so would either of the above work???
 
Old 05-23-2011, 08:29 PM   #4
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 332Reputation: 332Reputation: 332Reputation: 332
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.
 
Old 05-23-2011, 08:39 PM   #5
PClOStinspace
Member
 
Registered: Jun 2008
Location: Bracknell, UK
Distribution: Ubuntu 13.10 Saucy
Posts: 152

Original Poster
Rep: Reputation: 19
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??
 
Old 05-23-2011, 08:50 PM   #6
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 332Reputation: 332Reputation: 332Reputation: 332
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] starting shell script in GUI qrange Linux - Software 7 01-11-2011 11:34 AM
Apps starting from GUI vs. CLI tcv Linux - Newbie 4 06-09-2007 09:07 PM
Bash script - how to tell if in GUI or CLI? dive Programming 2 11-19-2005 02:12 AM
starting KDE application on specific workspace aguerra Linux - General 2 02-20-2005 06:58 PM
Starting Application in a specific "workspace" in gnome tarakian Linux - Newbie 0 01-15-2004 07:40 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:43 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration