Help with Connecting to OBS WebSocket Using a Script Launched by Automator (macOS)

Gregoryen

New Member
Hello everyone,

I’m working on macOS and using Automator to run scripts, whether they’re in Python, Shell, or another language. I’m trying to set up a script that, when launched from Automator, connects to the OBS Studio WebSocket server (port 4455 with a password) to activate or deactivate a macro (called TEST for this example) within the Advanced Scene Switcher plugin.

My Goal

Once the Automator app is launched, I want it to execute a script that connects to the OBS WebSocket and sends a command to toggle the macro.

What I Need Help With

1. What type of script to use? Python, Shell, or something else—I’m open to suggestions on which solution would be best.
2. Example code for the script: A basic script that connects to the OBS WebSocket and sends this command would be really helpful. I’m not sure what needs to go in the script for this connection.

Thanks in advance for any advice and guidance!
 

Warmuptill

Active Member
Hi,
Unfortunately I am not too familiar with MacOS / the Automator app, but I have used the obs websocket interface of the Advanced Scene Switcher before, so I might be able to help in that regard.

Let's assume you have a macro setup like this:

1729933332653.png


The macro "Listen for pause" is listening for the websocket message containing the string "Pause the other macro" and if it receives said message it pauses the macro named "TEST".

If that is roughly what you had in mind you can use the following python script to send the corresponding websocket message to OBS:

Code:
from obswebsocket import obsws, requests

host = "localhost"
port = 4455
password = "password"
message = "Pause the other macro"

ws = obsws(host, port, password)
ws.connect()

try:
    ws.call(
        requests.CallVendorRequest(
            vendorName="AdvancedSceneSwitcher",
            requestType="AdvancedSceneSwitcherMessage",
            requestData={"message": message},
        )
    )

except KeyboardInterrupt:
    pass

ws.disconnect()

The python script uses obs-websocket-py, which can be installed with:
pip3 install obs-websocket-py

You can of course also set up a second macro / extend the logic for the unpause case.

Hope that helps!
 
@Warmuptill ....

I have been successful at getting python script to work against AdvSS as you showed, and I thank you.

Do you know how to do the same from Javascript?

(I am trying to create a web page that provides a way to trigger hotkeys from a mouse click, and hanve not been able to make obs-websockets-js to work right, although I can get it to connect, from a Javascript.)
 
Top