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 ?

  • 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. – Jacob Vlijm Mar 3 '16 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 '16 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 '17 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 '17 at 18:03
up vote 13 down vote accepted

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 .

  • 1
    Perfect, didn't have time to post an answer, but still wanted to help out :) – Jacob Vlijm Mar 3 '16 at 18:47
  • 1
    Works great, thanks. – Heather92065 Mar 3 '16 at 18:54
  • 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 :) – BarathVutukuri Aug 17 '17 at 5:16

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. 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.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.