macOS service to queue from browser w/Automator & AppleScript

Background: Hey all, I’m playing with what’s possible to control from macOS and/or from browsers. I’m pretty close to having OS-wide shortcuts to increase/decrease the volume of the currently-selected output (without having to manually give focus to Roon first), using AppleScript’s keystroke and key code functions and macOS’s ability to assign arbitrary shortcuts to Automator/AppleScript scripts (https://eastmanreference.com/how-to-automate-your-keyboard-in-mac-os-x-with-applescript).

The question: That works because Roon has a way to perform the task with keyboard shortcuts. The workflow I’m trying to get working, and wondering whether anyone has ideas about, is highlighting a song name in a browser (or any other app), then use the macOS “Services” menu (http://www.atpm.com/16.01/services.shtml) to run an Automator/AppleScript service that searches for the track and queues the first track result. Imagine the local version of a bookmarklet and you get the idea.

Exposing a service that receives the highlighted text is easy (https://www.google.com/search?q=highlight+text+service+automator). The AppleScript should be able to put focus in Roon’s search box with Command-F, then input the highlighted text and “press” enter. The challenge is that I can’t come up with a set of app menu clicks, keyboard shortcuts, or command-line arguments that will play or even navigate a set of results.

Things I’ve considered: Some typical options that don’t seem to help here:

  • AppleScript can navigate an app’s dropdown menus (https://lifehacker.com/5749811/turn-any-action-into-a-keyboard-shortcut-on-your-mac and find in page for “click menu item”), but Roon doesn’t have menu items for performing common actions
  • Even if I could somehow get a consistent result set, there doesn’t seem to be a way to cycle the focus through successive clickable links with the keyboard (like tab does in a browser). In Roon, tab shows/hides the sidebar.
  • There’s no CLI argument to perform a search or play, and it doesn’t really fit this situation anyway
  • AppleScript can invoke JavaScript and manipulate a DOM, but that doesn’t apply to a Mono app like Roon

I also considered trying to generate a click on an arbitrary x,y coordinates. However, AppleScript makes it difficult to click a position relative to the corner of an app’s window (rather than the corner of the display) and apps like cliclick seem to have the same restriction. Even if an app could click x,y within Roon, with no other way to navigate elements, I’m not sure I could come up with a consistent place to click.

I’m far from an expert about what’s possible with Automator, so I figured I’d see whether anyone can think of a way to navigate search results and click play (or ideally, Play Actions -> Add Next) that I haven’t considered. Searching Discourse didn’t turn up any relevant posts.

Worst case, it’ll be on the Roon team’s radar. Here’s an example page where I’d love to use this: http://kutx.org/playlist. I manually searched for many of these song+artist names exactly as shown in the page and in 100% of cases, the first track result (from Tidal) was the song in question. In over 90% of cases, just the song name yielded the correct song. On many other pages, I come across a few song names or a band name that I haven’t heard. Today I copy and paste manually (or I don’t because it’s distracting), but if I could highlight and right-click Services -> Queue next in Roon, I’d play a lot more. Spotify and Tidal get pretty close to this with a bookmarklet (though only with the Web player); I still need to click play, but it saves the copy/paste/search.