electron/docs/api/shell.md

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

87 lines
2.8 KiB
Markdown
Raw Normal View History

2013-09-09 07:35:57 +00:00
# shell
2013-08-14 22:43:35 +00:00
2016-04-21 22:39:12 +00:00
> Manage files and URLs using their default applications.
Process: [Main](../glossary.md#main-process), [Renderer](../glossary.md#renderer-process) (non-sandboxed only)
2016-11-03 17:26:00 +00:00
2013-08-14 22:43:35 +00:00
The `shell` module provides functions related to desktop integration.
2015-08-29 05:28:30 +00:00
An example of opening a URL in the user's default browser:
2013-08-14 22:43:35 +00:00
```js
2018-09-13 16:10:51 +00:00
const { shell } = require('electron')
2015-08-29 05:28:30 +00:00
shell.openExternal('https://github.com')
2013-08-14 22:43:35 +00:00
```
**Note:** While the `shell` module can be used in the renderer process, it will not function in a sandboxed renderer.
2015-08-29 05:28:30 +00:00
## Methods
The `shell` module has the following methods:
### `shell.showItemInFolder(fullPath)`
2013-08-14 22:43:35 +00:00
* `fullPath` string
2013-08-14 22:43:35 +00:00
Show the given file in a file manager. If possible, select the file.
2013-08-14 22:43:35 +00:00
### `shell.openPath(path)`
2013-08-14 22:43:35 +00:00
* `path` string
Returns `Promise<string>` - Resolves with a string containing the error message corresponding to the failure if a failure occurred, otherwise "".
Open the given file in the desktop's default manner.
2013-08-14 22:43:35 +00:00
### `shell.openExternal(url[, options])`
* `url` string - Max 2081 characters on windows.
* `options` Object (optional)
* `activate` boolean (optional) _macOS_ - `true` to bring the opened application to the foreground. The default is `true`.
* `workingDirectory` string (optional) _Windows_ - The working directory.
* `logUsage` boolean (optional) _Windows_ - Indicates a user initiated launch that enables tracking of frequently used programs and other behaviors.
The default is `false`.
Returns `Promise<void>`
Open the given external protocol URL in the desktop's default manner. (For example, mailto: URLs in the user's default mail agent).
### `shell.trashItem(path)`
* `path` string - path to the item to be moved to the trash.
Returns `Promise<void>` - Resolves when the operation has been completed.
Rejects if there was an error while deleting the requested item.
This moves a path to the OS-specific trash location (Trash on macOS, Recycle
Bin on Windows, and a desktop-environment-specific location on Linux).
2015-08-29 05:28:30 +00:00
### `shell.beep()`
2013-08-14 22:43:35 +00:00
Play the beep sound.
### `shell.writeShortcutLink(shortcutPath[, operation], options)` _Windows_
* `shortcutPath` string
* `operation` string (optional) - Default is `create`, can be one of following:
* `create` - Creates a new shortcut, overwriting if necessary.
* `update` - Updates specified properties only on an existing shortcut.
* `replace` - Overwrites an existing shortcut, fails if the shortcut doesn't
exist.
* `options` [ShortcutDetails](structures/shortcut-details.md)
Returns `boolean` - Whether the shortcut was created successfully.
Creates or updates a shortcut link at `shortcutPath`.
### `shell.readShortcutLink(shortcutPath)` _Windows_
* `shortcutPath` string
2016-08-25 21:43:06 +00:00
Returns [`ShortcutDetails`](structures/shortcut-details.md)
Resolves the shortcut link at `shortcutPath`.
An exception will be thrown when any error happens.