URL Commands? Desktop Shortcuts support?

Hello. I thought I would spend 15 minutes this evening automating a simple repetitive action that I take and reduce it to a couple of clicks.

My first surprise was that DT doesn’t seem to support Shortcuts on desktop. A little surprising, but forgivable. I can work around that. Surely it’s just a matter of constructing a couple of quick URLs.

It seems like it should have been this simple:

Except I hadn’t included a location or a content, because all I wanted was a blank note in the folder/group that I use 90% of the time at work, in the format that I use 95% of the time. It should have been as simple as tap, press enter, type a title, press Cmd+Enter, start typing the notes.

The first part that failed was apparently you can’t use the URL commands without a location parameter. The PDF manual for version 3.9.7 doesn’t mention this limitation at all. Instead the URL opens DT, makes a little bop noise, and does…nothing.

I wouldn’t have thought to add a location parameter until I found this thread from mid-2017 that mentions that the URL command requires a location parameter, and that the next release would improve this. That doesn’t appear to have come to fruition, seems like? (Edit after submitting, forgot the URL, but apparently I can’t use URLs here either, even to another message on the same forum, so maybe you can find it with the ID 22173, but I don’t know if that’s unique to the post or not.)

Can I suggest making this limitation more clear in the documentation, if that is in fact the case and I’m not missing something?

And can anyone point me in the right direction for how to accomplish what I’m looking to do? As one of three people in the world who liked the idea of the touchbar, I thought it would be a simple matter to rig up a touchbar button to a Shortcut, which popped up a simple menu that used a few URL shortcuts to eliminate friction in my day.

Edit: New members can only use one picture apparently, so pretend this is a screenshot of a touchbar with a purple “New Note” button on it.

All I wanted was a simple way to automatically create a new note for the project I’m working on at work. Is the answer here that I need to learn AppleScript in 2024, having managed to avoid it up until now?

Edit: Apparently new users can only upload one screenshot, so pretend this is a screenshot of a pile of notes in the format of “2024-07-14 Topic Name, 2024-07-15 Topic Name.”

I’m sorry if this comes across in a negative way. I’m frustrated from having spent a LOT more time than expected on something that was supposed to be less than an hour, and not even having a satisfactory solution yet. I’ve tried to filter that out of my post. My hope is that I’m misunderstanding something here. And get seeming unexplained behavior documented if I did actually understand why the URL scheme didn’t perform as initially expected.

Thank you for your time.

Welcome @GreySim

Quick answer as it’s 4:25am and I’m not at my Mac (logically): AppleScript is not something to be avoided and Shortcuts is a poor substitute for it. Our Automation section on these fora is full of people who got started with AS because of DEVONthink and there’s no one I know that regretted it. I would say avoiding it has been a limiting factor, if you have a need for robust automation.

Also, URL commands are also very limited in functionality versus a script.

And lastly, you should look at Data > New from Template and the Smart Templates section of the Automation chapter of the built-in Help and manual.

I will return to this once I’m fully awake and coherent. :sleeping:

3 Likes

Which, in my perhaps foggy mind, is a “location” (or rather a destination in the context of DT URL commands).

And then DT would have to kinda guess where you want that note to appear. With all that AI stuff floating around – perhaps, one day.

You could provide an URL command that contains the group you’re using 90% of the time as a destination parameter. Or you could write a script to do that and attach that to a toolbar button (or the touchbar, if you’re so inclined)

No. You could also use JavaScript. Which is, IMO, a better scripting language and more useful than AppleScript. Or, as said before, use a command URL.

Aside: DT is not a note-taking app. It’s not advertised as such. So, if your expectations in this regard are not met, perhaps the expectations are at fault.

Also, @BLUEFROG is, of course, right that Shortcuts are a poor substitute (I’d have chosen an unfriendlier term) for scripting. The stuff is a mess, from the app to the implementation of the commands – the find a location within a certain distance command exists since the very beginning and it ignores this distance since then. Crap.

2 Likes

Obviously, I couldn’t get back to sleep (yet), so here is a simple teaching example…

