Control OBS and react to its events, via the obs-websocket plugin.
Install and configure the obs-websocket plugin first from their project
Note: This Spoon will only work with Hammerspoon 0.9.100 or later.
Note: This Spoon will only work with obs-websocket 5.0.1 or later, which also requires OBS Studio v27 or later.
Download: https://github.com/Hammerspoon/Spoons/raw/master/Spoons/OBS.spoon.zip
Example:
-- This example will start OBS, connect to it, and then start streaming once connected
obs = hs.loadSpoon("OBS")
obsCallback = function(eventType, eventIntent, eventData)
  print(eventType)
  print(eventIntent)
  print(hs.inspect(eventData))
  if eventType == "SpoonOBSConnected" then
    obs:request("StartStream")
  end
end
obs:init(obsCallback, "localhost", 4444, "password")
obs:start()
      | Signature | OBS.eventSubscriptionValues | 
              
|---|---|
| Type | Constant | 
| Description | A table of the possible values for the   | 
              
| Notes | 
  | 
              
| Source | Source/OBS.spoon/init.lua line 58 | 
| Signature | OBS:reconnectDelay | 
              
|---|---|
| Type | Variable | 
| Description | Controls how long to wait, in seconds, before attempting to reconnect to OBS. Defaults to   | 
              
| Source | Source/OBS.spoon/init.lua line 112 | 
| Signature | OBS:shouldReconnect | 
              
|---|---|
| Type | Variable | 
| Description | Controls whether the websocket connection should be re-established if it is lost. Defaults to   | 
              
| Source | Source/OBS.spoon/init.lua line 105 | 
| Signature | OBS:addEventSubsciption(event) | 
              
|---|---|
| Type | Method | 
| Description | Adds an event subscription  | 
              
| Parameters | 
  | 
              
| Returns | 
  | 
              
| Notes | 
  | 
              
| Source | Source/OBS.spoon/init.lua line 309 | 
| Signature | OBS:init(eventCallback, host, port[, password, eventSubscriptions]) | 
              
|---|---|
| Type | Method | 
| Description | Initialisation method  | 
              
| Parameters | 
  | 
              
| Returns | 
  | 
              
| Notes | 
  | 
              
| Source | Source/OBS.spoon/init.lua line 117 | 
| Signature | OBS:removeEventSubsciption(event) | 
              
|---|---|
| Type | Method | 
| Description | Removes an event subscription  | 
              
| Parameters | 
  | 
              
| Returns | 
  | 
              
| Notes | 
  | 
              
| Source | Source/OBS.spoon/init.lua line 326 | 
| Signature | OBS:request(requestType[, requestData[, requestId]]) | 
              
|---|---|
| Type | Method | 
| Description | Sends a request to OBS  | 
              
| Parameters | 
  | 
              
| Returns | 
  | 
              
| Notes | 
  | 
              
| Source | Source/OBS.spoon/init.lua line 343 | 
| Signature | OBS:requestBatch(requests[, haltOnFailure]) | 
              
|---|---|
| Type | Method | 
| Description | Sends a batch of requests to OBS  | 
              
| Parameters | 
  | 
              
| Returns | 
  | 
              
| Notes | 
 Example: spoon.OBS:requestBatch({
 {["requestType"] = "StartVirtualCam"},
 {["requestType"] = "SetCurrentProgramScene", ["requestData"] = { ["sceneName"] = "FancyScene" }}
})
 | 
              
| Source | Source/OBS.spoon/init.lua line 377 | 
| Signature | OBS:setLogLevel(level) | 
              
|---|---|
| Type | Method | 
| Description | Sets the logging level for the OBS Spoon  | 
              
| Parameters | 
  | 
              
| Returns | 
  | 
              
| Source | Source/OBS.spoon/init.lua line 419 | 
| Signature | OBS:start() | 
              
|---|---|
| Type | Method | 
| Description | Connects to OBS  | 
              
| Parameters | 
  | 
              
| Returns | 
  | 
              
| Source | Source/OBS.spoon/init.lua line 161 | 
| Signature | OBS:stop() | 
              
|---|---|
| Type | Method | 
| Description | Disconnects from OBS  | 
              
| Parameters | 
  | 
              
| Returns | 
  | 
              
| Source | Source/OBS.spoon/init.lua line 274 | 
| Signature | OBS:updateEventSubscriptions(eventSubscriptions) | 
              
|---|---|
| Type | Method | 
| Description | Updates the event subscriptions  | 
              
| Parameters | 
  | 
              
| Returns | 
  | 
              
| Source | Source/OBS.spoon/init.lua line 289 |