SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2015-08-26 14:29:30

plummet
Member
From: West Riding of Yorkshire, UK
Registered: 2012-03-24
Posts: 13

Starting an app on a desktop

I know that this has been covered before, but I could not get it to work for me.

I want to start my email and calendar (icedove) application on one desktop and my browser (currently chromium) on another whenever I log in.  I discovered the wmctrl  (window manager control) command and hacked together a crude script to do what I wanted.  Here it is for comment/criticism/theft.

There may be a much easier or simpler way of doing this (eg. perl or python or tcl) - but I learned shell scripting on Unix before Microsoft existed - and old habits...

My bash script 'setdesktop'

#! /bin/bash
#This is a script to move a running application to a specified desktop
app=$1
desktop=$2
#echo app is $app
#echo desktop is $desktop
# remember which is the current desktop
current=$(wmctrl -d | grep '*' - | awk '{print $1}' -)
#echo $#
xmessage -timeout 5 "Moving $app to desktop $desktop."
if [ $#! = '2' ] ; then
    xmessage -timeout 5 "usage $0 '<application name> <desktop number>'"
else    
    if wmctrl -l | grep -i --quiet $app - ; then
	if wmctrl -d | awk '{print $1}' | grep --quiet $desktop -; then
	    wmctrl -s $desktop && wmctrl -R $app
	else
	    xmessage -timeout 5 "Cannot access desktop $desktop for application $app"
	fi
    else
	xmessage -timeout 5 "$app not running"
    fi
fi
wmctrl -s $current

This can be used at  the autostart script as:-

(sleep 3; icedove)&
(sleep 2; (chromium &) ;sleep 1; setdesktop chromium 1)&

If you do not have the ampersand after the 'command' the rest of the line following does not run until the command terminates - which is not a lot of use.  roll

Plummet


Plummet,
__________________
A fat hairy bloke.  Current favourite language Python.  Builds RC model aircraft.  Cooks and bakes.  Makes clothes.  Tries to grow fruit and veg - the mice and rabbits enjoy them.  Does sound for amateur dramatics.
I insist that I do not snore.

Offline

Be excellent to each other!

#2 2015-08-26 15:07:16

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: Starting an app on a desktop

WoW!  That's complicated.

I use wmctrl to start 15 conkys on various desktops.  The trick is to have the "app" fully loaded before switching desktops and you can do it directly in your OpenBox autostart file - since I always like to be on desktop #1 when done I do it like this:

# on desktop 2 ## inital sleep time to insure wallpaper is set
	(sleep 3s ; wmctrl -s 1 ; icedove) &

# on desktop 1 (start 3 seconds after desktop 1 commands)
	(sleep 6s ; wmctrl -s 0 ; chromium) &

EDIT:  Are you an OpenBox user?

Last edited by Sector11 (2015-08-26 15:11:58)


·  ↓   ↓   ↓   ↓   ↓   ↓  ·
BunsenLabs Forums now Open for Registration
·  ↑   ↑   ↑   ↑   ↑   ↑  · BL ModSquad

Offline

#3 2015-08-26 15:35:41

damo
#! gimpbanger
From: N51.5 W002.8 (mostly)
Registered: 2011-11-24
Posts: 5,434

Re: Starting an app on a desktop

An easy way to start apps on specific desktops is to use the <applications> section in rc.xml.

At it's simplest, use

    <application name="program-name">
      <desktop>4</desktop>
    </application>

For multiple instances of a program, they can be started via a script:

<application name="script-name">

Waldorf had OBApps, which is a gui for doing this (latest is available on sourceforge). Maybe try using gdebi to install from http://packages.crunchbang.org/waldorf/ … .7_all.deb


BunsenLabs Group on deviantArt
damo's gallery on deviantArt
Openbox themes
Forum Moderator smile

Offline

#4 2015-08-26 19:59:46

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: Starting an app on a desktop

SourceForge takes liberties with open-source software, uses it to push advertisements

Read more: http://www.digitaltrends.com/computing/ … z3jx9iR3H3


·  ↓   ↓   ↓   ↓   ↓   ↓  ·
BunsenLabs Forums now Open for Registration
·  ↑   ↑   ↑   ↑   ↑   ↑  · BL ModSquad

Offline

#5 2015-08-27 04:29:19

flaneur
#! Member
Registered: 2014-01-24
Posts: 99

Re: Starting an app on a desktop

Just to add to damo's recommendation, to get the program's name, you can use xprop or obxprop.

I use an alias:

myxprop='xprop | grep -E "_OB_APP"'

to trim the output of xprop.

I'm mentioning this because sometimes the program's name as required by the <applications> section isn't always "intuitive" and is case-sensitive. Here's what I get for Firefox:

$ myxprop
_OB_APP_TYPE(UTF8_STRING) = "normal"
_OB_APP_TITLE(UTF8_STRING) = "Mozilla Firefox"
_OB_APP_GROUP_CLASS(UTF8_STRING) = "Firefox"
_OB_APP_GROUP_NAME(UTF8_STRING) = "firefox"
_OB_APP_CLASS(UTF8_STRING) = "Firefox"
_OB_APP_NAME(UTF8_STRING) = "Navigator"
_OB_APP_ROLE(UTF8_STRING) = "browser"
$ 

Last edited by flaneur (2015-08-27 04:33:21)

Offline

#6 2015-08-27 09:54:08

plummet
Member
From: West Riding of Yorkshire, UK
Registered: 2012-03-24
Posts: 13

Re: Starting an app on a desktop

Ta Flaneur,

I suspect that the reason that I could not get the XML solution to work was that I assumed that the 'name' of iceweasel would be iceweasel or firefox, not navigator.

Also ta for the 'obvious' solutions of putting the wmctrl commands inside the autostart.  I heard that the definition of a genius is the ability to see the flaming obvious first.  I don't claim to be one. 

In mitigation, I was taught to do things the UNIX way.  That is - or was - to solve a problem, and to do it in a reuseable way, and to then reuse it.  Hence I would always write a script or programme to do it.  I would be able to test it in isolation, handle errors, Then I would use it.

Ho hum.

Plummet


Plummet,
__________________
A fat hairy bloke.  Current favourite language Python.  Builds RC model aircraft.  Cooks and bakes.  Makes clothes.  Tries to grow fruit and veg - the mice and rabbits enjoy them.  Does sound for amateur dramatics.
I insist that I do not snore.

Offline

#7 2015-08-27 14:08:07

damo
#! gimpbanger
From: N51.5 W002.8 (mostly)
Registered: 2011-11-24
Posts: 5,434

Re: Starting an app on a desktop

plummet wrote:

Ta Flaneur,

I suspect that the reason that I could not get the XML solution to work was that I assumed that the 'name' of iceweasel would be iceweasel or firefox, not navigator.

Don't forget that you can use "x-www-browser" as the command, which uses whatever is set as the default browser.

Also ta for the 'obvious' solutions of putting the wmctrl commands inside the autostart.  I heard that the definition of a genius is the ability to see the flaming obvious first.  I don't claim to be one. 

In mitigation, I was taught to do things the UNIX way.  That is - or was - to solve a problem, and to do it in a reuseable way, and to then reuse it.  Hence I would always write a script or programme to do it.  I would be able to test it in isolation, handle errors, Then I would use it.

I also prefer to run things from scripts, so that there is as little as possible in autostart.

PS: Love your sig!


BunsenLabs Group on deviantArt
damo's gallery on deviantArt
Openbox themes
Forum Moderator smile

Offline

#8 2015-08-27 16:24:38

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: Starting an app on a desktop

plummet wrote:

Also ta for the 'obvious' solutions of putting the wmctrl commands inside the autostart.  I heard that the definition of a genius is the ability to see the flaming obvious first.  I don't claim to be one.

Me neither ... I got the wmctrl thing from an old friend and bash script guru Mobilediesel ... and I don't use the wmctrl lines directly in the 'autostart' file either.  I call a "StartStopConky" bash script as the last command in my autostart:

(sleep 2s ; S11_ssc) &
exit

which is:

#!/bin/sh
# click to start, click to stop

if pidof conky | grep [0-9] > /dev/null
   then
exec killall conky
   else

# Start with low sleep on highest desktop
# Increase sleep as desktop lowers to insure the conky is running before changing desktops.

# on desktop 4 only | no sticky
	(sleep 0s && wmctrl -s 3 && conky -q -c /media/5/Conky/S12/S12_time_L.conky) &
	(sleep 0s && wmctrl -s 3 && conky -q -c /media/5/Conky/S12/S12_time_R.conky) &
	(sleep 0s && wmctrl -s 3 && conky -q -c /media/5/Conky/S12/S12_time_tm.conky) &

# on desktop 3 only | no sticky | test area
# 	(sleep 3s && wmctrl -s 2 && conky -q -c /media/5/conky/7_months_h.conky) &
# 	(sleep 3s && wmctrl -s 2 && conky -q -c /media/5/Conky/S11_Word.time.conky) &

# on desktop 2 only | no sticky
	(sleep 7s && wmctrl -s 1 && conky -q -c /media/5/Conky/S11_Rem_Cal.conky) &
	(sleep 7s && wmctrl -s 1 && conky -q -c /media/5/Conky/S11_Dates.conky) &

# on desktop 1 only | no sticky
	(sleep 9s && wmctrl -s 0 && conky -q -c /media/5/Conky/S11_VRX.conky) &
	(sleep 9s && wmctrl -s 0 && conky -q -c /media/5/Conky/S11_9_month_cal.conky) &
	(sleep 9s && wmctrl -s 0 && conky -q -c /media/5/Conky/S11_VNSTAT_2.conky) &
	(sleep 9s && wmctrl -s 0 && conky -q -c /media/5/Conky/S11_OJO.conky) &

	(sleep 11s && wmctrl -s 0 && conky -q -c /media/5/Conky/S11_thin_r_side.conky) &
	(sleep 11s && wmctrl -s 0 && conky -q -c /media/5/Conky/1b2_accuweather_conkyweather_font/conkyrc_1b2_int_s11_thin) &

# on all desktops | sticky
	(sleep 11s && wmctrl -s 0 && conky -q -c /media/5/Conky/S11_MD_Cal-br.conky) &
	(sleep 15s && wmctrl -s 0 && conky -q -c /media/5/Conky/S11_Email_01.conky) &
	(sleep 17s && wmctrl -s 0 && conky -q -c /media/5/Conky/Eagle.conky) &

exit
fi

An OB Menu item calling the script kills them if they are running or starts them is they are not running... and in autostart ... starts them on boot.


·  ↓   ↓   ↓   ↓   ↓   ↓  ·
BunsenLabs Forums now Open for Registration
·  ↑   ↑   ↑   ↑   ↑   ↑  · BL ModSquad

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.
Server: acrobat

Debian Logo