Leading zeros in months and days

I’m trying to make a very simple template for journal entries.
I’d like to create a text file named YYYY-MM-DD.
I’ve found that I can use %month% and %days% in file names, but those variables don’t add the leading zero for month and days between 1 and 9.

I can’t use %shortDate% because I need the system wide short date set to the italian format.

Is there any way to solve the problem?


This can be done by using a template script package (.templatescriptd):

  1. Create a new script in Apple’s Script Editor
  2. Paste this code:

tell application "DEVONthink Pro"
	set theDate to current date
	set theDay to (day of theDate) as integer
	set theDayStr to (theDay as string)
	if theDay < 10 then set theDayStr to "0" & theDayStr
	set theMonth to (month of theDate) as integer
	set theMonthStr to (theMonth as string)
	if theMonth < 10 then set theMonthStr to "0" & theMonthStr
	set theDateStr to ((year of theDate) as string) & "-" & theMonthStr & "-" & theDayStr
	set theFile to (path to me as string) & "Contents:Resources:%theDate%.rtf"
	import theFile placeholders {|%theDate%|:theDateStr} to current group
end tell

  1. Save it as a script bundle (.scptd)
  2. Add an RTF document named %theDate%.rtf to the script bundle (just drop it on the drawer in the Script Editor)
  3. Save it again

Finally, change the script’s extension to .templatescriptd and move it to ~/Library/Application Support/DEVONthink Pro 2/Templates.noindex.

1 Like

Aargh. (see below)

I’ve just repeated the steps without any issues (of course :wink:). Could you attach your zipped script package that doesn’t work?

Never mind.

I was running it from AppleScript Editor so of course the path was bolloxed up. :blush:

Executing the script via the Script Editor after step 5 but before renaming it should be possible too (at least over here using Mac OS X 10.6.3).

It works like a charm!

Thank you very much.


I am trying to achieve the same thing, however I am stuck at step 4. How can I add the .rtf to the script bundle? I don’t see a drawer in the Applescript Editor and no menu entry that adds a file to the script either. Has the script editor changed in the last five years, so that I need to do this differently now?

Thank you,

The window’s button bar has a button “Bundle contents” at its right end.

Thank you, alastor, that’s what I thought the drawer was.

It turns out that it did not wort for me yesterday, since I manually renamed the file to the .scptd format instead of properly saving it into this format. This way the drawer was not greyed out, but I still could not move any files into it.

It works really nicely now, thanks!


Yes, manually changing the extension would cause that.
Another thing to be aware of: when you save a script bundle somewhere else, or with a new name, any files you put into its Resources folder are not copied to the new bundle.
The Editor does not really know they are there.

IMHO, month and date padding to 2 digits is so useful it should be built-in:


which would make this script un-needed.

but thanks for it, as we need it in the meantime

1 Like

Welcome, @jdm

Thanks for the suggestion. No promises, but it’s noted.

1 Like