DEVONthink and DEVONthink To Go automation with Shortcuts + JavaScript

I am looking for way how to make automation of DEVONthink and DEVONthink To Go in the same way.

Currently I have i(Pad)OS Shortcuts for iPad and iPhone, and Keyboard Maestro + AppleScript for mac.

Is it good idea to rewrite all the Shortcuts and KM macros into Shortcuts + JavaScript?

I mean, at mobile and desktop platforms, Shortcuts run JavaScript.

AFAIK, shortcuts doesn’t run JavaScript on iOS. Nor AppleScript.
Also, Apps on iOS generally provide no scripting support. In particular, DTTG is not scriptable.

Edit apparently, it is possible to run JavaScript code in Shortcuts:

Though that’s a real pita.

Thanks for the article, @chrillek.

I have tested “Run JavaScript on Web Page” action before.

For instance, the following Shortcut converts number to words using JavaScript — Convert Number to Words.

Such operation would be too cumbersome without JavaScript (very PITA :slight_smile: ).

Is it possible to make such Shortcut with JavaScript — New Note?

What I mean? There are no DEVONthink actions for Shortcuts in macOS — for instance, there are no “Create Item” and “Open Item” actions. Is it possible to replace them with URL-commands using JavaScript?

If yes, a user would be able to use the same Shortcuts in i(Pad)OS and macOS.

I don’t know if that’s possible. And I also don’t see the point. At the time being, I don’t touch Shortcuts with a ten foot pole, and given Apple’s record with automation technology, I’m not very optimistic that it will get better (in the sense of useful). We still can’t even synchronize Shortcuts across the platforms, and that’s in the third iteration of the product.

Also, why would anyone go through all the loops to run JS code in Shortcuts on macOS if it’s possible to run the code directly in DT (or via osascript or in Script Editor)? Or simply use a keyboard shortcut to create a document or open it.

This whole “run JS in Shortcuts on i*OS” approach is a terrible hack which is only necessary because Apple’s automation support is so broken. Why should one want to run the same hacky stuff on macOS where it’s not necessary at all?

4 Likes

And I also don’t see the point.

The point is — I have about 70 Shortcuts in i*OS for DEVONthink To Go — for journaling, photoalbum, CRM, … For family, personal use and business.

For instance, for creating PDF quotations and bills with price calculation, graphics, with automatic writing in registers.

I like mobility. i*OS Shortcuts let me have mobile office.

If DEVONthink had the same Shortcuts actions like in i*OS… I understand it’s too expensive to support so many things — Shortcuts, JavaScript and AppleScript at both platforms.

Thanks @chrillek for your thoughts.

Shortcuts on macOS supports running scripts.

I know. It doesn’t on i*OS, though. Which makes it impossible to write portable Shortcuts with scripts.

I sync my shortcuts across platforms. Even to watchOS. Admittedly they live in different environments, but they do sync.

1 Like

Scriptable on iOS can run JavaScript scripts it will work with shortcuts.
It also has it capabilities hardware, sensors and dialogs.
There is a beta MacOS version but it doesn’t look like like it’s been updated in a while but it works.

There are no DEVONthink actions for Shortcuts in macOS — for instance, there are no “Create Item” and “Open Item” actions. Is it possible to replace them with URL-commands using JavaScript?

yes there is no shortcut support in DEVONthink for MacOS.

  • yes you can use x-devonthink in AppleScript, JXA (JavaScript for Automation) and virtually any language that support URI schemas.
  • Shortcuts has command line support so you could call shortcuts from AppleScript or JXA
shortcuts run <shortcut name> args
  • You can also call AppleScript or JXA from shortcuts via osascript or via the html trick to run JS in a web page.
  • You can call AppleScript or JXA script files from AppleScript or JXA script files
  • You can call shortcuts from shortcuts (shortcuts has a method for this)
  • You can use functionality from other applications that support AppleScript or Shortcuts
  • Like above You can use helpers small apps to extend functionality.

So using these options you can get Devonthink to call Shorcuts. Then use logic to call AppleScript/JXA or another shortcut depending on OS/Device. Don’t forget you can breakdown complex shortcuts into sub shortcuts.

AppleScript/JXA hasn’t been updated for ages I am not sure Apple has a future for it. I think shortcut support will become a must eventually.

If I remember correctly, the OP was looking for shortcuts that are portable across platforms. Running JavaScript (outside of html documents) and AppleScript is only possible in Shortcuts for macOS, though (AFAIK). Also, osascript is macOS-only.

So it would be trivial to write a Shortcut to create a new document for DT in AppleScript or JXA. But that wouldn’t work on iOS. In order to use the same Shortcut on both platforms, one would have to do some OS divination in the the code.

Correct there is no JXA or AppleScript on iOS/iPadOS.

In order to use the same Shortcut on both platforms, one would have to do some OS divination in the the code.

That’s exactly what I suggested you cannot call shortcuts from DT triggers so you need to create a wrapper. Have shortcuts then call the shortcuts from AppleScript or JXA on macOS for DT if it needs to be an action otherwise as a shortcut from share panel or service, call shortcut from share panel on iOS. Then use URI schema on iOS for DTTG via shortcuts or call ActionScript/JXA or URI for DT on MacOS. Depends on how much functionality can be shared by shortcuts to whether its actually worth it. If not, just write two sets of scripts.

Then use logic to call AppleScript/JXA or another shortcut depending on OS/Device.