How to create single-click/-keystroke shortcut to start recording on Mac OS?

I want to record landline calls at my desk with one-click or similar. For example, say I get a work call that I want to record, I just hit one key on my Microsoft Natural Ergonomic 4000 keyboard or one button on my multi-button Logitech mouse and the Mac (Mac Mini running El Cap/OS 10.11) just starts recording. No steps, just one button or keystroke, regardless of what application is open or running.

I currently have a landline phone recorder adapter, which outputs a standard 3.5mm jack. I have an Olympus digital recorder, which works fine. But I want to remove the Olympus from the system and just record directly to my Mac's hard drive using something like Quicktime to record the audio calls. Now I have plugged the adapter's 3.5mm output into the Line In input on the back of my Mac Mini. It records in Quicktime and Audacity fine, but I want it to open either audio app and start recording with one-click, etc.

How do I do that? Keyboard Maestro the best way? Anything cheaper or free? Thanks.


I wrote two scripts for you to do this in QuickTime Player:

Script to start recording:

tell application "QuickTime Player"
    activate
    start (new audio recording)
end tell

Script to end recording:

Edit (21/12/2018): this script uses UI scripting, which is not recommended, but seems the best option for now. If you have a better solution, that addresses the issues that are stated in the comments, please edit this answer.

tell application "QuickTime Player"
    activate
end tell

tell application "System Events"
    tell process "QuickTime Player"
        tell window 1
            click (first button where its accessibility description = "stop recording")
        end tell
        click menu item "Save…" of menu "File" of menu bar 1
    end tell
end tell

After the second script a dialog will open, which asks you to enter a file name and save location.

To make this work, you have to copy both scripts and paste them into two separate files in Script Editor (default installed on your Mac). Save the files and follow this guide to assign shortcuts to them.

Update 21/12/2018: I updated the start script with user3439894's suggestion. I kept the stop script the same, because his stop script suggestion doesn't seem to work. (A window with 'Finishing Recording' appears, but keeps loading)