23

I can't find how to launch a chrome app from a bash ?

I'm trying to achieve this with Postman.

From google-chrome -h, I tried (unfortunately) those ones :

$ google-chrome --app="Postman"
$ google-chrome --extension="postman"

The result is that a new blank window is opened.

My first guess is the app is stored on my machine and I need to open a specific file (the app index) to launch it.

Is it possible to achieve this ?

And if it's possible, how to do ?

4
  • 1
    Probably if you open the corresponding .desktop file in ~/.local/share/applications (drag it over an opened gedit window) you can see the correct command in the Exec= line. Mar 3, 2016 at 13:04
  • Perfect, thank you @JacobVlijm . The command use the --app-id=[id] I assume this id is permanent so I will create an alias, but do you know a way to launch it by its name ?
    – chalasr
    Mar 3, 2016 at 13:15
  • @JacobVlijm Why the question is not duplicate of What command should I type to run Chrome from the terminal?
    – d a i s y
    Jun 3, 2017 at 9:08
  • @daisy because that's not the same question. This is about how to launch a chrome application, not chrome itself.
    – chalasr
    Jun 3, 2017 at 18:03

5 Answers 5

30

Answered thanks to @JacobVlijm .

To run a chrome app from command-line, use the following :

google-chrome --app-id=[app_id]

Assuming the path of google-chrome is /opt/google/chrome/google-chrome.

To retrieve the app id, search the first occurrence of the application name in /home/$USER/.local/share/applications .

4
  • 1
    Perfect, didn't have time to post an answer, but still wanted to help out :) Mar 3, 2016 at 18:47
  • You can even get the app id from the Chrome Store URL for the particular application. Of course this works only if you have access to the internet :) Aug 17, 2017 at 5:16
  • 1
    If you have multiple Chrome profiles, you need to add the profile directory to the command line, too: google-chrome --profile-directory=Default --app-id=[app-id] Jul 30, 2019 at 12:33
  • 2
    You can get an app id by 1. xprop WM_CLASS | sed -E 's/^.*crx_([a-z]+)".*$/\1/g') 2. click the app
    – yosefrow
    May 12, 2020 at 7:38
3

After all the stuff I have executed following command, worked for me and open postman

google-chrome --app-id=fhbjgbiflinjbdggehcddcbncdddomop

Assume default configurations

Pattern: google-chrome --app-id=<extensionID>

To get the extension ID:

  • open chrome://extensions/ in your chrome browser
  • click "Details" button of Postman extension
  • view address on address bar, where url in format of chrome://extensions/?id=<extensionID> Copy extensionID from url and use it in command

In same way you can use any extension of google chrome

0
2

Unfortunately, no there is no way provided to call an app at the command line by it's name. Providing this feature would mean unreliable extra parsing for installed apps and some would consider it a security flaw. You can do the parsing yourself, however, with a script that searches and extracts the name of each extension/app until it finds the name you search for:

/usr/local/bin/chrome-app-by-name:

#!/bin/zsh
emulate -R zsh -o extendedglob -o nullglob
setopt rematchpcre ;# recommended, I'm so used to PCRE, I sometimes forget what doesn't work in Regex
Chrome_Profile=Default  ;# or "Profile 1" ...
cd ${XDG_CONFIG_HOME:-$HOME/.config}/google-chrome/${Chrome_Profile}/Extensions
foreach app in */*
   # We have just called the path to each version of each extension/app.
   # Next we enclose in braces - slightly unnecessary - to ensure that
   #  whatever version of Zsh, "manifest.json" is completely read and 
   #  closed before we use the variable.
   {
      App_Manifest="$(cat <$app/manifest.json)"
   }
   if [[ $App_Manifest =~ '^\s*"name"\s*:\s*"([a-zA-Z 0-9_.-]+)"' ]]
   then
      app_name="$match[1]" ;# capture the sub-expression match for "name"
      if [[ $app_name == $1 ]]
      then
         # For my system this is actually exec google-chrome-stable ...
         exec google-chrome --app-id="${app%%/*}" $argv[2,-1]
      fi
   fi
end
echo "App name not found.  Please use Exact, case-sensitive spelling."

Some apps set their names deeper in the scripts - I don't know why! You may have to re-write or add to a script like this one to search ".desktop" files in ~/.local/share/applications for their '^NAME=...' equivalent to the above, and then get the execution command there.

I have not tested this script - I just wrote it on the fly to answer your question. I hope that as an example it works for you, but if the idea is not quite right, we could tweak it a bit. Zsh is simple, strait-forward syntax compared to some other sh-compatible shells. I have tried to leave out any features that require new versions or modules except for PCRE. PCRE is so much easier to use for the exact pattern matching I often need that I neglect regular Regex most of the time. A longer Perl script could work, also most of this syntax will run unmodified in /bin/bash. foreach ... end, $match[1] style arrays, setopt rematchpcre, the exact systax of Bash Regex, and emulate are the main exceptions.

1
  1. Open the folder in which the apps are stored in your terminal.
  2. Run chmod +x *.desktop
  3. Go back to the graphical folder in which your apps reside
  4. Now they should have icons and they correct names
  5. Right-click the app you want to launch
  6. Click properties
  7. In the Command line that is listed about halfway down is the command used to open that app.
1

In BASH term use this to launch your gmail ETC:

google-chrome --app=https://mail.google.com/mail/u/0/#inbox 

i have this on my mail watcher setup too!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .