Trying to set a F8 pause/play dictation command

automatorkeyboardvoice-dictation

So I'm what one would describe as ridiculously disabled. I've recently taken a liking to using the dictation functionality due to only having the use of one hand and often having to lie on my back.

I'd like to add the F8 play/pause key to the list of dictation commands, but unfortunately the dictation custom commands don't take single keypresses. It seems the solution is to create a workflow. However, upon trying automator to record the keypress I seem to have discovered that it doesn't recognise that key for some reason.

Just as a note, I use this play/pause functionality for iTunes AND Chrome Youtube videos at the same time. For example, I'll start iTunes playing, then start the Youtube video. Since the Youtube video was the last to be interacted with the play/pause affects Youtube, and not iTunes. That functionality I would like to keep if possible. So I guess if you can't just do a simple keypress it'd need to check if Youtube or iTunes is the current/last interacted with active app and act accordingly.

Does anyone have a possible solution or workaround they can think of?

Thank-you

Best Answer

What you probably need is to insert the right key code command using an AppleScript action in your workflow.

In this case it's 100.

on run
    tell application "System Events"
        key code 100
    end tell
end run

In this article you can learn more about it: https://eastmanreference.com/complete-list-of-applescript-key-codes. You will find this table:

enter image description here

Remember to check your keyboard settings.

enter image description here

If the Fn key is enabled for F1, F2 etc. keys, you will have to adapt your code like this:

on run
    tell application "System Events"
        key code {63,100}
    end tell
end run

Also remember that you must allow the apps on your Security & Privacy settings for Accessibility, or else the program will not be able to control your computer.

enter image description here