Jump to content
kerim

Escape ASCII for URL

Recommended Posts

I'm writing a workflow that uses Bear's x-callback-url scheme. I got it to work, but I keep running into problems when my text contains certain ASCII. For instance, I have to write %23 instead of # or it won't work. Is there some way to automate this, so that the final output is properly escaped? I searched but couldn't find anything. Thanks!

Share this post


Link to post

We can’t properly help you without access to your Workflow.


Debugging can already be hard with access to the code, and you’re asking us to guess yours from a description. There are multiple places where you code or Workflow setup may be going wrong. There are multiple ways to url encode a string, but we don’t even know what language you’re using. Without looking at it we’re shooting in the dark, which is a waste of time for everyone involved (including you).


Read the Reporting Problems with Workflows topic, as it gives a nice overview on how to build an effective report.

Share this post


Link to post
3 hours ago, kerim said:

I'm writing a workflow that uses Bear's x-callback-url scheme. I got it to work, but I keep running into problems when my text contains certain ASCII. For instance, I have to write %23 instead of # or it won't work. Is there some way to automate this, so that the final output is properly escaped? I searched but couldn't find anything. Thanks!

 

You need to URL-encode anything you stick in a URL. If you're using a real programming language, it almost certainly has a function to do that.

 

If you want more actionable help, please follow @vitor's advice.

Share this post


Link to post

Thank you everyone for the quick responses. Here's a link to the workflow. But the reason I didn't share it is that I'm not a programmer and I've just created this by merging two scripts I found that were written by other people. I would rather just know the best practice for doing this rather than trying to fix this code, as I've probably made things much more complicated than they need to be if you actually know what you are doing. I just need to take the output of some text and URL-encode it before passing it on to the URL. I am happy to use examples from any "real programming language" if anyone has any suggestions for a simple way to do this. Thanks!

Share this post


Link to post

Here's a fixed version.

 

I've ripped out all the PHP stuff. That was completely broken, as it was a Script Filter script designed to show results in Alfred. It would not work the way you want.

 

I've left in the normalise command, though I'm not sure it's necessary.

 

What I added was a single Run Script action to URL-encode the input.

Edited by deanishe
Fix link

Share this post


Link to post
1 hour ago, kerim said:

the reason I didn't share it is that I'm not a programmer and I've just created this by merging two scripts I found that were written by other people

 

TBH, that's more of a reason to share. It's more likely there'll be other issues.

 

As noted, you were using the wrong kind of script. No amount of URL-encoding could have made that workflow work because the script you'd repurposed wrapped the encoded text in XML.

Share this post


Link to post

Thanks so much! Unfortunately there is something weird about the link you posted, while my mouse turns to a pointer over all the other links, somehow that one isn't registering as a link for me, so I can't download the file. :(

Share this post


Link to post

Thanks so much @deanishe! I got it working. As you say, the normalise command does not seem to matter. One strange thing that someone might want to look into is that it did not work if it was set to "Chrome" but did work if it was set to Safari, or set to the "default browser" - even if the default browser is Chrome!

Share this post


Link to post
1 hour ago, kerim said:

One strange thing

 

It's not strange at all. Why would you expect Chrome (or any web browser) to be able to open a bear:// URL? It's entirely meaningless to any application except Bear.

 

You should use "default browser" and nothing else. The system will look which application is registered for the bear:// scheme and pass the URL to that application. Not to a web browser. They're for http(s):// URLs.

Share this post


Link to post

" Why would you expect Chrome (or any web browser) to be able to open a bear:// URL? It's entirely meaningless to any application except Bear."

 

You seem to think it laughable that someone would not understand the difference between "the default browser" and the actual default browser. I really appreciate all the time you've taken to help me out, but I don't consider this laughable or obvious at all.

Share this post


Link to post
1 hour ago, kerim said:

You seem to think it laughable that someone would not understand the difference between "the default browser" and the actual default browser.

 

Hardly.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...