Skip to Content
ScriptEvent Scripts

Event Scripts

iOS/tvOS5.0+macOS5.0+

Stash supports triggering JavaScript scripts when specific runtime events occur. Event scripts are configured under event.script, with script sources declared through script-providers.

For JavaScript script syntax and available interfaces, refer to Syntax and Interface.

Configuration Format

event: script: - name: on-network-changed event: network-changed argument: 'arg-value' # Optional, parameter passed to the script timeout: 30 # Optional, execution timeout in seconds, defaults to 30 - name: on-engine-started event: engine-started script-providers: on-network-changed: url: https://example.com/network-changed.js interval: 86400 on-engine-started: url: https://example.com/engine-started.js interval: 86400

Parameters:

  • name: Script name, matching the script identifier declared in script-providers.
  • event: Event type that triggers script execution.
  • argument: Optional, runtime parameter passed to the script, of type string.
  • timeout: Optional, script execution timeout in seconds, defaults to 30.

Supported Event Types

In event scripts, $script.type is "event", and the global $event object contains { name, data }:

Event NameDescription$event.data Structure
network-changedNetwork environment changed (e.g., switching between Wi-Fi and cellular){ ipv4, ipv6, interface, ssid } (ipv4/ipv6 are booleans; interface can be "wifi", "cellular", "wired", "loopback", or "other"; ssid is a string)
engine-startedStash engine startup completed{}
profile-reloadedProfile reload completed{}
notificationTriggered when a script sends a notification via $notification.post{ title, subtitle, body, info }

Inside a script handling the notification event, $notification.post is automatically ignored by the system to prevent recursive triggering.

Script Example

// $script.type === 'event' console.log(`Event triggered: ${$event.name}`) if ($event.name === 'network-changed') { const { ssid, interface: iface, ipv4, ipv6 } = $event.data console.log( `Current network: ${iface}, SSID: ${ssid || 'None'}, IPv4: ${ipv4 ? 'Available' : 'Unavailable'}, IPv6: ${ipv6 ? 'Available' : 'Unavailable'}`, ) // Automatically switch policy on a specific Wi-Fi network if (ssid === 'Home-5G') { await $stash.setSelectGroupPolicy('PROXY', 'DIRECT') } } $done()
Last updated on