Scripting Noise Removal

Audacity v1.3.13-beta, Mac OS X v10.6.8

Audacity’s noise filter is basic, but reasonably effective. It is applied in two stages, (a) get noise profile, and (b) remove noise.

http://wiki.audacityteam.org/index.php?title=Noise_Removal

I find that there are two issues with applying it. First, Audacity doesn’t have keyboard shortcuts for effects (filters), other than cmd-R (repeat last effect), which is anyway valid only for the current doc. (Maybe it does, but I missed them?)

Second, I find its application somewhat counterintuitive. Thus, say I call the effect and define a noise profile; and then, I press cmd-R. This should mean, repeat “the last applied effect using the same option and without displaying the dialog”, ie, re-define the noise profile. But instead, Audacity applies the noise removal as set. IOW, invoking cmd-R doesn’t repeat stage (a), but applies stage (b).

Audacity doesn’t support AppleScript; but it is possible to script it with GUI scripting. And it turns out that it is quite easy to use GUI scripting to manipulate the Noise Removal effect.

(To use GUI scripting, it has to be enabled in System Prefs. Check Help on how to enable it and how to start UI scripting.

Try these articles
http://www.macosxautomation.com/applescript/uiscripting/
http://www.mactech.com/articles/mactech/Vol.21/21.06/UserInterfaceScripting/index.html

which are still valid and give a more detailed intro to the topic.

**Note:**In Mountain Lion, the System Preference to look for is called “Accessibility”.

You should also enable your Scripts menu (AppleScript Editor prefs). This will give you access to scripts supplied with the OS and to any scripts you place in <~/Library/Scripts>. Moreover, if you create inside the latter folder a folder called “Applications” and, inside it, one called “Audacity”, scripts placed in <~/Library/Scripts/Applications/Audacity> will appear in the Script menu only when Audacity is frontmost.)

