AHK Script for Audacity help Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Crono1124
Posts: 2
Joined: 16 May 2022, 21:15

AHK Script for Audacity help

Post by Crono1124 » 16 May 2022, 21:27

Hello all,

I am trying to get the program Audacity to work with my hot key script below.
Currently the program Audacity uses the following key presses of p & f to pause the music or skip 15 seconds backwards respectively while still playing the song. The code below works when I press 4 on my keyboard to pause and play the music. However whenever I press 2, nothing happens.

Code: Select all

~2::
ControlSend,,f,ahk_class wxWindowNR ; Skip back 15 seconds
return

~4::
ControlSend,,p,ahk_class wxWindowNR ; Play or pause
return
If i have the window not minimized and active then press f in audacity, the music skips backwards. Any ideas?
I am using ControlSend because i need the commands to work on a minimized window but is there a better way to do this?
Also the default key press to skip backwards is "," or "<" for 15 seconds. i simply remapped this key to avoid confusing scripts with `,

User avatar
mikeyww
Posts: 26857
Joined: 09 Sep 2014, 18:38

Re: AHK Script for Audacity help

Post by mikeyww » 16 May 2022, 22:38

I tried but without luck. Since it looks like you just want to play music, you could use a more responsive player.

AHK_user
Posts: 515
Joined: 04 Dec 2015, 14:52
Location: Belgium

Re: AHK Script for Audacity help

Post by AHK_user » 16 May 2022, 23:07

I have automated some actions in the past in Audacity without any problems.

WinMenuSelectItem seemed to work good in comibination with ControlSent and ControlClick, I used "ahk_exe audacity.exe" to target the window.

Here is the script, but it was written for the dutch language, so you will need to rewrite it.

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#SingleInstance, Force

File := "C:\Users\test\Documents\PJVP\Oefenbestanden\OK - Perhaps Love\TENOR_PERHAPS LOVE.mp3"
File_New := StrReplace(File, ".mp3", "_91.mp3")
; Convert mp3 to slower speed
Controlsend, , ^o, ahk_exe audacity.exe

WinWait,  Selecteer een of meerdere bestanden ahk_exe audacity.exe
ControlSetText, Edit1, %File%, Selecteer een of meerdere bestanden ahk_exe audacity.exe
Controlsend, Edit1, {enter}, Selecteer een of meerdere bestanden ahk_exe audacity.exe
WinWait, Importeren ahk_exe audacity.exe
WinwaitClose, Importeren ahk_exe audacity.exe
sleep, 500

Controlsend, , ^a, ahk_exe audacity.exe
WinMenuSelectItem, ahk_exe audacity.exe, , Effecten, Tempo Wijzigen...
WinWait, Tempo wijzigen
ControlSetText, Edit1, -9, Tempo wijzigen
ControlClick, Button8, Tempo wijzigen
WinWait, Hoge kwaliteit tempowijziging
WinWaitClose, Hoge kwaliteit tempowijziging

WinMenuSelectItem, ahk_exe audacity.exe, , Bestand, Exporteren, Exporteren als MP3
WinWait, Audio exporteren ahk_exe audacity.exe
ControlSetText, Edit1, %File_New%, Audio exporteren ahk_exe audacity.exe
Controlsend, Edit1, {enter}, Audio exporteren ahk_exe audacity.exe

Winwait, Metadata-tags bewerken ahk_exe audacity.exe
ControlClick, Button12, Metadata-tags bewerken ahk_exe audacity.exe
WinwaitClose, Metadata-tags bewerken ahk_exe audacity.exe
SplitPath, File_New, , , , OutNameNoExt
WinWait, %OutNameNoExt% ahk_exe audacity.exe
WinWaitClose, %OutNameNoExt% ahk_exe audacity.exe
sleep, 500
Controlsend, , ^w, ahk_exe audacity.exe

Winwait, Wijzigingen oplaan in ahk_exe audacity.exe
ControlClick, Button2, Wijzigingen oplaan in ahk_exe audacity.exe

Crono1124
Posts: 2
Joined: 16 May 2022, 21:15

Re: AHK Script for Audacity help  Topic is solved

Post by Crono1124 » 16 May 2022, 23:11

Although It was not how i originally intended for it to work, the below script switches the windows briefly to execute a command.
It seems the function ControlSend did not have the ability to manipute a screen function without a button.

Code: Select all

~2::
WinGetTitle, Title, A
WinActivate, ahk_exe Audacity.exe
winwaitactive, ahk_exe Audacity.exe
Send <
;Sleep 200 ;not needed
WinActivate, %Title%
return
From the looks of it this is similar to what Ahk_user recommended?

Either way, thank you everybody for helping.

Post Reply

Return to “Ask for Help (v1)”