0

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

-1

Separated the two applications into two separate dictation commands using applescript in automator. The latter controls the Youtube video on the tab Chrome last interacted with, which is essentially perfect.

on is_running(appName)
    tell application "System Events" to (name of processes) contains appName
end is_running

if is_running("iTunes") then
    tell application "iTunes"
        playpause
    end tell
else if is_running("Spotify") then
    tell application "Spotify"
        playpause
    end tell
end if
to clickClassName(theClassName, elementnum)
    tell application "Google Chrome" to (tabs of window 1 whose URL contains "youtube")
    set youtubeTabs to item 1 of the result
    tell application "Google Chrome"
        execute youtubeTabs javascript "document.getElementsByClassName('" & theClassName & "')[" & elementnum & "].click();"
    end tell
end clickClassName    

clickClassName("ytp-play-button ytp-button", 0)

--clickClassName("ytp-prev-button ytp-button", 0)
--clickClassName("ytp-next-button ytp-button", 0)

-1

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

1
  • Why would people downvote a well-intentioned answer? At least state a reason. The truth is this site is full of entitled @$$#0!&$, trying to prove how they are smarter than everybody else. Even if you ask the wrong question they will bash you around because you didn't know how to search for it elsewhere. – Mateus Ribeiro Feb 1 '20 at 2:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .