I need to start a GUI application [Lotus Symphony] on a workspace different from the currently used one. [ex.: there are 4 workspaces on a GNOME desktop.]
Q: How do I do this?
p.s.: It’s needed because Lotus Symphony’s first start after a reboot is very, very slow, but after it’s been used once, it starts very quickly. I think it caches itself. That’s why I want to start it at every boot on a different workspace, so it will be fast later if I need to use it.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Check out Devil’s Pie (although i am not sure it would work with Gnome3), and you can find more useful information on stackoverflow bash.
Basically you should do the following:
#!/bin/bash wmctrl -n 8 firefox & thunderbird & /usr/bin/netbeans --locale en & amsn & gnome-terminal & sleep 15 wmctrl -r firefox -t 0 wmctrl -r netbeans -t 1 wmctrl -r terminal -t 2 wmctrl -r amsn -t 6 wmctrl -r thunderbird -t 7 #focus on terminal wmctrl -a terminal
(i have just copy & pase the above code from the StackOverFlow link above, since i think it is self explanatory).
UPDATE:
See here for an easier solution at the best site for Gnome 3 extensions, you should install the Auto Move Windows extension for Gnome 3.
In case it isn’t working for you (as you can see at the link there are some distros that the automation of the installation isn’t working right, get a more detailed exploitations here on how to get it work.
Method 2
Original post was regarding using a script to make an application appear on a particular workspace, such that another script might be used in Start Up script to allow a user to continue working while a very slow starting application loaded on another workspace. My script works great as front-end for the rather cumbersome wmctrl syntax, to launch any one application on any given workspace, from any command prompt. Thus a further script that simply lists something like, lh 1 thunderbird; lh 2 firefox; lh 3 calculator…., or whatever, is now easy. There are however some difficulties with timing, thus the sleep in my script. The below is the updated version, which I will not be maintaining or post again. Use AS IS, no guarantee of fitfulness for any particular use. Modify as you please. I suggest saving as /usr/local/bin/lh, simply because lh is not any other known program name, at least not on Mint 18. As for variables—I quoted variables I deemed necessary to be quoted.
#!/bin/sh
## Author: B.A. Computer Services www.ba-computer.com
## Purpose: Frontend to launch anything on a specific desktop/workspace.
## lh is short for LaunchHere
USAGE="USAGE: $(basename $0) [-r] workspace(1,2,..) command
LaunchHere launches COMMAND on specific workspace.
-r option returns to current workspace"
[ -z "$1" ] && echo $USAGE && exit 0
ISRETURN=$(false); [ "$1" = "-r" ] && ISRETURN=true && shift;
WRKSPC=$1;[ -z "$WRKSPC" ] && echo $USAGE && exit 0
WSN=$(expr $WRKSPC - 1) ## wmctrl starts with 0 as first wrkspc
shift; CMD="$*"; [ -z "$CMD" ] && echo $USAGE && exit 0
WM=$(which wmctrl);[ -z "$WM" ] && echo MISSING wmctrl && exit 1
CURRENT=$(wmctrl -d | grep '*' | cut -c1)
# Switch to desired workspace
$WM -s $WSN
$CMD &
PID=$!
echo Executed $CMD on workspace $WRKSPC, PID=$PID
sleep 3
# Return to CURRENT workspace ?
# [ $ISRETURN ] && echo TRUE || echo FALSE
[ $ISRETURN ] && $WM -s $CURRENT
Method 3
Install wmctrl
sudo apt install wmctrl
And create a script (in this example thunderbird on the second workspace (-t 1)):
#!/bin/sh
(thunderbird &) & sleep 5 &&
sh -c "wmctrl -i -r `wmctrl -l | grep Thunderbird` -t 1"
To know your application name on wmctrl you can view it by taping on your terminal :
wmctrl -l
And replace it with the correct name in the script.
Be carrefull with the capital letter (“Thunderbird” not “thunderbird”) !!
Other example with firefox on the 3d workspace (-t 2):
#!/bin/sh
(firefox &) & sleep 5 &&
sh -c "wmctrl -i -r `wmctrl -l | grep Firefox` -t 2"
Bonus :
Here is the command to execute at start-up :
sh -c "thunderbird & sleep 5 && wmctrl -i -r `wmctrl -l | grep Thunderbird` -t 1"
Work on Debain 10 with Cinnamon. But should work for all
Method 4
I have created a small library of Python scripts to achieve goals like this. You can find it on gitHub as Launch on workspace. For most programs, it can be used as simply as
import launch_on_workspace as low low.launch_and_move(['cmd','option1','option2',...], 3)
to launch cmd with given options at desktop 3 (numbered as in wmctrl, so it will be 4 in GNOME).
Some programs need specific settings (when they use more processes for the startup), and the library already offers few of custom starters. For example, a new window of firefox can be run on a workspace 3 by firefox(3, url).
On top of that, the library offers the possibility to move the windows to certain screens in multi-monitor settings.
Method 5
Beta – but it works for me on linux mint.
#!/bin/sh ## Author: B.A. Computer Services www.ba-computer.com ## Purpose: Frontend to launch anything on a specific desktop/workspace. ## lh is short for LaunchHere USAGE="USAGE: $(basename $0) workspace(0,1,2,..) command" WRKSPC=$1;[ -z "$WRKSPC" ] && echo $USAGE && exit 0 shift; CMD="$*"; [ -z "$CMD" ] && echo $USAGE && exit 0 WM=$(which wmctrl);[ -z "$WM" ] && echo MISSING wmctrl && exit 1 echo Executing $CMD on workspace $WRKSPC $WM -s $WRKSPC eval $CMD & sleep 1 $WM -r :ACTIVE: -t $WRKSPC
Method 6
I am inspired from @user278634’s post in this thread, thank you.
What I modified is:
- change ‘eval $CMD &’ to ‘eval “$CMD &”‘ because of getting command pid $!.
- keep current workspace rather than switching to the specified one; just launching command at the specified workspace.
- move the command to the specified workspace just after window-id is found, rather than sleep 1 sec. This is a little bit important for me because I usually open 8 terminals for each workspace and X-geometry at the startup of desktop-login. This would take more than 8 seconds when using ‘sleep 1’ while my script takes just 2..3 sec.
Here my script is:
#!/bin/sh
# = NAME
# lh - Launch Here
#
# = SYNOPSIS
# lh <workspace> <command> [<command-args>]
#
# = DESCRIPTION
# launch command (with any command-args) on a specific desktop/workspace.
#
# Example:
#
# lh 2 xterm -geometry 80x46+881+0
#
# = Author
# Fumisky Wells
USAGE="USAGE: $(basename $0) workspace(0,1,2,..) command"
WRKSPC=$1;[ -z "$WRKSPC" ] && echo $USAGE && exit 0
shift; CMD="$*"; [ -z "$CMD" ] && echo $USAGE && exit 0
WM=$(which wmctrl);[ -z "$WM" ] && echo MISSING wmctrl && exit 1
eval "$CMD &"
pid=$!
while :; do
wid=$($WM -l -p | grep " $pid " | awk '{print $1}')
if [ "$wid" != "" ]; then
$WM -i -r $wid -t $WRKSPC
exit
fi
# not found yet...
sleep 0.1
done
Method 7
I found I needed to insert a delay or this didn’t seem to work, with the sleep 10 it does. Ubuntu 20.04.
bash -c 'sleep 10; wmctrl -s 1; gnome-terminal; wmctrl -s 1'
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0