5

I can start a command in a new Gnome Terminal as follows:

nohup gnome-terminal --window-with-profile=Background --command ls >/dev/null 2>&1&

(Based on https://askubuntu.com/a/46630/7146 and https://stackoverflow.com/a/10708326/236081)

However, I want the new terminal window to start minimised in the Launcher. How can I do that?

lofidevops
  • 20,924

4 Answers4

4

What about minimizing your window after creating it?

$ (mate-terminal --window-with-profile=Background --title=xxx  --command top >/dev/null 2>&1 &); sleep 0.1; xdotool windowminimize $(xdotool search --name xxx|head -1)

I use Mate instead of Gnome but it should work just the same if you replace mate-terminal with gnome-terminal:

$ (gnome-terminal --window-with-profile=Background --title=xxx  --command top >/dev/null 2>&1&); sleep 0.1; xdotool windowminimize $(xdotool search --name xxx|head -1)

First, i create new window with mate-terminal and I assign name using --title=xxx option. After that I use xdotool search --name xxx|head -1 to find id of this window and I pass it to xdotool windowminimize. sleep 0.1 delay is necessary because window needs a little while to be created.

Instead of using window title you can also use other search options:

$ xdotool search Usage: xdotool search [options] regexp_pattern
--class         check regexp_pattern agains the window class
--classname     check regexp_pattern agains the window classname
--maxdepth N    set search depth to N. Default is infinite.
                -1 also means infinite.
--onlyvisible   matches only windows currently visible
--pid PID       only show windows belonging to specific process
                Not supported by all X11 applications
--screen N      only search a specific screen. Default is all screens
--desktop N     only search a specific desktop number
--limit N       break search after N results
--name          check regexp_pattern agains the window name
--title         DEPRECATED. Same as --name.
--all           Require all conditions match a window. Default is --any
--any           Windows matching any condition will be reported
--sync          Wait until a search result is found.
-h, --help      show this help output

If none of --name, --classname, or --class are specified, the  defaults are: --name --classname --class

Example using --class 'mate-terminal' option:

(mate-terminal --command 'top' &) && sleep 0.1 && xdotool windowminimize $(xdotool search --class 'mate-terminal' |sort|tail -1)

This should work for gnome:

(gnome-terminal --command 'top' &) && sleep 0.1 && xdotool windowminimize $(xdotool search --class 'gnome-terminal' |sort|tail -1)

I sort output of xdotool search since newly created window should be last one listed.

Nykakin
  • 3,744
  • Worked most time also for me (tested with gnome-terminal --title=123 & disown && sleep 1 && xdotool windowminimize $(xdotool search --name 123|head -1)), but the gnome title will be renamed automatically through the $HOME.bashrc a few seconds after startup, so the time window is really short and sometimes it fails for me. – TuKsn Jun 27 '14 at 08:29
  • @Tuknutx, I updatet my answer. – Nykakin Jun 27 '14 at 10:25
  • It works really good for me with sleep 0.8. – TuKsn Jun 27 '14 at 10:39
3

Gnome-Terminal has no option to start minimised.

The following is more a workaround to do this:

First wmctrl is needed, but not the version from the repositories because this version doesn't have an option tho minimize windows. (If you have already installed wmctrl you have to remove it).

Download the version from github https://github.com/geekless/wmctrl/archive/master.zip and install it (follow the INSTALL file -> ./configure then sudo make install). If you get error: X11/Xmu/WinUtil.h you have also to install sudo apt-get install libxmu-dev and then try again.

Then you can run from commandline this for example:

gnome-terminal -x sh -c "ls; bash" & disown && sleep 3 &&  wmctrl -i -Y  $(wmctrl -l | awk -F' ' 'END{print $1}')

Explanation:

  1. gnome-terminal -x sh -c "ls; bash" & disown run gnome-terminal in background and execute a command (in this case ls)
  2. sleep 3 wait until the gnome-terminal window appears (you can experiment with this value, 3 seconds could be to short or to long, depends on your hardware)
  3. wmctrl -i -Y -i -> Interpret window arguments as a numeric value, -Y -> Iconify (minimize) the window
  4. $(wmctrl -l | awk -F' ' 'END{print $1}') or $(wmctrl -l | tail -1 | cut -d' ' -f1) get the window id of the last opened window (should be the window id of gnome-terminal in this case)

To simplify it you can add a function to your $HOME/.bashrc file:

gterm-min() {
    gnome-terminal -x sh -c "$1; bash" & disown  
    sleep 3   
    wmctrl -i -Y  $(wmctrl -l | awk -F' ' 'END{print $1}')
}

then you could use it like this:

gterm-min "ls -la"
TuKsn
  • 4,370
  • 2
  • 26
  • 43
1

I based my solution on some of the answers given for minimising and maximising windows. In this case, though, I wanted to target just this Gnome Terminal (but not other Gnome Terminals), so I gave it a name using --title:

nohup gnome-terminal --title="Tiny Terminal" --window-with-profile=Background --command "$argv" >/dev/null 2>&1&

And created a Devil's Pie rule for windows named "Tiny Terminal":

(if
(is (window_name) "Tiny Terminal")
(begin (minimize) )
)

(If you prefer, you can use gdevilspie to create this rule in a GUI.)

This achieves the original desired affect. However, when I tried it out, I realised that I also wanted the terminal to restore to a maximised state, which is addressed in a separate answer.

lofidevops
  • 20,924
0

Here is how I launch "The Language Tool" server, without sleep, witout loop:

#!/bin/bash

LT_WIN_NAME='The Language Tool'

xterm -geometry 126x12+0+0 -T "${LT_WIN_NAME}" -e\
 java -cp languagetool-server.jar org.languagetool.server.HTTPServer --allow-origin "*" &
xdotool windowminimize $(xdotool search --sync --name "${LT_WIN_NAME}")
Aubin
  • 131