How to pass a URL containing parameters through x-callback-url?

I’m working on an Alfred workflow for adding entries to a note, with a link previously stored in the clipboard. (It’s part of a project for implementing Daily Log routines in the Agenda).

It works when the URL doesn’t contain any parameters but breaks because ?s and &s are not correctly treated.

This is how I am preparing the text to pass to the callback-url:

PROTOCOL=`echo -n $CLIP | cut -d: -f 1`
URL=`echo -n $CLIP | cut -d: -f 2`
URL=`/usr/bin/python -c "import urllib; print urllib.quote(\"${URL}\")"`

echo -n "[${query}](${LINK})"

In a later stage, this output will be stored in the TEXT variable, and the callback is called with open:

open "agenda://x-callback-url/append-to-note?title=${TITLE}&text=${TEXT}"

Any ideas?

The quotes seem wrong, especially line 4, and the last term looks off (“echo …”).

This echo is simply the way to pass data inside an Alfred workflow. That part is working fine, the real issue is how to invoke the open command.

Having this in the clipboard, for example:


This is how the open command is being issued:

open "agenda://x-callback-url/append-to-note?project-title=Journal&title=13 Jul | Sáb&text=- [ ] [test](airmail://

The note is successfully appended in the Agenda, but the link is broken.

In other words, the question is how should &s and ?s be encoded in the value of a text parameter for the x-callback-url call.

I also tried substituting just those characters (sed -e 's/&/%26/g; s/\?/%3F/g' instead of the url encode via python), but the following doesn’t work either:

open "agenda://x-callback-url/append-to-note?title=13 Jul | Sáb&text=- [ ] [test again](airmail://"

Maybe Python & urllib.encode() ?

You definitely have to escape your URL, for example spaces should be converted to %20 etc. Accented characters are officially also not part of the URL spec.

The ampersands that separate parameters should not be encoded of course, but all values for those parameters should be.