Tutorial: chaining Drafts URL scheme to build smart dictation URLs πŸ’¬

Goal

For this case, I was interested in building a quick dictation tool that would open already set in my target language (:fr: or :uk:), capture and copy the output to paste in another app. I used to rely on the dictation key in macOS but hated the extra step of selecting the language in the dropdown list.

I figured I’d cobble something with Drafts since I loved the education experience there and it had loads of scripting capabilities.
My goal would be to add quick dication buttons to my stream deck keys.

Here is my documented take on building this simple automation. Maybe that will be helpful to other folks looking at x-callbacks, Drafts URL scheme and other.

Reasoning

The Drafts app has a very powerful URL scheme that can be used for automation.
It integrates with x-callback-url meaning that upon running an action from the url scheme, you can pass its result to another URL scheme.

The only thing is, while I did use URL-schemes, I never chain two using x-callback before which is why I documented my thinking which I am publishing here.

I surmised it should be possible to do something like:

  1. Use /dictate url scheme action
  2. Chain in another URL using x-success
  3. Use /runAction url scheme action

So, looking closer at the two url scheme actions:

  • The /dictate Drafts URL scheme action takes 3 arguments but I only need these 2
    • locale (ie: en-UK, fr-FR)
    • save (boolean) - if set to false, the dictation will be returned to the callback only - I’d rather not populate my Drafts with all my text entries.
  • The /runAction Drafts URL scheme action takes 3 arguments by I only need to be aware of 2
    • text - the action input - I don’t actually need to append this one, it’s done automatically after running the first step!
    • action - the action name - I want to use β€œCopy”

Chaining Drafts URL scheme automations 2022-05-19 10.19.17.excalidraw|

Wrapping up
So, putting it together, my URL would look like:
drafts://x-callback-url/dictate?locale=fr-FR&save=false&x-success=drafts%3A//x-callback-url/runAction?action%3DCopy

:white_check_mark: Which runs perfectly fine! :white_check_mark:

Here are my two language variants for French and American English

  • French dictation and copy
drafts://x-callback-url/dictate?locale=fr-FR&save=false&x-success=drafts%3A//x-callback-url/runAction?action%3DCopy
  • UK English dictation and copy
drafts://x-callback-url/dictate?locale=en-UK&save=false&x-success=drafts%3A//x-callback-url/runAction?action%3DCopy

Let me know if that was helpful / can be improved / etc! :smiley:

4 Likes

Looks like a great idea. The two links at the bottom of your post, @MarcMagn1. do not seem to be working links.

Katie

You’re right, I exported directly from Obsidians and used the links there to test.

I just changed the original post to show the URL in snippet format, it should be better now.

1 Like