Old 01-21-2018, 08:30 AM   #1
uncleswede
Human being with feelings
 
Join Date: Feb 2015
Posts: 1,096
Default User confirmation for custom actions?

Does anyone know of a way to add user confirmation to a custom action?

For example, you might have a "delete all tracks" custom action that, when executed, prompts "ARE YOU SURE Y/N?" and, only if you type/click Y, does the rest of the custom action run.

I was thinking either:

1) creating a SWS Cycle Action with an IF statement that runs a Y/N confirmation script, which returns ON or OFF to the Cycle action processor. If ON is returned (i.e. user confirmation) the cycle action runs the specified custom action (e.g. "delete all tracks".
but how to write a 'user confirmation' script that returns ON or OFF?


2) a complete script which starts with user confirmation and is then able to run a sequence of named Reaper actions (or action IDs, maybe)
my scripting prowess is minimal but I'd be happy to edit a boilerplate script to add the actions (or action IDs)

Any ideas welcome.

Cheers
uncleswede is offline   Reply With Quote
Old 01-21-2018, 08:37 AM   #2
foxAsteria
Human being with feelings
 
foxAsteria's Avatar
 
Join Date: Dec 2009
Location: Oblivion
Posts: 10,255
Default

action is called "prompt to continue"
__________________
foxyyymusic

Last edited by foxAsteria; 01-21-2018 at 10:45 AM.
foxAsteria is online now   Reply With Quote
Old 01-21-2018, 10:19 AM   #3
uncleswede
Human being with feelings
 
Join Date: Feb 2015
Posts: 1,096
Default SOLVED

OK - answered my own question.

Here's a boilerplate Reaper LUA script that can ask for confirmation at run time and then run a native or custom action of your choice.

Just substitute the TITLE, ACTIONID and NATIVE values, save as a text file with a .lua extension in your scripts folder and load into Reaper via the Action dialog Script/Load function

Code:
-- @description Run action with user confirmation
-- @version 1.0
-- @author uncleswede
-- @changelog
--  + init 21 Jan 2018

local r = reaper;

--Change the title to an appropriate prompt
local title = 'View virtual MIDI keyboard'

--Change actionID to the required action
--  TIP: rt-click on an action in the Reaper action screen
--       and choose Copy selected action command ID
--       to copy the ID to the clipboard
--  Native actions are numerical (5 digits) and custom/SWS
--  are alphanumeric
local actionID = '40377'

--set native to 0 for native reaper actions or any non-zero value for
--custom or extension (e.g. SWS) actions
local native = -1

r.Undo_BeginBlock2(0)
ret = r.MB(title .. ' (Y/N)?', title, 4)

 if ret == 6 then
 
   if native == 0 then
   
   r.Main_OnCommand(actionID, 0)
   
   else
 
   r.Main_OnCommand(r.NamedCommandLookup(actionID), 0)
   
   end
   
 end
 
r.Undo_EndBlock('Create folder from selected tracks', -1)
uncleswede is offline   Reply With Quote
Old 01-22-2018, 09:15 PM   #4
Jason Lyon
Human being with feelings
 
Join Date: May 2016
Posts: 720
Default

All supported languages allow you to use OnCommand API calls within scripts - in fact, most scripts I've come across contain one or more of them somewhere. I'd get used to using them in scripts to allow you options, even if the task you currently have in mind really is just an exercise to save fingerwork.

Custom Actions are always the best place to start. A lot of the time, it's already possible to do what you want natively or via whatever other Custom Actions you've downloaded.

They're essentially macros - the equivalent of chaining together a number of shortcut commands, just as you would with, say, a wordprocessor. If the job can be done like that - great. Even if you have to create your own chain of commands, worry no further.

But the day will come when you need more than just a single "Are you sure?" confirmation. You'll often need more than one confirmation or to get more detailed inputs from the user. You'll need to parse the inputs. You might need to check how many tracks or items are selected, what kind of data is on them, where you are on the timeline, etc. Or find certain tracks or items and read data from them or within their data files. Then you'll need to run certain actions on certain tracks or items and not others.

So at that stage you need to use and manipulate variables and arrays (tables in Lua) and decision branching, and that's scripting territory.

The custom action approach basically says: "hit this combination of keystrokes in this order." I'd describe it as "training REAPER to type".

The scripting approach says: "have a good look at what's going on and depending on what you find, hit some combination of keystrokes applied to chosen parts (or do all kinds of other devious things)." That's more like "teaching REAPER to solve a puzzle".

PS It's handy to right-click the menu bar in the Actions window and check the box "Show action IDs".

Last edited by Jason Lyon; 01-23-2018 at 05:30 AM.
Jason Lyon 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 12:08 PM.


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