Automate OBS Studio Profile Switching via Bash CLI

This guide explains how to automate profile and scene switching in OBS Studio using a custom Bash script and command-line interface (CLI) tools. By leveraging the built-in OBS WebSocket server and a lightweight terminal client, you can trigger seamless stream configuration changes automatically based on system events, hotkeys, or schedules.

1. Enable OBS WebSocket Server

To allow a command-line tool to communicate with OBS Studio, you must enable its built-in WebSocket server.

  1. Open OBS Studio.
  2. Navigate to Tools > WebSocket Server Settings from the top menu.
  3. Check the box to Enable WebSocket Server.
  4. Note the Server Port (default is 4455) and click Show Connect Info to copy or set your Server Password.

2. Install the OBS Command-Line Tool

To send commands from your Bash script to OBS, you need a CLI utility. The open-source tool obs-cmd is designed specifically for OBS WebSocket v5.

3. Write the Custom Bash Script

Create a new script file, make it executable, and configure it to connect to your OBS instance to switch profiles.

  1. Create the script file:

    touch switch_obs.sh
    chmod +x switch_obs.sh
  2. Open the file in a text editor and add the following code:

    #!/bin/bash
    
    # Configuration - Match these with your OBS settings
    OBS_HOST="localhost"
    OBS_PORT="4455"
    OBS_PASSWORD="your_actual_password_here"
    
    # Target Profile and Scene names
    TARGET_PROFILE="Gaming_Setup"
    TARGET_SCENE="In-Game Action"
    
    # Helper variable for the command
    OBS_CLI="obs-cmd -w $OBS_HOST:$OBS_PORT -p $OBS_PASSWORD"
    
    echo "Connecting to OBS..."
    
    # Switch the Profile
    echo "Switching profile to: $TARGET_PROFILE"
    $OBS_CLI profile switch "$TARGET_PROFILE"
    
    # Pause briefly to allow the profile swap to load assets
    sleep 1.5
    
    # Switch to the desired Scene within that profile
    echo "Switching scene to: $TARGET_SCENE"
    $OBS_CLI scene switch "$TARGET_SCENE"
    
    echo "OBS configuration updated successfully."

4. Run and Test the Script

Ensure OBS Studio is running, then execute the script from your terminal:

./switch_obs.sh

If configured correctly, OBS Studio will immediately swap to your specified profile and transition to the target scene. You can now bind this script to keyboard shortcuts, system cron jobs, or trigger it automatically when specific applications launch.