Skip to content

ShellOption

tympanix edited this page Mar 15, 2017 · 4 revisions

Description

ShellOption is used to to define additional actions in the context menu when right clicking a file. A ShellOption must always be linked to a ProgId and cannot be instantiated without the presence thereof. The context menu of a file is linked directly to the ProgId hence the file in question must have the ProgId as its default program. Only the user can determine which ProgId he/she chooses to be the default for any given file type.

Example

The following example shows the general usage of ShellOption and creation of three actions which will be shown in the context menu.

new ProgId({
    // Other options...
    shell: [
        new ShellOption({verb: ShellOption.OPEN}),
        new ShellOption({verb: ShellOption.EDIT, args: ['--edit']}),
        new ShellOption({verb: 'customaction', args: ['--custom'], action: 'Awesome Action'})
    ]
})

Options

verb, (string), default: ShellOption.OPEN

The verb is used as an identifier for the shell action. Although you can define your own verb, some verbs have special meaning (canonical verbs) in the default windows context menu. The verb is not shown in the context menu and is for programmatic purposes.

More: Creating Shortcut Menu Handlers

action, (string)

The actions defines the localized name for the action shown in the context menu. When using canonical verbs these default to the localized string of the action e.g. Open, Edit or Print. If the verb is not a canonical verb and the action option is not supplied, the name of the context menu action will default to the value given in verb

icon, (string)

A tiny icon can be shown in the context menu to the left of the name. If the path is relative it will be relative to the application executable. For canonical verbs it is not advised to show any icon but may be considered for custom verbs.

args, (string array), default: ['%1']

The arguments that is passed to the command when invoking the context menu action. The arguments are appended to the command which will be executed. The default value is the special argument %1 which will resolve to the absolute path of the file that the action was invoked upon.

friendlyAppName, (string)

A localized name of the action that is shown in the Open with... menu. If not supplied this will default to the name of your application executable. Note the friendlyAppName may be different for every ShellOption. Only the friendlyAppName for the ShellOption that is the default (selected) command for the ProgId will be displayed as the official app name. If set to true the value will be taken from app.getName() which is the name of your Electron application. You will only need to change this if you need to set your application name dynamically or have another good reason to deviate from your default executable name. For most use cases this option is redundant.

selected, (boolean), default: false

Whether the action is the default selected action when opening the context menu. This action will always appear as the first action, will be highlighted in bold, and is the action performed when double clicking the file. If the option is not supplied, the default context menu action will default to the verb ShellOption.OPEN.

squirrel, (boolean), default: false

Not part of the windows registry but merely a helping option to ease the use for applications using the Squirrel framework. Settings this to true will set the command to the Squirrel executable and call it with the --process-start-args argument followed by the arguments supplied in args. If you are using Squirrel this is a set it and forget it option. Instead of setting this individually you can set it for all shell options in the ProgId.

command, (string), default: process.execPath

The command that is executed when invoking the context menu action. The command is appended the arguments from args. All arguments and the command itself is enclosed in double quotes.

Functions

install(), returns: Promise

Installs the ShellOptions into the ProgId which it is linked to. Returns a promise whether the installation was successful or not.