Old 11-20-2018, 01:33 AM   #1
Arthur McArthur
Human being with feelings
 
Arthur McArthur's Avatar
 
Join Date: Sep 2016
Location: Toronto
Posts: 744
Default Scripts to open/close another script

Is it possible to make scripts that don't toggle another script, but specifically just open or close it? Most scripts don't report their state to REAPER, so I can't use the Cycle Action Editor for this.
Arthur McArthur is offline   Reply With Quote
Old 11-20-2018, 08:03 AM   #2
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

By opening you mean, open it in the Reascript-IDE?
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is offline   Reply With Quote
Old 11-20-2018, 09:54 AM   #3
lb0
Human being with feelings
 
Join Date: Apr 2014
Posts: 4,171
Default

Yes - would definitely like to be able to close a specific script from another script.
__________________
Projects - Reascripts - Lua:
Smart Knobs 2 | LBX Stripper | LBX Floating FX Positioner
Donate via Paypal | LBX Tools Website
lb0 is offline   Reply With Quote
Old 11-20-2018, 10:27 AM   #4
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,913
Default

Quote:
Originally Posted by lb0 View Post
Yes - would definitely like to be able to close a specific script from another script.
You could possibly close a script window by sending it a close window message using js_ReaScriptAPI extension, this quick test works here (on Windows 7),..

Code:
hWnd = reaper.JS_Window_Find("ReaNoir v2.07", true) -- find window by title bar text
if hWnd ~=nil then 
  reaper.JS_WindowMessage_Post(hWnd, "WM_CLOSE", 0,0,0,0)
end

Last edited by Edgemeal; 11-20-2018 at 10:33 AM.
Edgemeal is offline   Reply With Quote
Old 11-20-2018, 03:30 PM   #5
Arthur McArthur
Human being with feelings
 
Arthur McArthur's Avatar
 
Join Date: Sep 2016
Location: Toronto
Posts: 744
Default

Quote:
Originally Posted by mespotine View Post
By opening you mean, open it in the Reascript-IDE?
I mean running the script, not opening in IDE
Arthur McArthur is offline   Reply With Quote
Old 11-20-2018, 03:30 PM   #6
Arthur McArthur
Human being with feelings
 
Arthur McArthur's Avatar
 
Join Date: Sep 2016
Location: Toronto
Posts: 744
Default

Quote:
Originally Posted by Edgemeal View Post
You could possibly close a script window by sending it a close window message using js_ReaScriptAPI extension, this quick test works here (on Windows 7),..

Code:
hWnd = reaper.JS_Window_Find("ReaNoir v2.07", true) -- find window by title bar text
if hWnd ~=nil then 
  reaper.JS_WindowMessage_Post(hWnd, "WM_CLOSE", 0,0,0,0)
end
This works great. Thanks edgemeal! How would one modify this to run the script if it isn't open?
Arthur McArthur is offline   Reply With Quote
Old 11-20-2018, 04:20 PM   #7
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,913
Default

Quote:
Originally Posted by Arthur McArthur View Post
This works great. Thanks edgemeal! How would one modify this to run the script if it isn't open?
Try something like,...
Code:
hWnd = reaper.JS_Window_Find("ReaNoir v2.07", true)-- find window by title bar text
if hWnd ~=nil then -- close window
  reaper.JS_WindowMessage_Post(hWnd, "WM_CLOSE", 0,0,0,0)
else -- launch ReaNoir script
  cmd = reaper.NamedCommandLookup('_RS3b8d8b2140a32d0bfaa6eda3bd21b06d0b7b215b')
  if cmd > 0 then 
    reaper.Main_OnCommand(cmd, 0)
  else
    reaper.MB("Invalid script Command ID!","ERROR",0)  
  end
end
NOTE: To close a window on Mac and Windows use this instead,..
Code:
reaper.JS_Window_Destroy(hwnd)

Last edited by Edgemeal; 05-10-2019 at 09:34 AM.
Edgemeal is offline   Reply With Quote
Old 11-20-2018, 10:07 PM   #8
Arthur McArthur
Human being with feelings
 
Arthur McArthur's Avatar
 
Join Date: Sep 2016
Location: Toronto
Posts: 744
Default

Awesome, thanks again! I ended up using this to just launch the script if it isn't open (works for docked scripts too which is great):

Code:
hWnd = reaper.JS_Window_Find("Reaticulate", true)-- find window by title bar text
if hWnd ~=nil then -- 
  
else -- launch  script
  cmd = reaper.NamedCommandLookup('_RSbe259504561f6a52557d2d1c64e52ef13527bf17')
  if cmd > 0 then 
    reaper.Main_OnCommand(cmd, 0)
  else
    reaper.MB("Invalid script Command ID!","ERROR",0)  
  end
end
Arthur McArthur is offline   Reply With Quote
Old 11-21-2018, 08:02 AM   #9
lb0
Human being with feelings
 
Join Date: Apr 2014
Posts: 4,171
Default

Quote:
Originally Posted by Edgemeal View Post
You could possibly close a script window by sending it a close window message using js_ReaScriptAPI extension, this quick test works here (on Windows 7),..

Code:
hWnd = reaper.JS_Window_Find("ReaNoir v2.07", true) -- find window by title bar text
if hWnd ~=nil then 
  reaper.JS_WindowMessage_Post(hWnd, "WM_CLOSE", 0,0,0,0)
end
Thanks Edgemeal, Yes - that would work. I'm very keen to maintain full OS independence - so would need to look into that - although I think most of JS's API's are cross-platform. And I'd worry if the script was docked - what then - does it still work? (I know - I should just try it - but I'm assuming a docked window becomes part of the containing window and so this would likely not work in that case)?
__________________
Projects - Reascripts - Lua:
Smart Knobs 2 | LBX Stripper | LBX Floating FX Positioner
Donate via Paypal | LBX Tools Website
lb0 is offline   Reply With Quote
Old 11-21-2018, 09:43 AM   #10
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,913
Default

You'll have to test it but I think JS coded the APIs to work with docking tabs also, for example my reset vu meter script seems to be work just fine on docked fx also.
Edgemeal is offline   Reply With Quote
Old 11-21-2018, 05:44 PM   #11
lb0
Human being with feelings
 
Join Date: Apr 2014
Posts: 4,171
Default

Quote:
Originally Posted by Edgemeal View Post
You'll have to test it but I think JS coded the APIs to work with docking tabs also, for example my reset vu meter script seems to be work just fine on docked fx also.
oooh - I'll give it a go then - thank you.
__________________
Projects - Reascripts - Lua:
Smart Knobs 2 | LBX Stripper | LBX Floating FX Positioner
Donate via Paypal | LBX Tools Website
lb0 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 02:25 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.