Call x-callback-url from OmniJS?


#1

Hi, I’d like to use OmniJS to invoke an x-call-back-url action in DEVONThink To Go, however it seems that URL.call() is only designed to call OmniJS actions in other Omni-JS-enabled application.

Is there a way to call x-callback-urls using OmniJS?

Kind regards, Sven.d


#2

It’s not immediately clear to me whether it is documented at all, but @kcase shared this on Twitter last night:

Not even sure that I fully understand how this would be used to return values created at run-time in the omniJS JSContext.


#3

OK, got it – I was being slow. It does return an evaluation of the text interpreted as JS code.

This for example, returns a list of names bound in the global namespace:


#4

After some experimenting, it seems as if OmniJS‘s URL.call function supports calling x-callback-urls, however it seems that the function passed as a callback doesn‘t get called.

For example, the following code activates DEVONtink To Go, which calls back to OmniOutliner. However, the callback never gets executed…

var scriptURL = URL.fromString('x-devonthink://x-callback-url/get-itemlink')
scriptURL.call(function(r){console.log('a')})

#5

Where, out of interest, are you hoping to see the console.log string ?


#6

In OmniOutliner 3/iOS, I ran the Script directly from its console.


#7

If I run this code in OmniOutliner iOS console,

(() => {
	'use strict';
	const 
		strURL = 'workflow://run-workflow?name=test&input=23';

	return URL.fromString(strURL).call(x =>
		console.log(x.toString())
	)
})();

It opens workflow app, and I get this output.

Collage_Fotor copy

I can successfully pass a number from OmniOutliner to Workflow and output it through OmniOutliner console. I cannot do the same with a string. I wonder why is that.


#8

Interestingly, when I omit the x-callback-url part from my URL.fromString('x-devonthink://x-callback-url/get-itemlink') example, DEVONthink complains that this actions can only be used via x-callback-url and aborts the action. However, in your example it seems as if the x-callback-url part gets added automatically.


#9

That’s due to a design oversight. We’ll fix it.


#10

Just a followup: this was fixed in OmniOutliner 5.3 for Mac and OmniOutliner 3.1 for iOS. It’s now possible to use URL.call() with x-callback-url URLs that return arbitrary content (rather than only working for URLs that returned JSON).


#11

It works now. Thanks for the follow-up !

Could you give an example of that ?


#12

I’m not sure if there has been a regression, but I’m getting the symptoms that was mentioned above when trying to call urls from omnioutliner pro. Whether I try to fetch or call a URL (bear:// in this case) the callbacks never fire and bear is never notified.

I can confirm that the URL is valid because if I console.log it and then load it in chrome, it all works as expected.