Automatically Create a File?

I am losing track of features in terms of what is in DevonThink and what is elsewhere!

Is it possible to have DevonThink automatically create a new markdown file, based on a criteria?

I am thinking to create a new ‘daily log file’ when the clock goes past midnight, with a standardised file name in the form of YYYY-MM-DD.

Is this doable within DevonThink, or should I turn to Keyboard Maestro?

Thanks!

As smart rules can process only existing items, the only possibility would be to use a scheduled smart rule executing a custom script.

1 Like

As @cgrunenberg said, in DT you’ll need a smart rule with script for that. Alternatively, an automator action or a shell script might achieve the same. But they all probably require your machine to be running all the time… Even so, I’m not sure that Automator or DT is able to run scripts when they are in the background or not even running. A shell script in combination with a cron job might be your best choice.

And: I’d suggest to make the file name a bit more specific then just the current date :wink:

1 Like

You could create a group, a reminder and use this reminder script

-- Create daily markdown record via reminder

on performReminder(theGroup)
	tell application id "DNtp"
		set theName to do shell script "date \"+%Y-%m-%d\""
		create record with {name:theName, type:markdown, plain text:""} in theGroup
	end tell
end performReminder
2 Likes

I never cease to be amazed by the friendly and helpful people on this forum. Thank you all!

2 Likes

Hi @pete31 - your script is working great for me.

One further question I’m hoping you might be able to help with…

Is there a way within the script to issue a shift-cmd-D to insert the text field as a markdown header level 1 (#)?

I don’t know AppleScript, so not sure how to write into the file that is created as part of the script.

Thanks!

Write everthing you want to be prefilled after plain text:, so a markdown header would be plain text:"# ".

If you also want text on a new line use either

plain text:"# " & linefeed & linefeed & "Text on a new line"

or

plain text:"# " & space & space & linefeed & "Text on a new line"

if you don’t want a blank line.

1 Like

Thanks! This is the working script as it stands currently:

-- Create daily markdown record via reminder

on performReminder(theGroup)
	tell application id "DNtp"
		set theName to do shell script "date \"+%Y%m%d\""
		create record with {name:theName, type:markdown, plain text:"# " & theName & linefeed & linefeed & "- "} in theGroup
	end tell
end performReminder

The last ideal improvement would be to replace my header text which returns variable theName into the equivalent of DT’s insert date, which creates a human readable friendly date.

Rearrange the do shell script and use it in a new variable, e.g.

set theDate to do shell script "date \"+%d.%m.%Y\""

Thank you, now I’ve got this working exactly how I want it, and I’ve learnt a bit of AppleScript and how to format dates within a Shell Script.

I appreciate your guidance, @pete31

1 Like