Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save alex700/dcb70d5ee9a546884d916ce752770823 to your computer and use it in GitHub Desktop.
Save alex700/dcb70d5ee9a546884d916ce752770823 to your computer and use it in GitHub Desktop.
Elgato Key Light Controller for OBS studio (MacOS version)

Automating Elgato Key Light with OBS Studio on macOS

This guide explains how to automate an Elgato Key Light to turn on when OBS Studio opens and off when it closes, using macOS's launchd.

Prerequisites

  • Elgato Key Light connected to the same network as your Mac.
  • OBS Studio installed on your Mac.

Step 1: Find the IP Address of Your Elgato Key Light

  1. Open the Elgato Control Center app on your computer or mobile device.
  2. Locate your Key Light and find its IP address in the device settings (e.g., 192.168.50.227).
  3. Note down this IP address, as we’ll use it in the script.

Step 2: Create a Command to Control the Elgato Key Light

  1. Create the Shell Script to Control the Light:

    • Open Terminal and create a new script file:
      sudo nano /usr/local/bin/elgato_light
    • Paste the following code, replacing "<Elgato_IP>" with the actual IP address of your Key Light:
      #!/bin/bash
      
      ELGATO_IP="<Elgato_IP>:9123"
      
      if [ "$1" == "on" ]; then
          curl -X PUT "http://$ELGATO_IP/elgato/lights" \
              -H "Content-Type: application/json" \
              -d '{"lights":[{"on":1,"brightness":100,"temperature":213}]}'
      elif [ "$1" == "off" ]; then
          curl -X PUT "http://$ELGATO_IP/elgato/lights" \
              -H "Content-Type: application/json" \
              -d '{"lights":[{"on":0}]}'
      else
          echo "Usage: elgato_light {on|off}"
          exit 1
      fi
    • Save and close the file (Ctrl + X, then Y, then Enter).
  2. Make the Script Executable:

    sudo chmod +x /usr/local/bin/elgato_light
  3. Test the Command:

    • Run the following commands to ensure they work:
      elgato_light on   # Turns on the light
      elgato_light off  # Turns off the light

Step 3: Create a Script to Check OBS Status and Control the Light

  1. Create a Check Script:

    • In Terminal, create another script that checks if OBS Studio is running and toggles the light:
      nano ~/check_obs_light.sh
    • Paste the following code:
      #!/bin/bash
      
      if pgrep -f "/Applications/OBS.app/Contents/MacOS/OBS" > /dev/null; then
          /usr/local/bin/elgato_light on
      else
          /usr/local/bin/elgato_light off
      fi
    • Save and close the file.
    • Please note: the actual path to the application might be different. To locate path run ps aux | grep -i "obs" after you launch OBS.
  2. Make the Script Executable:

    chmod +x ~/check_obs_light.sh

Step 4: Set Up launchd to Run the Script Automatically

  1. Create a launchd Property List (plist) File:

    • This .plist file will run check_obs_light.sh at regular intervals to check OBS status.
    • Create the file with:
      nano ~/Library/LaunchAgents/com.user.check_obs_light.plist
  2. Add the Following Configuration:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
      <dict>
        <key>Label</key>
        <string>com.user.check_obs_light</string>
        <key>ProgramArguments</key>
        <array>
          <string>/bin/bash</string>
          <string>/Users/YOUR_USERNAME/check_obs_light.sh</string>
        </array>
        <key>StartInterval</key>
        <integer>3</integer>
        <key>RunAtLoad</key>
        <true/>
      </dict>
    </plist>
    • Replace YOUR_USERNAME with your actual macOS username.
  3. Load the launchd Agent:

    • Load the agent to start checking OBS status at intervals:
      launchctl load ~/Library/LaunchAgents/com.user.check_obs_light.plist
  4. To Reload the Agent After Making Changes:

    • If you update the .plist file (e.g., to change the interval), reload it with:
      launchctl unload ~/Library/LaunchAgents/com.user.check_obs_light.plist
      launchctl load ~/Library/LaunchAgents/com.user.check_obs_light.plist

That’s It!

Your setup is now complete. When you open OBS Studio, the Elgato Key Light will turn on, and when you close OBS Studio, it will turn off. This setup works seamlessly without needing a constantly running script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment