Execute action and return immediately
I am executing some reaper actions that pop up a dialog box and I spent a considerable amount of time writing code to interact with that dialog box from an external app. It works.
I then tried to put that code in a lua script and quickly realized that it won't work because Main_OnCommandEx is synchronous/blocking, probably due to the modal dialog window.
Basically, I do
Main_OnCommandEx(ActionThatPopsUpDialogBox/Window)
Exec("MyApp");
But MyApp needs to be ran while the dialog is up, but this doesn't occur because the Main_OnCommandEx does not return until the dialog is closed ;/
I cannot reverse the order for several reasons. The major one is Exec is blocking(I use io.popen, which blocks. Even if it didn't, would create some serious synchronizing issues). If I could get a non blocking Exec I might be able to get it to work, but it will be tricky.
While I doubt it is possible, my suggestion is for reaper to allow one to run Main_OnCommandEx assynchronously. Either by adding another command such as Main_OnCommandExAsync or passing a flag. to know when the command is finished running, one can query to see. (by simply running the command in it's own thread, which should be easy to do, a few lines of code, this can be accomplished).
Does anyone have any ideas how to solve this?
heres the Exec function I'm using
function Exec(cmd, raw)
raw = raw or true
local f = assert(io.popen(cmd, 'r'))
local s = assert(f:read('*a'))
f:close()
if raw then return s end
s = string.gsub(s, '^%s+', '')
s = string.gsub(s, '%s+$', '')
s = string.gsub(s, '[\n\r]+', ' ')
return s
end
For a test case, you can do:
reaper.Main_OnCommandEx(40022);
reaper.ShowConsoleMsg("This should pop up right after the save as dialog box opens from above, not after it closes!")
Last edited by Airal; 06-18-2017 at 05:02 AM.
|