Below are two AppleScript scripts. Copy each to a blank AppleScript Editor doc and save in <~/Library/Scripts/Applications/Audacity> as plain scripts. I called them “Noise - Get Profile.scpt” and “Noise - Remove.scpt”. Use a keyboard shortcuts manager (I prefer Spark http://www.shadowlab.org/Software/spark.php) to assign them shortcuts. Then, in Audacity, select some noise, invoke the first shortcut, then select all the sound to be processed, and invoke the second shortcut. (Of course, instead of invoking the second shortcut, you could just use Audacity’s cmd-R.)

Please note I’ve only tested these scripts on a few docs; they should work, but there are no guarantees, and I can not support them – you’re on your own. It’s more a case of using them as examples to write your own scripts and improve your workflow when using Audacity.

Noise - Get Profile

(*
- UI scripting must be enabled
- tested only on Mac OS X v10.6.8 and Audacity v1.3.13-beta!
- use at your own risk
*)
on run
tell application "System Events"
tell process "Audacity"
set frontmost to true
try
click menu item "Noise Removal..." of menu of menu bar item "Effect" of menu bar 1
click button "Get Noise Profile" of window "Noise Removal"
end try
end tell
end tell
end run

Noise - Remove

(*
- UI scripting must be enabled
- tested only on Mac OS X v10.6.8 and Audacity v1.3.13-beta!
- assumes Noise > Remove option is selected
- use at your own risk
*)

on run
tell application "System Events"
tell process "Audacity"
set frontmost to true
try
click menu item "Noise Removal..." of menu of menu bar item "Effect" of menu bar 1
click button "OK" of window "Noise Removal"
end try
end tell
end tell
end run

Thanks for your contribution alexius.

I agree that it’s counter intuitive (and I only learned of this recently), but it is useful. It does not appear to be mentioned in the manual, so I’ve added a note here: http://manual.audacityteam.org/man/Noise_Removal#Tips

Alexius, just to clarify, no - there are no keyboard shortcuts for effects - it’s a common request. Do you want to add a vote for it?

I think your piece might be worth mentioning at “Accessing Effects with Shortcuts” on our Wiki page about “Navigating Effects”:
http://wiki.audacityteam.org/wiki/Navigating_Effects

Would you be agreeable to us adding that? If you would like to add it yourself, please send me a Private Message (PM symbol to right of this post) so I could give you a Wiki account you could log in with.

Also, it would be good to know if seeking by letter and/or Page Up/Page Down will navigate Audacity’s Effect Menu on Mac - that Wiki page has been waiting for someone to add that information.



Gale

Sure.

Please feel free to to do so.

Keep in mind that, on Mac OS X, it is possible to assign shortcuts to apps using System Preferences > Keyboard Shortcuts > Application Shortcuts. I haven’t tried it, but I don’t see why it shouldn’t work. (I don’t know how conflicts with Audacity’s own shortcuts would be resolved.) I haven’t tried it, because of the dual function of Noise Removal.

That’s easy, but keep in mind I’m using Mac OS X v10.6.8 (Snow Leopard), not Lion (the latest version).

(1) System Preferences > Keyboard Shortcuts > Keyboard & Text Input > Move focus to menu bar shortcut must be enabled.

(2) Moving focus to menubar in Audacity selects the Apple menu.

(3) Navigating the menu bar.

(a) With arrow, tab, and return

  • right arrow: moves selection to the right
  • left arrow: moves selection to the left
  • down arrow: first press reveals the menu
  • up arrow: nothing, if menu is not revealed; if menu is revealed, selects the last available choice
  • tab: same as right arrow
  • shift-tab: same as left arrow, except when the focus is on the Help menu
  • return: reveals the menu, if menu is not revealed
  • shift-return: if menu is not revealed, it reveals it; if it is revealed, it removes focus from menu bar without applying any command (same as escape).

(b) With letter keys

This is bizarre and inconsistent. First press selects the first menu bar item (in alphabetical order, irrespective of position on menu bar) whose name begins with that letter. Subsequent presses may select the next item in alphabetical order, or the previous item in alphabetical or, or may do nothing. However, other letters may also select items, seemingly at random – Y selects “Window”, Q selects “Track” – I can make neither head nor tail of it.

(Btw, this is not Audacity – other apps, including Apple’s, show exactly the same behaviour.)

(4) Navigating the menu

(a) With arrow, tab, and return

  • right arrow: reveals a sub-menu, if it exists; if there is no sub-menu, reveals and moves to the next menu on the right
  • left arrow: moves to the next menu on the left
  • down arrow: moves down through menu choices
  • up arrow: moves up through menu choices
  • tab: same as 3a
  • return: if there is a sub-menu, it reveals it; otherwise, activates the menu selection

(b) With letter keys

Similar to 3b, though somewhat less bizarre. The first press selects the first menu choice (strictly in alphabetical order) in the menu. Subsequent presses do nothing, or select a menu choice beginning with the same letter. However, pressing a letter alphabetically close may also select the item, eg, press Y to select Wahwah. The logic (if any) escapes me.

Arrow keys and tab are the only reliable means of navigating the menu bar and menus.

Thank you for these great information.

I’m trying to set an applescript but i have difficulties to find the name of the Track Pop-Down Menu (see image below-red). How could i indicate that i want to access it and split stereo track?

Thank you!

Did you read MacTech | The journal of Apple technology. ?

There is a tool available to help. It is called UI Element Inspector, and it can be downloaded from Apple’s AppleScript web site <> http://www.apple.com/applescript/uiscripting/> >.

Or call the SHIFT + M shortcut:
http://manual.audacityteam.org/man/Keyboard_Shortcut_Reference#tracks


Gale

Moved from the (now closed) 1.3.x Mac board to the 2.0.x Mac board.

Keyboard shortcuts for effects are now available in the current version of Audacity .

Thanks. The Wiki page about Effect menu navigation will be moved to the Manual for 2.0.6 release and will have a link to this topic.

I should add that in in OS X Mavericks, the method to enable UI scripting in System Preferences has changed. In Mavericks you have to go to the Accessibility section of the Security & Privacy Preferences then drag Audacity from /Applications into the list of applications in that Accessibility section.

I can’t make those application shortcuts work for Effects. But I can specify a shortcut for Audacity Record in System Preferences and it works, even if that binding is already allocated in Audacity Keyboard Preferences to another command.

Unfortunately the application shortcuts in System Preferences are not global shortcuts, so they don’t control Audacity when it does not have focus.


Gale