-
Notifications
You must be signed in to change notification settings - Fork 107
Scripting
This section will describe how to use the scripting API to add custom macro conditions and actions.
The API is not limited to Python, but the examples showcased here will only be using Python.
This examples shows how to register a new condition type which will randomly evaluate to true based on provided user input percentage in the range from 0 to 100:
import obspython as obs
import threading # Required by advss helpers
import random
CONDITION_NAME = "Random condition"
###############################################################################
# This function will define the UI for the custom condition type based on a obs_properties object.
# In this case only a single float selection field for specifying the probability of returning true.
# This isn't mandatory.
# You can also have a condition without any additional UI elements.
###############################################################################
def get_condition_properties():
props = obs.obs_properties_create()
obs.obs_properties_add_float(
props, "probability", "Probability of returning true", 0, 100, 0.1
)
return props
###############################################################################
# You can provide default values for each of the settings you have defined earlier.
# This isn't mandatory.
# You can also have a condition without any settings to be modified.
###############################################################################
def get_condition_defaults():
default_settings = obs.obs_data_create()
obs.obs_data_set_default_double(default_settings, "probability", 33.3)
return default_settings
###############################################################################
# This function will be used by the advanced scene switcher to determine if a condition evaluates to true or false.
# The settings for each instance of this condition type will be passed via the data parameter.
###############################################################################
def my_python_condition(data):
target = obs.obs_data_get_double(data, "probability")
value = random.uniform(0, 100)
return value <= target
###############################################################################
# Let's register the new condition type
###############################################################################
def script_load(settings):
advss_register_condition(
CONDITION_NAME,
my_python_condition,
get_condition_properties,
get_condition_defaults(),
)
###############################################################################
# Deregistering is useful if you plan on reloading the script files
###############################################################################
def script_unload():
advss_deregister_condition(CONDITION_NAME)
###############################################################################
########################### boilerplate code below ############################
###############################################################################
This is the custom condition type we defined with this script in action:

As you can see the frequency at which this condition returns true depends on the provided input value, just as we expect it to.
Registering an action would be identical to the example above, but instead of passing a function which returns a boolean value to advss_register_condition, you would pass a function performing your desired actions to advss_register_action.
The boilerplate code mentioned above can be found here. (TODO) Usually you can just copy it directly into your script without any modifications.
The advanced scene switcher offers the following procedure handlers:
bool advss_register_script_action(in string name, in ptr default_settings, out string properties_signal_name, out string trigger_signal_name)bool advss_register_script_condition(in string name, in ptr default_settings, out string properties_signal_name, out string trigger_signal_name)bool advss_deregister_script_action(in string name)bool advss_deregister_script_condition(in string name)bool advss_get_variable_value(in string name, out string value)bool advss_set_variable_value(in string name, in string value)
- Installation
- Show webcam only when speaking
- Twitch Category Changer
- Hotkeys to control counter in text source (e.g. death or win counter)
- Show text source with latest Twitch follower
- Detect elements on screen and hide them automatically
- Motion detection
- Start other programs when starting OBS
- Crossfading audio during scene changes
- Looping a set of media sources
- Switch scenes randomly
- Re-shuffle VLC source
- Automatically switch scene if a game capture's target window no longer exists
- Audio based scene switching in podcast setting
- Switching scenes based on portrait or landscape mode resolution of a window capture source
- Set up a hotkey to start and stop recording with a fade from and to black
- Automatically cycle through a list of scenes
- Toggle visibility of scene items on a timer
- Advance through a list of scenes by hotkey
- Performing actions only when transitioning from A to B
- Media playlist with commercial interruptions
- Split recording of stream into chunks
- Switching scenes for Aitum Vertical plugin
- Using MIDI devices
- Controlling audio source volume using MIDI devices
- Change capture window of Window Capture source
- Show URLs in clipboard in browser source
- Use hotkey to refresh browser source
- League of Legends process based scene swtich
- Push-to-show source
- General tab overview
- Starting and stopping the plugin
- Macros explained
- Macro tab overview
- Creating a macro
- Pausing macros
- Macro duration modifiers
- Macro docks
- Exporting and importing individual macros
- Audio condition
- Cursor condition
- Date condition
- Hotkey condition
- Media condition
- Process condition
- Scene item transform condition
- Slide Show condition
- Video condition
- Audio action
- Http action
- Hotkey action
- Random action
- Scene item visibility
- Sequence action
- Action Queue example
- Variables
- Macro properties
- Websockets
- Scripting
- Troubleshooting
- Saving and loading settings