Environment
An Environment
contains properties and method related to the overall application environment. A single instance is always available via the nova
global.
Properties
assistants
The global instance AssistantsRegistry object used to register and interact with assistants.
This property is readonly.
clipboard
The global instance Clipboard object.
This property is readonly.
Added in Nova 1.2.
commands
The global instance CommandsRegistry object used to register and interact with commands.
This property is readonly.
config
The Configuration object for the application, written into the user’s global preferences.
It is recommended that extensions prefix variables they define with a common string, followed by a dot, such as “my_extension.key_name”.
Variables defined by an extension’s payload using the “configuration” key will automatically be shown in the extension’s global preferences UI.
This property is readonly.
crypto
The global instance Crypto object.
This property is readonly.
Added in Nova 10.
credentials
The global instance of the Credentials object used to interact with credential storage.
This property is readonly.
environment
An Object
containing the environment variables available to task execution, such as invocations of the Process class. Most often, this includes the values made available to the user’s default login shell. As such, this value can change depending on the state of the user’s preferences for requesting environment from the default login shell.
This property is readonly.
extension
The current Extension instance representing the running extension.
This property is readonly.
fs
The global instance of the FileSystem object.
This property is readonly.
locales
An array of strings defining the user’s preferred languages, in BCP 47 format.
This property is readonly.
path
The global instance of the Path object.
This property is readonly.
subscriptions
A CompositeDisposable object that will be cleaned up automatically when the extension is deactivated. Extensions may add any disposable objects they wish to this composite. Built-in objects from the extension runtime do not need to be registered for deactivation (all built-in objects will be cleaned up automatically when an extension is deactivated.) However, custom objects implementing the Disposable interface may wish to receive a call to dispose()
to perform some action when they are cleaned up. The extension itself should not attempt to dispose of this object, it will be done automatically by the extension runtime at a proper time.
This property is readonly.
systemVersion
The current operation system version, an an Array
of three Number
values. Each number corresponds to the major, minor, and patch version of the operation system, respectively (e.g. for macOS 10.14.0 the returned value would be [10, 14, 0]
).
This property is readonly.
version
The current application version, as an Array
of three Number
values. Each number corresponds to the major, minor, and patch version of the application, respectively (e.g. for Nova 1.0.2 the returned value would be [1, 0, 2]
). This array will not reflect whether the application version contains a beta identifer (such as 1.0.2b3
).
This property is readonly.
versionString
The current application version (as a String
).
This property is readonly.
workspace
The current Workspace instance representing the workspace in which the extension is executing.
This property is readonly.
Methods
beep()
Alert the user by causing an auditory beep.
localize(key, value, [tableName])
Returns a localized version of the string designated by the specified key and residing in the specified localization table within the extension.
This method searches each of the extension’s localizations (directories using an .lproj
extension) for a JSON file with the name tableName
. If tableName
is not provided or null
, it will search for a default file named strings.json
. Localizations are searched in the preferred order based on the user’s preferred languages.
The return value of this method depends on its arguments:
- If
key
isnull
andvalue
isnull
, returns an empty string. - If
key
isnull
andvalue
is non-null, returnsvalue
. - If
key
is not found andvalue
isnull
or an empty string, returnskey
. - If
key
is not found andvalue
is non-null and not empty, returnvalue
.
isReleasedVersion()
Whether the current application version is a fully-qualified release (true
) or a pre-release (false
).
inDevMode()
Whether the current extension is running in development (ad-hoc) mode.
openConfig([identifier])
Requests the application open the global settings view for a specified extension, by identifier. If no identifier is specified, the current extension’s global settings will be opened.
openURL(url, [callback])
Asks the application to open a url using the user’s preferred handler. For example, passing an HTTP URL to this method will open it the user’s default browser.
The optional callback
argument should be a callable, which will be invoked when the URL has been handled. The callback will be passed a boolean value indicating whether the URL was successfully opened (an example of failure would be if no application is installed to handle the URL).