Skip to main content

System Events

To communicate with external programs like python scrips you can use SystemEventManager in SmartifyOS.SystemEvents

SystemEventManager

System event manager for communicating with external processes using file changes.

CallEvent

public static void CallEvent(string eventPath, string content, bool createIfNotExists = false)

Modifies the file to trigger a change.

Parameters
eventPathPath to file, relative to user profile (eg. SmartifyOS/Events/event)
contentContent to write in file to add additional data for the other script (eg. python)
createIfNotExistsShould the file be created if it doesn't exist

SubscribeToEvent

public static void SubscribeToEvent(string eventPath, Action<string> onEvent)

Subscribes to file changes

Parameters
eventPathPath to file, relative to user profile (eg. SmartifyOS/Events/event)
onEventCalled when the file changes, includes the files content as string

Usage Example:

private void Start()
{
SystemEventManager.SubscribeToEvent("SmartifyOS/Events/OnUsbDeviceConnected", OnUsbDeviceConnected);
}

private void OnUsbDeviceConnected(string content)
{
Debug.Log("USB device connected");
}