Skip to content

Opening a desktop program

Sander Ronde edited this page Feb 9, 2022 · 5 revisions

Introduction

The steps below help you open a desktop program with a Custom Right-Click Menu context menu item. To do this your first of all need to link that program to a URI scheme, which you can then use in a link type menu item, just like a normal URL. Currently there's only a guide for how to do this on Windows (as I don't own a mac).

Windows

Automatically adding the key value pair

This method uses the extension to generate a .reg file that will create the key/value pair for you. If you don't trust this extension to make changes to your registry or you want to add custom arguments to the command, you can instead use the manual method.

  1. Open up the options page
  2. Scroll to the "Launching programs instead of links" section
  3. Enter the file path to the .exe file you want to open into the "File path including name" box. Enter file path
  4. Enter a name for your URI scheme into the "URI scheme name" input. This can be any name you want (as long as it's not taken by another program) and will be linked to open the program you entered above.
  5. Click generate
  6. If you haven't already, enable download permission for the extension to enable it to download the generated file to your hard drive.
  7. Run the downloaded file.
  8. Test if it works by opening your favorite browser and going to myscheme:// where myscheme is the name you just chose for the scheme in step 4. Be sure to go to the page, and not to google it. It should now open the program for which you entered the file path in step 3. If it works, go to step step 11, otherwise go to step 9.

Go to page, don't google

  1. If it doesn't open, make sure you chose the correct file in step 3 by running the file and seeing if that does indeed open the program. Also double check that you entered the correct scheme name. If it still doesn't work, attempt the manual method.

Manually adding the key value pair

With this method you can manually add the key/value pair. This also allows you to specify optional arguments.

  1. Open up the registry by entering "regedit" in the windows run dialog (Windows key + R) and pressing "OK".

Opening regedit

  1. Right-click the HKEY_CLASSES_ROOT folder and click "new", and then click "key". Now enter a name you want to give this scheme. It doesn't matter what the name is as it won't be used for anything except for identifying it in this list.
  2. Left-click the folder you just created to open it. Then right-click the "(Default)" key and click "Modify".

Modifying key

  1. In the data input enter "URL:My name" (without quotes) where "My name" is a descriptive name for this scheme. This is what will be shown when changing the url scheme settings in windows and as such will only be a description for you.
  2. Right-click the folder and click "new" and then "string value" to create a new value. Name it "URL Protocol" (again without quotes). Leave the data section empty (don't change anything from the default).
  3. Right-click the folder and click "new" and then "key". Name this key "DefaultIcon". Click this newly created folder to select it and again Modify the "(Default)" entry. Set its value to the location of a file that has the icon you want to use (which generally is the .exe file you want to open), followed by ",1".

Setting default icon

  1. Create another new key for the root item you created in step 2. Name this key "shell". Create a key for this folder ("shell") as well, this time named "open". Now create another key for this folder ("open") and call it "command". The end result should look like the image below.

Nested folders

  1. Select the "command" folder and change its "(Default)" value again. Set it to the path of the file you want to open surrounded by quotes. If you want arguments to be passed, put a space behind the first string and behind that %1 surrounded by quotes.

Example file path

  1. Test the scheme by going to the name of the scheme followed by ://. Be sure to go to the page and not to google it (see image). It should now open the program. If you added the %1, any string after :// will be passed as arguments. If your program would be explorer.exe (windows explorer) and your command was explorer://C: it would open up to the C: drive. If it works go to step 11 and otherwise go to step 10.

Go to page, don't google

  1. Double check that the file path you passed in step 8 is correct and does indeed open the program. Also check that you went to the correct URL in your browser (your scheme followed by ://). If you added the "%1" behind the path, try to remove it and try again. Some programs don't play nice with it. For example explorer.exe will keep opening new copies of itself.

Adding the new URI scheme to a CRM item

  1. Go to the extension's options page.
  2. Create a new item (or use an existing one). The type will default to link.
  3. Open it by clicking on it. Enter a name you like in the "name" field.
  4. Enter the scheme you just created into the input field under the "Link(s)" section. Be sure to check the "Open in current tab" checkbox. Not doing this will open the scheme in a new tab, leaving an empty page open which is useless.

Enter the scheme

  1. Press save and test it.

Passing arguments to the program

You can pass arguments to the program you want to call by adding "%1" at the end of the command in regedit as seen above. Unfortunately, this "%1" will be replaced with the full scheme. Most programs don't expect the full scheme as a parameter. For example, if you want to open www.google.com in chrome, you would normally run chrome.exe "www.google.com". The problem however, is that the "%1" is replaced with the full scheme. So if you call myscheme://www.google.com, chrome is called as chrome.exe myscheme://www.google.com and it doesn't know what to do with that.

I've created a little python script to fix this problem over here. Simply download the script and install python if you haven't already. Instead of calling the program you want to execute directly, use the following steps to pass the output you want to pass to the program.

This tutorial takes starts after step 7 in "Manually adding the key value pair" tutorial.

  1. Get the full command you want to execute. The example command we'll use is the one below, where we want to dynamically choose the URL to open. So we want myscheme://about:blank to open the about:blank page in chrome. To do so, we'll first put in a filler value, which is in this case about:blank.
C:\Program Files (x86)\Google\Chrome\Application\chrome.exe --incognito "about:blank"
  1. Surround any separate part that is not already in quotes with quotes:
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" "--incognito" "about:blank"
  1. Replace the values that you want to be substituted with a hash (#) immediately followed by a number, starting at one. For example the first passed value would be replaced with #1, the second one with #2 and the third one with #3. Since the value we want to choose dynamically is about:blank, we end up with the following:
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" "--incognito" "#1"
  1. (optional) install python if you haven't already. If you're wondering whether to install 2.7 or 3.*, both are fine.
  2. Download the python script, place it somewhere and copy its location.
  3. Prepend the word python in quotes followed by the path of the script in quotes to the command we just created.
"python" "C:\Users\me\scripts\urischeme-filter.py" "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" "--incognito" "#1"
  1. Select the "command" folder and change its "(Default)" value again. Set it to the command we just created.

  2. Test your scheme

  3. (optional) If you want the data you enter to contain slashes, and for that data to not be split up (for example a URL), add "-s" after the script in the command (see below). In this scenario, calling myscheme://www.google.com/search would result in chrome being called with "www.google.com/search" as a parameter instead of with just "www.google.com"

"python" "C:\Users\me\scripts\urischeme-filter.py" "-s" "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" "--incognito" "#1"
  1. (optional) In order get some more help regarding the script you downloaded, run it on the command line with the "-h" parameter