tell application id "DNtp"
	-- Provide a list of database exact names to choose from.
	set destinationDatabase to item 1 of (choose from list {"Netsuite", "Scratchpad"} without empty selection allowed and multiple selections allowed)
	
	-- Get the current date as a string (YYYY-MM-DD, depending on the locale)
	set cd to short date string of (current date)
	
	-- Prompt to enter a title.
	-- This command is particular to DEVONthink. You could alternately use: set noteTitle to text returned of (display dialog "What is the title of the note?" default answer "Today's Note")
	set noteTitle to display name editor info "What is the title of the note?" default answer "Today's Note"
	
	-- Optionally, create a variable with boilerplate content to put in the document.
	-- Variables are concatenated (strung together) with text via "&".
	-- Return can be used instead of linefeed but Return is generally better used with rich text.
	set theContent to "# " & noteTitle & linefeed & "*" & cd & "*" & linefeed & linefeed & "---" & linefeed
	
	-- Create the document in the Inbox of the selected database. This may need to be changed if you meant to reference groups instead of databases, but that wasn't entirely clear to me.
	-- You need to provide a name, the type, the content. The content could even be "".
	-- You also need to provide where the document should be created.
	set newDocument to create record with {name:(cd & " " & noteTitle), type:markdown, content:theContent} in (incoming group of database destinationDatabase)
	
	-- As a convenience, the document is opened…
	-- Looking at DEVONthink's scripting dictionary in Script Editor tell you the command "open window for" requires the term "record".
	open window for record newDocument
	
end tell

… yielding…


Your URL command was invalid and the location parameter is not required (hence not documented as a requirement). If you read the URL Commands section closely, you’ll see there is no content parameter. There is a text parameter and states the two commands it’s explicitly used for, including createMarkdown.

And while I strongly recommend learning proper automation, your Shortcut would be more like this, noting Shortcuts is automatically URL encoding the text for you. I don’t think that’s necessarily a good thing as nothing is learned from it, but it’s convenient…

Now, I am going back to sleep (at 6am)

3 Likes

It’s possible to run AppleScript and JXA within Shortcuts. Not the most elegant of solutions, but it does allow you to access all of DT’s scripting resources within Shortcuts.

IMO the URL scheme is suitable for lightweight automation, such as bookmarklets. Scripting is necessary if you want something a bit more complex. As @chrillek has said, JavaScript is a worthy alternative if you have concerns over the state of AppleScript.

1 Like

I don’t have the documentation pulled up at the moment, but if I remember correctly the “location” is a source URL, seemingly intended mainly for use with web clipping. There was a separate “destination” parameter which takes a GUID(?) that is used to determine where the new file lands. I was already using that destination parameter (you can see it in the provided screenshot), but it didn’t actually do anything until I also included a location parameter, which made no sense in my use case because there was no source location.

Thank you for that pointer. I’m using the touchbar so I can quickly capture a new note even if the DT window isn’t already on my screen. It’s often on another virtual desktop, and I’m usually wanting to pull it up while on a video call.

Extremely helpful information! I’d forgotten about JavaScript as an option, and that actually has me a lot more excited to pursue that route of automation.

And the reminder that DT is not a note-taking app is very helpful as a frame of reference. It feels so easy to use it as a note-taking app sometimes, but then other times it’s not, because that’s not the primary intention. I’ll definitely be rethinking my approach here. (The approach may or may not change, but I’ll be re-examining it at least.)

It’s not my favorite way to automate things, but for simple tasks it works. And in this case I just (thought that I) needed a quick menu and a couple of URL commands. And BetterTouchTool makes it really easy to create a button that launches a Shortcut.

Or run a script, I guess.

While not a core focus of the app, many people compose and edit “notes” (which is technically a use of a format, not a format in and of itself) in DEVONthink. I do it day in and day out. :slight_smile:

2 Likes

I definitely think AppleScript is still a relevant skill, and I wouldn’t regret knowing it if I’d already made the investment. But these days Shortcuts works okay for most of the basic needs I have, and as someone else pointed out JavaScript is also a valid route to take and I thankfully already have some decent JavaScript knowledge.

I’m already stuffing my brain full of new stuff for work, learning NetSuite and adapting it to our needs. Which is why I’m suddenly trying to make sure I’m on top of my knowledge organizing, and minimizing friction to capture knowledge quickly. I wasn’t fond of the idea of learning a whole new syntax and peculiarities just for one app.

I understand why Shortcuts wouldn’t be many peoples’ favorite first option. But for simple tasks it works well enough, and it benefits from being a solid integration point for newer apps or apps that have updated frequently and adopt new frameworks as they come out. In this case, BetterTouchTool offered a really easy way to just select the Shortcut and attach it to a new touchbar button. And it wasn’t a complex automation either: pick from a couple of options in a menu, fire off one of 2-3 URL commands.

