For the app in the foreground, it’s really easy: System Settings – Keyboard – Keyboard Shortcuts – App Shortcuts – add shortcut for Voice Memos – Play/Pause Recording – F8
For app running in the background, you need a QuickAction and it would be easier if you define it for just one app, let’s say TextEdit (it could be Microsoft Word or another app):
- Automator – New QuickAction – Workflow receives - no input – in TextEdit- add Run AppleScript:
AppleScript:
tell application "VoiceMemos" to activate
tell application "System Events" to keystroke {space}
tell application "TextEdit" to activate
Save the QuickAction as PlayPauseVoiceMemos and go into System Settings – Keyboard – Keyboard Shortcuts – Services – General and add F8 as the shortcut for PlayPauseVoiceMemos.
Now, when you are in TextEdit (or your chosen app), press F8 and you will have to grant TextEdit permission to control System Events. After the permission is granted, pressing F8 in TextEdit will briefly bring VoiceMemos to the foreground, press space (Play/Pause), then bring TextEdit to the foreground again.