docs » WiFiTransitions

Allow arbitrary actions when transitioning between SSIDs

Download: https://github.com/Hammerspoon/Spoons/raw/master/Spoons/WiFiTransitions.spoon.zip

API Overview

API Documentation

Variables

actions
Signature WiFiTransitions.actions
Type Variable
Description

Table containing a list of actions to execute for SSID transitions. Each action is itself a table with the following keys:

  • to - if given, pattern to match against the new SSID. Defaults to match any network. Transitions through the disabled state are ignored (i.e. normally a nil SSID is reported when switching SSIDs)
  • from - if given, pattern to match against the previous SSID. Defaults to match any network.
  • fn - function to execute if there is a match. Can also be a list of functions, which will be executed in sequence. Each function will receive the following arguments:
    • event - always "SSIDChange"
    • interface - name of the interface on which the SSID changed
    • old_ssid - previous SSID name
    • new_ssid - new SSID name
  • cmd - shell command to execute if there is a match. Can also be a list of commands, which will be executed in sequence using hs.execute. If fn is given, cmd is ignored.
logger
Signature WiFiTransitions.logger
Type Variable
Description

Logger object used within the Spoon. Can be accessed to set the default log level for the messages coming from the Spoon.

Methods

processTransition
Signature WiFiTransitions:processTransition(new_ssid, prev_ssid, interface)
Type Method
Description

Process the rules and execute any actions corresponding to the specified transition.

This method is called internally by the hs.wifi.watcher object when WiFi transitions happen. It does not get any system information nor does it set any Spoon state information, so it can also be used to "trigger" transitions manually, either for testing or if the automated processing fails for any reason.

Parameters:

  • new_ssid - new SSID name
  • prev_ssid - previous SSID name. Defaults to nil
  • interface - interface where the transition occurred. Defaults to nil
start
Signature WiFiTransitions:start()
Type Method
Description

Start the WiFi watcher

Returns:

  • The WiFiTransitions spoon object