DmitriySalnikov / OBSNotifier

Simple program for displaying notifications from OBS on your desktop.
MIT License
51 stars 1 forks source link

[Feature Request] / [Script] Autostart with OBS #5

Closed ghost closed 2 years ago

ghost commented 2 years ago

Hi, I've just tried this for the first time and it's excellent! Thanks very much :) I'm migrating to linux soon, and I'm going to miss it already.

There is one thing I'd like to do if it's possible, and that's automatically start OBSNotifier with OBS. I don't want to start with windows and run in the background always, because this PC is not always used for gaming/streaming purposes.

Since I'm also running OBS with 'below normal' process priority, I would like to do this for OBSNotifier, too.

I started to write this as a FR but then I decided I was being lazy so I tried to remember some lua I knew once, read a few docs, and wrote this. It's the first lua I've written in about 15 years, and minimum effort, so it's probably horrible and needs fixing in some way, but it does work!

I put the script in the OBSNotifier appdata directory, so that it can be edited without admin, and OBSNotifer in program files, but I figured I should have a facility to choose the path to the .exe, and to opt in/out of low process priority, and also it logs what it's trying to do. This is what it looks like, pretty spartan: image

Maybe it'll be useful for you or others, so I'll share it here, note it is unlicensed so do what you like with it:

obs = obslua

function script_description()
    return [[Starts OBSNotifier when OBS starts]]
end

function script_defaults(settings)
    local OBSNotifierPathDefault = "%PROGRAMFILES%\\OBSNotifier\\OBSNotifier.exe"
    obs.obs_data_set_default_bool(settings, "lowprio", true)
    obs.obs_data_set_default_string(settings, "path", OBSNotifierPathDefault)
end

function script_properties()
    local properties = obs.obs_properties_create()
    obs.obs_properties_add_path(properties, "path", "Path to OBSNotifier", obs.OBS_PATH_FILE, "Program (*.exe)", nil)
    obs.obs_properties_add_bool(properties, "lowprio", "Run with lower priority")
    obs.obs_properties_apply_settings(properties, settings)
    return properties
end

function script_update(settings)
    path = obs.obs_data_get_string(settings, "path")
    path = path:gsub("/", "\\")
    lowprio = obs.obs_data_get_bool(settings, "lowprio")
    start_OBSNotifier(path, lowprio)
end

function start_OBSNotifier(path, lowprio)
    priostring = "/NORMAL"
    if (lowprio == true)
    then priostring = "/BELOWNORMAL"
    end
    StartCommand = "start /B " .. priostring .. " \"OBSNotifier\" \"" .. path .. "\""
    obs.script_log(obs.LOG_INFO, "Executing command: " .. StartCommand)
    output = os.execute(StartCommand)
    obs.script_log(obs.LOG_INFO, "Output: " .. output)
end
DmitriySalnikov commented 2 years ago

Sounds good. I can add a button to create this script in AppData, update it if necessary and show the user a hint on how to use it.

image

I'm migrating to linux soon, and I'm going to miss it already.

I've already thought about remaking this program on something cross-platform. But for example, using Avalonia, this program will become much larger, not 2MB, but 60MB+

ghost commented 2 years ago

Well obviously I am biased, but I wouldn't mind a bigger program. I think the memory footprint won't be an issue on a PC that's streaming anyway. So long as the performance is still good. The performance now seems excellent.

It would be great to have a button to create the script! Makes it much easier to install :)

Thanks mate!

DmitriySalnikov commented 2 years ago

Well obviously I am biased, but I wouldn't mind a bigger program. I think the memory footprint won't be an issue on a PC that's streaming anyway. So long as the performance is still good. The performance now seems excellent.

Yes, I agree. This is not a problem when one replay can take from 100MB and up to several GB.. I just don't like when a mini application with little functionality takes up a lot of space. Like, for example, most applications on electron. Anyway, I'll think about different options. I want to fix the other issues first.

DmitriySalnikov commented 2 years ago

I started working on this feature, but I simplified the script a bit. Now there is no parameter for choosing the path to the program. This path is set when creating or updating the script by clicking in the OBS Notifier settings.

obs = obslua

function script_description()
    return [[Starts OBSNotifier when OBS starts]]
end

function script_defaults(settings)
    obs.obs_data_set_default_bool(settings, "lowprio", true)
end

function script_properties()
    local properties = obs.obs_properties_create()
    obs.obs_properties_add_bool(properties, "lowprio", "Run with lower priority")
    obs.obs_properties_apply_settings(properties, settings)
    return properties
end

function script_update(settings)
    lowprio = obs.obs_data_get_bool(settings, "lowprio")
    start_OBSNotifier(path, lowprio)
end

function start_OBSNotifier(path, lowprio)
    priostring = "/NORMAL"
    if (lowprio == true)
    then priostring = "/BELOWNORMAL"
    end
    StartCommand = "start /B /MIN " .. priostring .. " \"OBSNotifier\" \"&OBS_NOTIFIER_PATH&\" --force_close"
    obs.script_log(obs.LOG_INFO, "Executing command: " .. StartCommand)
    output = os.execute(StartCommand)
    obs.script_log(obs.LOG_INFO, "Output: " .. output)
end

I think it will be easier this way. The user will only need to specify the path to the script. Also, the path will be automatically copied to the clipboard after clicking on the button.

ghost commented 2 years ago

Now there is no parameter for choosing the path to the program. This path is set when creating or updating the script by clicking in the OBS Notifier settings. The user will only need to specify the path to the script. Also, the path will be automatically copied to the clipboard after clicking on the button.

Very smooth :)

DmitriySalnikov commented 2 years ago

I seem to have completed the integration of the autostart script acd02500b80f42dca42a3bd9bdff9fe7bcd3ef32 Could you check if it works as intended? download an artifact

ghost commented 2 years ago

...And you got CI working, nice!

Works great, thanks mate!

Edit: I did notice this little typo 'settigns' image

DmitriySalnikov commented 2 years ago

Thanks!

DmitriySalnikov commented 2 years ago

I did make more changes to the script 7561b2c7422afdcb09ce9ffb2e97d0bf7621b5e3 3c1e686977819c2bb8939c9929318d2c330f4d76 I didn't like that the console window appeared before opening OBS Notifier. Now WinAPI is used to open the program.

Now I think it's finished. (but maybe there are some bugs 🙂)

ghost commented 2 years ago

Works great! I see you also noticed the thing where it wouldn't open the first time, thanks for getting that one too :) I had assumed that the flashing console screen was OBS launching the script, when in reality it was the script launching OBSNotifier. Sorry about that. It's much better now.

image This was nice, too. All very smooth.