scheduled recording via external scripting

Emerogork2 asked about this here:
https://forum.audacityteam.org/t/task-scheduler-win-7-audacity-1-3-beta/21977/1
and here:
https://forum.audacityteam.org/t/can-i-program-a-start-stop-times-for-audacity/22626/7
and in a Feature Request here:
https://forum.audacityteam.org/t/fr-task-scheduler-win-7-audacity-1-3-beta/22650/1

I thought the reply to be more general and of interest to a wider audience so will discuss using the Windows Task Scheduler with AutiIt3***** in this thread. If folks on Mac and/or Linux could chime in with similar tools that would be great!

I am going to break the instructions into separate posts as the day goes on and I get it all worked out…

*****installer with “lite” editor:
http://www.autoitscript.com/site/autoit/downloads/
full-featured editor:
http://www.autoitscript.com/site/autoit-script-editor/downloads/[/quote]

Since I have not learned about menu item selection I will use keyboard shortcuts:
I set Record as <ALT + CTRL + SHIFT + R> and Stop as <ALT + CTRL + SHIFT + S>
You may use your preferred shortcuts and modify the
Send(“!^+r”) & Send("!^+s)
lines as needed. In the “Record” script you will also need to modify the path to Audacity line:
Run(“D:audioAudacitySVNwinUnicode ReleaseAudacity.exe”)
to match your install location.



Here is the “record” script in AutoIt:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile_x64=getStJI.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.6.1
 Author:         edgar5

 Script Function: open Audacity, start recording


#ce ----------------------------------------------------------------------------

; Script Start
Run("D:audioAudacitySVNwinUnicode ReleaseAudacity.exe")
WinWaitActive("Audacity")
; WinMenuSelectItem("", "", "Transport", "Record")
;since I have not learned about menu item selection I will use keyboard shortcuts
;I set Record as <ALT + CTRL + SHIFT + R>
;and Stop as <ALT + CTRL + SHIFT + S>
Send("!^+r")
; note the exclamation point (!) means ALT, the carat (^) means CTRL and the plus sign (+) means SHIFT

here is the script to stop recording:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile_x64=getStJI.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.6.1
 Author:         edgar5

 Script Function: stop recording in Audacity


#ce ----------------------------------------------------------------------------

; Script Start
WinActivate ("Audacity")
;SendKeepActive("Audacity");you might need this is other windows are being activated at the same time
Send("!^+s")
; note the exclamation point (!) means ALT, the carat (^) means CTRL and the plus sign (+) means SHIFT

I just tested these two scripts with Win7’s Task Scheduler and it worked just fine. Remember, you must have set Audacity’s Audio Host, Input Device & number of channels to the proper values before executing the script (these are all “sticky” and will start with the last known values).

Maybe my system is different but I had to make a minor change in each script.
To start the recording it became: Send (“!^+rr”);
and to stop: Send(!rs");

Looks like it going to work for me.
Now I can start looking at the rest of the menus to see what is good to find (-:
Thanks,…

The exact strings will depend on your settings. Let us know how you get on with this!

It has been tested, I can click on the two files to start it then stop it.
I have set the scheduled already, I will know for sure tomorrow morning…

I created a few scripts using various keyboard sequences from your posts. (StartRec.AU3, StopRec.AU3,and then modified StopRec.AU3 to get Pause.AU3, and Append.Au3) As Icons, I can click on them and they all work as expected.

It is when I activate them from the Task Scheduler is when they seem to fail. It looks like the instance of Audacity created by the StartRec.AU3 loses focus and when the key pattern is from StartRec.AU3 sent, it does not appear to be sent to the instance of Audacity. I almost think that windows received the commands and probably tries to execute them elsewhere. Is there a way to remind the script to send the code to Audacity. (Send (“!^+rr”). Maybe there needs to be a pause between the instantiation and the send. Maybe, to coin a phrase, Id “WinWaitActive” is in question, how about WinKeepFocusActive (“Audacity”)? or how about SendAfter5SecondsToAudacity (“!^+rr”)?

One why I can see this is the top bar in Audacity loses its blue color. If I click on the window, it gets the color back and Audacity immediately starts recording.
I am continuing my exploration but would appreciate insights…

Simplified Update: I set up two scripts, almost exactly as what is posted above except I changed the paths. On schedule, the Start script gets Audacity open and recording. The Stop script sets up a new instance of Audacity. The original instance continues to record. How do I get the stop script to send the instruction to the original Audacity instance?

When I run these from Icons on the desktop, they work as designed…

If the Stop script is opening a second Project or only one Project (from Start) is open but never get focus during Stop, have a look at these lines in Stop:
WinActivate (“Audacity”)
;SendKeepActive(“Audacity”);you might need this is other windows are being activated at the same time

The first line relies on the Project window from Start being named “Audacity” (no quotes in title bar) :
a.png
If your title is different you will need to change the Stop script to match.

Try removing the leading semi-colon of the second line.

Timing is everything! You might need to add Wait statements (WinWaitActive, Delay() Amount of time to pause (in milliseconds)) but make them short.

Excellent. I ended up placing that line in both Start and Stop. Before i posted my previous comment, I had enabled it in the Stop but among other situations, I ended up disabling it. Now it is enabled in both and the set up seems to be working.

Once again, I will set up a real-time test and see what happens…

I guess this would not behave very well if I had an Audacity session already open as a project.
This remains to be another test some time in the future…

I accidentally tested this before the original posting…The Start script will work fine–a new Project will open and start recording. The Stop script is nebulous–it depends upon the title of the “Audacity session already open”–if it is the default “Audacity” there will be a name collision for the script and it is anyone’s guess which window might “activate”–maybe either or both of:
WinActivate (“Audacity”)
SendKeepActive(“Audacity”)
will fail and the script do whatever the failure mode is.

I have a cohort that is also trying the same thing. His system seems to require the use of the pauses although I have not even tried them. I sent him an e-mail message to check to see if the Turbo switch is in or out… He send back a note telling me that he cannot find it. I am willing to bet that he looked for it… (-:

What is the name of the language being used here?
Is there a list of commands and definitions?

I would call it a proprietary Basic. All the commands and functions are in the Help file.

Is there a way to name the window that opens? I would guess that Audacity is there by default.
This way I can control more than one open window.

In short…“No”.

For some background have a look at:
http://bugzilla.audacityteam.org/show_bug.cgi?id=322
which is a bug report tangential to this.

Obviously, if you wanted to do your own compile of Audacity, it would be easy to add a new CLI switch which would control the title of the window. The logic would be complicated by conditions such as passing both an audio file to open and a Project window name–these would collide; also thought would have to be given to what happens if a new Project window were opened–without other changes it would get the generic “Audacity” as a name.

Don’t forget that while recording in one open Project you may not work in any other open Projects.

I figure the not being able “to work in other projects” meant Audacity projects. That is one of the reasons I would have liked to be able to name the instance.

Here is a bizarre one: In situations where I had made mistakes sending information to Audacity, the recording did not start or stop depending on what I planned to do. As a result, I guess the commands went elsewhere. It made the system do strange things, mostly keyboard. I no longer had F-key or letter control but numbers and numlock/CapsLock worked. When I left clicked on an icon, it presented the properties screen. I could right click and hit Play to get the Icon to work. I had to reset the computer to gain control again. The only time this happens is when my TaskScheduler/Audacity programming failed. When the scheduled event worked, no keyboard problems… Problem seemed to happen when Audacity did not have focus.

Audacity only allows a single instance of itself to be run at a time. That instance may have multiple Projects (note the capital P)–about 32 on Windows and 90-100 on Mac and Linux; regardless only one Project may be “working” at any given time thus you may not record in one Project and edit at the same time in another–no background recording.

Bizarre but not too unexpected. You cannot imagine the horrible messes I have made with simple programming errors!

I recall them from my MASM course,…