To use this in Alfred create a new workflow and then create a new action Run NSAppleScript
and paste in the below script.
Note: If you want to run this on the CLI you can remove the on alfred_script(q)
and end alfred_script
and add #!/usr/bin/env osascript
as the first line to run it from the CLI.
See http://sanitarium.se/blog/2024/04/15/day-to-day-automation-using-alfred/#spotify-controller for more context.
There are a couple of different things going on in the pipeline to open the browser:
sed -E 's|([ ]+)|-|g'
- Replace spaces with
-
- Replace spaces with
iconv -f 'utf-8' -t 'ASCII//TRANSLIT'
- Convert any non-ASCII characters to their most direct ASCII counterpart. For example,
Björn
becomesBjorn
and not the localizedBjoern
- Convert any non-ASCII characters to their most direct ASCII counterpart. For example,
sed -E 's|[^a-zA-Z0-9-]||g'
- Remove any characters not matching that regex.
[^]
means anything not in this group
- Remove any characters not matching that regex.