I have created a swift application and I would like to build a direct export out of my application into DT. In other words I want to build native support for DT in my application.
For now I only do this on MacOS.
When I check the URL commands help I can see that I need to use the createHTML
command. Before I can start using this I want to make certain I have the basics right, so I start with the example of the help:
x-devonthink://createRTF?title=New%20bookmark&location=http%3A%2F%2Fwww.devontechnologies.com&noselector=1
If I go into my browser it works. When I put this command in the URL bar, the command is executed and the document is created. This works both in Safari
and Waterfox
.
I don’t want to use a browser as intermediary. I want to call DT directly. So I tried the following command from the command line (terminal):
curl 'x-devonthink://createRTF?title=New%20bookmark&location=http%3A%2F%2Fwww.devontechnologies.com&noselector=1'
This fails with the message: curl: (1) Protocol “x-devonthink” not supported or disabled in libcurl
I also tried curl
from brew
with similar results.
I then finally tried this from Swift
which is my ultimate goal:
let url = URL(string: "x-devonthink://createRTF?title=New%20bookmark&location=http%3A%2F%2Fwww.devontechnologies.com&noselector=1")!
let task = URLSession.shared.dataTask(with: url) { (data, response, error) in
if let error {
print("Error: \(error)")
return
}
guard let data = data else { return }
print(String(data: data, encoding: .utf8)!)
}
I get this error:
Error: Error Domain=NSURLErrorDomain Code=-1002 "unsupported URL"
Note that I left the UserInfo
part of the error out for brevity.
When I read other posts about this the seem to mention that I need to add x-devonthink
to the Queried URL Schemes
in the Info.plist
of my applicaiton. Just to be certain I have done this but it does not seem to have any effect.
So does someone know how I can call this command directly without using a browser as intermediate?