Seems like it’s going to be slightly more complicated than that in the end, but not too bad.

To avoid creating a bunch of replies at once (and because I have to start work here shortly), I also just want to thank you for the example script that I saw in another reply. Really kind of you, thank you.

1 Like

Well damn. I guess I rushed through the last couple of tests a little too quickly. I think what happened was that I misread “comment” as “content” and didn’t really question it.

In my (weak) defense, the URL command I had more carefully constructed that failed was:

x-devonthink://createMarkdown?title=[Current Date] [Provided Input]&destination=6F1651FF-F643-4AEB-A154-B02DD86E3B22

This silently fails. Or not-so-silently. You get the little boop sound, but no note, no error message.

Add a location and it works fine (except that I didn’t want a location):

x-devonthink://createMarkdown?title=[Current Date] [Provided Input]&destination=6F1651FF-F643-4AEB-A154-B02DD86E3B22&location=[URLs not allowed in posts]

This, combined with the thread I referenced earlier from 2017 is why I thought the location parameter was required. The URL in my screenshot was from a couple of too-quick iterations later that I tried before I gave up and posted here.

But as you have pointed out, location is NOT required. But without location, apparently text is required? Which is okay! I just didn’t know that text would have been required:

x-devonthink://createMarkdown?title=[Current Date] [Provided Input]&destination=6F1651FF-F643-4AEB-A154-B02DD86E3B22&text=behold

Works just fine. And I can throw a starting header/title into these notes as the text.

If there is somewhere to improve the documentation here, it’s that when you create a note/document through the URL command, you also need to specify some content through one of several options (location/text/maybe others)? It’s probably pretty weird to want to create a document with no content, but apparently there are some weirdos out there who will try it (it’s me, I’m the weirdo).

Thank you everyone who offered guidance. You have a really lovely community here.

2 Likes

The major problem with Shortcuts is the lack of debugging and proper error reporting. When something doesn’t work, there is little to no usable information to determine how to fix it. Automator wasn’t a ton better but it did provide more debugging info.

If there is somewhere to improve the documentation here, it’s that when you create a note/document through the URL command, you also need to specify some content through one of several options (location/text/maybe others)?

I am responsible for the documentation, so I will look at providing more or better examples.

It’s probably pretty weird to want to create a document with no content, but apparently there are some weirdos out there who will try it (it’s me, I’m the weirdo).

I think we’re all a bit odd :wink:

4 Likes

Can you recommend a site to learn AppleScript for a complete novice? Thank you

You didn’t ask me, but I’d rather recommend learning JavaScript. AS is old (-fashioned), not well designed and missing many useful features (string methods, array methods like sort, regular expressions are only some of them). Also, it’s only available on macOS, while JavaScript is ubiquitous. And the web is full with information on it. AS – not so much.

In any case: each programming task can be solved with any programming language. It’s only a matter of time and lines of code.

This is the most common resource for all things AppleScript.

This is another good place, from the makers of Script Debugger (whose owner coincidentally now runs MacScripter)

And a broader but still useful forum…

And our forums.

PS: I personally recommend AppleScript. :slight_smile: But if you feel JXA suits you, go for it.

1 Like

I clicked the reply thinking you or Jim will respond. I greatly respect your valued thoughts. You suggest JavaScript vs AS, so then I will research websites for beginners. Thank you

While one might argue whether AppleScript or JXA are more readable, AppleScript is definitely more reliable than JXA. And while there’s a ton of JavaScript code out there, there’s very little JXA code. Much less than AppleScript code.

2 Likes

Right. Though some of us are trying to change that :wink:

And JXA by itself is, in my opinion, not less reliable than AS – Apple didn’t really finish it. But then they stopped working on AppleScript, too.

Interestingly, there are even areas where both languages fail, like with some Mail properties. Which, of course, Apple doesn’t fix one way or another.

I have once written AppleScript documentation for the apps Papers 3 and Bookends. These scripting guides also contain a quick introduction to AppleScript and feature a “Resources” section at the end with links to further learning resources for AppleScript.

5 Likes

That is a superb intro to Applescript - thanks

2 Likes

Very nicely presented! Good on ya and thanks for sharing with the class :slight_smile:

2 Likes