Smart Rule to create new Markdown file in predefined group?

Hello,

Apologies in advance for the noob question, but I couldn’t figure it out after searching and learning from the AppleScript dictionary for DT and this forum.

Use case

I just started experimenting with taking short journals in DT. I plan to store all the journal entries as Markdown files in the group Journal, which is located at the root level of the database Personal. The title of each entry is its creation date, formatted as MM-DD-YYYY. I plan to write in the default external app for Markdown.

Objective

I’m trying to automate the processing of creating a journal entry utilizing Smart Rules. When I run it, it should:

  1. Create a new Markdown file titled MM-DD-YYYY in the group Journal from the database Personal.
  2. Open the new empty entry in the external app.

I feel like this should be a trivial automation, but I just can’t get it to work perfectly. Thank you in advance!

Why would you use a smart rule for this?
This is the place for a template.

I’d suggest creating a template then double-clicking or pressing Shift-Command-O to open it externally.

Here’s a simple example template…
MDY.zip (805 Bytes)

I do almost exactly this but all on an iPhone.
I use shortcuts to create the markdown doc with prepopulated info (a TOC, weather and some tables for what media I am consuming). There’s also a set of shortcuts to create clipboard text that can be pasted into that days doc for various activities. I am tweaking the shortcuts constantly as my journaling gets more involved and spreads out into what is becoming a writing project. I do all my journal entries in DTTG and feel pretty comfortable in markdown mode.

For me, having it on my phone means I can journal anywhere and I can also tweak my workflow anywhere.
I’ve so far resisted adding photos to my journals but the impulse is there and I think DTTGs photos-in-markdown implementation has gotten better recently.

The journal DB exists on my desktop but I only deal with it there to clean up the odd wayward tag or glaring typo and to back it all up.

Hi Jim, thanks for the reply!

I considered templates but decided to use smart rules instead because I thought templates would be the best solution if I plan to use the template across different databases and groups, whereas in my case the files will only be stored in the same Journal group.

By using smart rules instead, I can automate the file creation action (navigating to Journal and use New from Template) and the Open in external app action. The overhead is admittedly minimal, but since this might evolve into a daily process, I wanted to automate wherever possible.

Hi, thanks for the reply!

I used to do exactly the same years ago on my iOS devices and it worked very well indeed, but eventually I gave up on the habit because I didn’t think it was worth it to keep a journal.

Recently I’m seeing the need to keep a journal again due to some changes in my life, but nowadays I’m working almost exclusively on my Mac so it makes much more sense to use DT on the Mac instead of on iOS.

I just spent some time trying to use Keyboard Maestro and DT’s URL Commands, but it didn’t work either. I used

x-devonthink://createMarkdown?title=test&destination=4603A598%2DB793%2D4691%2DBACA%2DD9919F198C89

Which merely launches DT and triggers a Boop OS sound effect without creating the new file. I have no idea what I’m doing wrong.

You’re welcome.

And what event trigger would you be using?

I don’t see how this would be any more performant than navigating to the group - likely via Favorites (since that’s a common use of them) then hitting a hotkey to use the template.

1 Like

That’s a very good point, thank you! I forgot about the feature since I’ve never found a use for it until now. I will adopt this approach instead of smart rules.

That said, could you help me understand why I couldn’t get the URL Commands to work? Although I won’t need it this time, it still bothers me that I don’t understand what I’m doing wrong.

You’re welcome!

The URL command for creating a Markdown file requires content via the source or text parameter or a URL-encoded location parameter.

x-devonthink://createmarkdown?title=test&destination=E853EBBE-AAF0-468E-9D52-A22CDE6EE97F&source=hello
1 Like

Got it. Thanks again for the help!

My pleasure.

I am using this AppleScript to achieve a similar effect. In my case I am running it through Keyboard Maestro, but it could work with any other automation tool that can run AppleScripts.

I do not really know who to credit for this AppleScript but surely it is not me"

set [_day, _month, _year] to [day, month, year] of (current date)

set _month to _month * 1
set _month to text -1 thru -2 of ("0" & _month)

set _day to _day * 1
set _day to text -1 thru -2 of ("0" & _day)

set the text item delimiters to ""
set theDate to {_year, _month, _day} as string

tell application id "DNtp" -- Talk to DEVONthink
	tell database "Personal"
		set theGroup to (get record with uuid "E08B7A41-2E52-49EF-9721-83B7B7367E89")
		set theRecord to create record with {name:"Journal - " & theDate, content:"# Journal - " & theDate, type:markdown} in theGroup
		set newWindow to open window for record theRecord
		activate
	end tell
end tell

1 Like

Thank you for sharing the script! (And the original creator, whoever they are :P)

Or you could just add it to DEVONthink and assign its own shortcut in System Preferences > Keyboard > Shortcuts > App Shortcuts. :smiley:

2 Likes

Thanks for taking me to another cool place in macOS that I paid attention to before, Jim! I played around with this idea but didn’t understand how it works, so I hope you could elaborate on it.

If I understand correctly, “add it to DEVONthink” means adding the AppleScript to DT’s Scripts folder (~/Library/Application Scripts/com.devon-technologies.think3/Menu) so that the script can be accessed from the menu:

But how do I refer to the scripts menu in System Preferences, since its name is an icon? After reading Apple’s support article for this feature, I tried Scripts and Script but neither worked:

What am I missing here?

You’re welcome.

If I understand correctly, “add it to DEVONthink” means adding the AppleScript to DT’s Scripts folder (~/Library/Application Scripts/com.devon-technologies.think3/Menu ) so that the script can be accessed from the menu:

That is correct.

You don’t need to specify the parent menu unless an item’s name already exists in the application, e.g., Format > Highlight > Red and Data > Label > Red. If the name is unique - and it likely is with a script - just enter that as the menu name in the system preferences.

PS, from our blog…

1 Like

Thanks, now I understand better.

DEVONtech’s blog is a such a great companion, I really should pay more attention to it. :stuck_out_tongue:

You’re welcome and indeed you should.

Remember you can also access the tips, etc. from the View > Extras sidebar in every edition of DEVONthink.

1 Like