|
|
|
09-14-2019, 11:50 AM
|
#1
|
Human being with feelings
Join Date: Dec 2011
Location: San Jose, CA, USA
Posts: 115
|
Run a background script at startup
I know about __startup.lua and I know I can execute commands from it when Reaper starts, but what about using it to start a background script?
Would dofile() be acceptable for starting a background script that utilizes defer() or is there another or better way?
EDIT: Just to be clear... I've tested dofile() and it works. I'm just not sure it's the best way to do it.
Thanks,
Ken
Last edited by kenm; 09-14-2019 at 11:57 AM.
Reason: See EDIT:
|
|
|
09-14-2019, 11:56 AM
|
#2
|
Human being with feelings
Join Date: May 2015
Location: Québec, Canada
Posts: 4,937
|
Yes, dofile from __startup.lua is fine and also SWS startup actions. A "background script" is just a script like all others.
EDIT: As suggested by Lokasenna below, Main_OnCommand(+NamedCommandLookup) is much better than dofile in this context.
Last edited by cfillion; 09-14-2019 at 12:25 PM.
|
|
|
09-14-2019, 12:03 PM
|
#3
|
Human being with feelings
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
|
dofile does run the child script in the same environment as the calling script.
I would suggest registering the script as an action and then running it from the startup script via Main_OnCommand - then it's completely separate from anything else you might want to do at startup*.
For instance, if you had five different background scripts you'd probably want them completely isolated from each other to avoid accidentally sharing any global values, not letting a crash take them all down, etc.
---
*Now that I think about it, a GUI script to help people manage startup actions without editing the startup file directly might be a good idea, similar to Nexus Mod Manager, and would really only make sense using the action approach above.
|
|
|
09-14-2019, 12:32 PM
|
#4
|
Human being with feelings
Join Date: Dec 2011
Location: San Jose, CA, USA
Posts: 115
|
Quote:
Originally Posted by Lokasenna
dofile does run the child script in the same environment as the calling script.
I would suggest registering the script as an action and then running it from the startup script via Main_OnCommand - then it's completely separate from anything else you might want to do at startup*.
For instance, if you had five different background scripts you'd probably want them completely isolated from each other to avoid accidentally sharing any global values, not letting a crash take them all down, etc.
---
*Now that I think about it, a GUI script to help people manage startup actions without editing the startup file directly might be a good idea, similar to Nexus Mod Manager, and would really only make sense using the action approach above.
|
True enough. The bottom of the Actions Menu shows __startup.lua still running.
Is there a way to define a consistent Action ID or should i just use NamedCommandLookup()?
|
|
|
09-14-2019, 12:55 PM
|
#5
|
Human being with feelings
Join Date: May 2017
Location: Leipzig
Posts: 6,621
|
Always use NamedCommandLookup to be on the safe side.
|
|
|
09-14-2019, 01:22 PM
|
#6
|
Human being with feelings
Join Date: Dec 2011
Location: San Jose, CA, USA
Posts: 115
|
Quote:
Originally Posted by mespotine
Always use NamedCommandLookup to be on the safe side.
|
OK. Sorry for being "thick in the head" but what's the call expecting?
I've tried:
val = reaper.NamedCommandLookup("Custom: ATOM_polling.lua") <-- From ReaperKeyMap file
val = reaper.NamedCommandLookup("Script: ATOM_polling.lua") <-- From Action Menu Text
val = reaper.NamedCommandLookup("_RSf8e4f6430c6d03c69b2d 5f2519ef97465317e503") <-- From Action Menu Command ID
but 'val' is always '0'.
|
|
|
09-14-2019, 01:41 PM
|
#7
|
Human being with feelings
Join Date: May 2017
Location: Leipzig
Posts: 6,621
|
https://mespotin.uber.space/Ultrasch...dCommandLookup
An example of such a call should be:
val=reaper.NamedCommandLookup("_RS6cb47ecf95a7665d f0c0de4e1c47746792fe5567")
If it returns 0, you probably either have a typo in the ActionCommandID or the ActionCommandID does not exist.
Have you tried other actions as well? You can try a number as well like 1007 and it should return 1007 as value.
val=reaper.NamedCommandLookup("1007") -- should return 1007
if it does not for some reason, then you found a bug.
|
|
|
09-14-2019, 02:32 PM
|
#8
|
Human being with feelings
Join Date: Dec 2011
Location: San Jose, CA, USA
Posts: 115
|
Not sure if this is a bug, an anomaly, or just the way it is, but...
This works if run from a script AFTER Reaper is up and running:
Code:
val = reaper.NamedCommandLookup("_RSf8e4f6430c6d03c69b2d5f2519ef97465317e503")
reaper.ShowConsoleMsg(tostring(val))
But shows '0' if executed in __startup.lua.
I suspect custom actions haven't been loaded yet when the startup script is run.
|
|
|
09-14-2019, 03:02 PM
|
#9
|
Human being with feelings
Join Date: May 2017
Location: Leipzig
Posts: 6,621
|
Hmm..shouldn't be the case. We use this all the time in __startup.lua
Maybe you need to report this as a bug in the bug-reports-section.
|
|
|
09-14-2019, 04:09 PM
|
#10
|
Human being with feelings
Join Date: Dec 2011
Location: San Jose, CA, USA
Posts: 115
|
Quote:
Originally Posted by mespotine
Hmm..shouldn't be the case. We use this all the time in __startup.lua
Maybe you need to report this as a bug in the bug-reports-section.
|
It is a bit odd. Do you use RedScript actions or actions created by extensions? I check and the SWS actions seems to enumerate correctly. It's only ReaScript actions that don't.
I ended up moving the NamedCommadLookup() to a function within my ATOM.lua module and it seems to work correctly now. I'll write up something in the bug-reports-section.
Thanks,
Ken
|
|
|
09-15-2019, 11:50 AM
|
#11
|
Human being with feelings
Join Date: Dec 2011
Location: San Jose, CA, USA
Posts: 115
|
Hi @mespotine,
Do you happen to be running on Windows? I'm on a Mac.
As it turns out, the bug is only in the Mac version. It works as expected and as you stated in the Windows version.
Bug report forthcoming.
Ken
|
|
|
09-15-2019, 02:58 PM
|
#12
|
Human being with feelings
Join Date: May 2017
Location: Leipzig
Posts: 6,621
|
Ok, this sounds like a bug.
Can you post a bugreport into the bugreports-subforum and include which Reaper version you use?
And can you post the accompanying scripts there as well, so the devs can test them directly?
|
|
|
09-15-2019, 04:09 PM
|
#13
|
Human being with feelings
Join Date: Dec 2011
Location: San Jose, CA, USA
Posts: 115
|
bug report posted.
Ken
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 02:47 AM.
|