Read and write private data between scripts or plugins
masterYou can share data between different scripts or plugins using OBS private data. This allows one script to write a value that another script can later retrieve.
Writing Data (Python)
Use S.obs_data_create(), set the value using the appropriate obs_data_set_<type> function, and then call S.obs_apply_private_data(settings) to commit it.
Reading Data (Python)
It is recommended to use a context manager to handle the lifecycle of the private data settings. Retrieve the data using S.obs_get_private_data() and the corresponding obs_data_get_<type> function, ensuring you call S.obs_data_release(settings) when finished.
Writing Data (Lua)
In Lua, create settings with S.obs_data_create(), set the value (e.g., S.obs_data_set_int), apply it with S.obs_apply_private_data(settings), and release the settings.
# Writing in Python
def send_to_private_data(data_type, field, result):
settings = S.obs_data_create()
set_func = getattr(obs, f"obs_data_set_{data_type}")
set_func(settings, field, result)
S.obs_apply_private_data(settings)
S.obs_data_release(settings)
# Reading in Python
@contextmanager
def p_data_ar(data_type, field):
settings = S.obs_get_private_data()
get_func = getattr(obs, f"obs_data_get_{data_type}")
try:
yield get_func(settings, field)
finally:
S.obs_data_release(settings)