Automating Ulysses on macOS
I’ve started a new blog about my journey to get fit and healthy in my 40s. So far, I’ve mostly posted my daily workouts as logged on my Apple Watch and processed on Today’s Plan. Since I’ll be doing this a lot, I’ve automated the process of retrieving my latest activity using the Today’s Plan API, and then automatically creating a post in Ulysses ready to write some introductory text and publish to my blog.
I’ll revisit the topic of Today’s Plan automation in another post, and for now, I’ll concentrate on Ulysses, which has an API based on x-callback-url schemes.
All I needed to do was create a script as follows.
#!/bin/zsh
cd /Users/christopher/Developer/z5
source .venv/bin/activate
TEXT=`python getLastActivity.py`
open "ulysses://x-callback-url/new-sheet?text=${TEXT}&group=/RossersBoot/Workouts"
After the crunch bang directive, the first couple of lines are to set things up for the Python script I wrote to use the Today’s Plan API.
The output of the Python file is URL-encoded and stored in the Bash variable, TEXT. All I do then is create the x-callback-url scheme Ulysses needs to create a new sheet with the generated text, and in the group of my choosing.
Lastly, I use the open command in macOS to hand everything off to Ulysses and creates the new sheets.
This should (theoretically) be easier when I update to macOS Monterey, which includes Apple’s Shortcuts app. WIth Shortcuts, I should be able to direct Ulysses callbacks back to the Shortcut, allowing me to edit the newly created sheet with things like tags and notes before I open the app. But for now, at least, the script is working very well.