Search code examples
bashterminalchromiumminimize

Start chromium-browser minimized using bash


I want to start chromium-browser minimized using bash in a terminal.

Currently using chromium-browser to open Chromium. But how to open it as minimized using a bash command.


Solution

  • Using wmctrl, (on Debian-based systems install with apt install wmctrl), to send commands to any NetWM window manager:

    chromium-browser && \
    last_chrom=$(wmctrl -l | 
                 grep -i chrom | tail -1 | 
                 while read a b ; do echo $a ; done) ; \
    wmctrl -ir $last_chrom -b toggle,hidden
    

    How it works:

    1. Start the browser.
    2. Save the window identity number of the most recent invocation of chromium-browser in the variable $last_chrom.
    3. Use wmctrl to hide that window.

    (Optional) To have the window close after running for a minute, add one more line:

    chromium-browser && \
    last_chrom=$(wmctrl -l | 
                 grep -i chrom | tail -1 | 
                 while read a b ; do echo $a ; done) ; \
    wmctrl -ir $last_chrom -b toggle,hidden ; \
    { sleep 1m &&  wmctrl -ic $last_chrom ; } &