How to make x-callback-url call to local app in Ruby?

368 Views Asked by At

I have a local app (NotePlan) installed on macOS, and it publishes an x-callback-url scheme. I'm simply trying to call it from a ruby script, but can't find help on this. (Plenty of help available for HTTP calls, but this is to a local app.)

require 'open-uri'
title = "note title"
uri = "noteplan://x-callback-url/openNote?noteTitle=#{title}"
uriEncoded = URI.escape(uri)
response = open(uriEncoded).read

It returns this error:

No such file or directory @ rb_sysopen - noteplan://x-callback-url/openNote?noteTitle=note%20title (Errno::ENOENT)

From the command line calling open "noteplan://x-callback-url/openNote?noteTitle=note%20title" does the expected thing, so the basic mechanism appears to work.

1

There are 1 best solutions below

0
JGC On

Well, I've found a way, though I regard it a hack, not a good answer.

response = %x[open "#{uri}"]

i.e. call the open command in a new shell.

I still hope someone can provide a better answer.