AppleScript reminder due dates: what changed in DT4?

In DT3, this script worked perfectly — it created a reminder on the record, set to 07:00 on the 5th of the current month if the current date was the 5th or earlier, and the 1st of the next month if it was after the 5th.

on performSmartRule(theRecords)
  tell application id "DNtp"
    repeat with theRecord in theRecords
      set theDate to current date
      if day of theDate > 5 then
        set day of theDate to 32 -- force to next month
      end if
      set day of theDate to 1
      set theDateString to (date string of theDate) & " 07:00:00"
      tell theRecord to make new reminder with properties {schedule:once, alarm:open externally, due date:theDateString}
    end repeat
  end tell
end performSmartRule

On DT4 it produces the error Can’t make “Monday, December 01, 2025 07:00:00” into type date or missing value. It seems to be objecting to the time — if I omit the & “ 07:00:00” everything works (except for the reminder only being set correctly if I run the script at 07:00 precisely!)

I can’t see what’s changed — the change list in the manual just mentions improvements to AppleScript, but it’s not feeling particularly improved from where I’m sitting right now :slightly_smiling_face:

I already raised a support ticket, and since managed to make it work by setting due date:theDate rather than using the date string, and setting the time by the (frankly ugly) set time of theDate to 7 * 60 * 60but I’d prefer:

  1. something that doesn’t rely on cryptic multiplications, and instead has code that clearly shows what it’s doing, and
  2. to know why the old code doesn’t work any more.

Since I haven’t changed OS at the same time, it seems unlikely (for once!) that this is Apple’s doing…

The script suite was completely rewritten with lots of additions and changes. But not every script is still compatible and therefore might need some minor changes.

Alternatively you could use this:
set {hours of theDate, minutes of theDate, seconds of theDate} to {7, 0, 0}

1 Like

If you run

log current date

in Script Editor, what output do you get? I can’t try that here, because my locale is set to German.
You could also try to use “add reminder” instead of “make new reminder”.
Or use set time of theDate to 7*3600 and use theDate instead of a string.

Edit I’m quite late to this party, it seems.

@chrillek Interestingly, I get nothing at all:

…which is bizarre, to say the least!

Thanks — your solution definitely leaves me with a clearer idea of what the script’s trying to do the next time I look at it :+1:

(Is there a list of incompatibilities anywhere? It sounds like there isn’t, but it might be a good idea to collect them in one place as people run into them…)

It’s a shame the dark mode colours for the script editor haven’t changed, though — that dark blue is virtually illegible on my screen (especially since there doesn’t seem to be a way to increase the font size!)

Ideally all the syntax colours would be light when the background is dark — so light cyan instead of blue, light pink instead of purple, and light green instead of mid-green. I usually end up copying everything across to Script Debugger just to be able to read it…

Turn on the protocol with Cmd-3:

Even in Script Editor, font size and color can be modified:

But I wouldn’t hold my breath waiting for Apple to fix dark mode for Script Editor.

Thanks — I get this:

Result:

date “Monday, December 01, 2025 at 08:51:39”

I wonder if it’s the “at” that it’s wanting now?

As for the colours, I wasn’t talking about the colours in Apple’s Script Editor — I guess that would apply if you only used external scripts with DT4, but that’s a faff for inline scripts. If you edit a smart rule in DT4 that has an inline script, and click the “Edit Script…” button, DT4’s own script editor is what’s showing up with unhelpful colours. (At least Script Editor does let you configure them!)

I was hoping to avoid having to copy a script from DT4 and paste it into Script Editor just to be able to read it :grin:

There’s always light mode :wink: Perhaps DT’s script editor uses the same colors as Script Editor so that changing them in one modifies them in the other?

As to your original question: The problem seems to be solved anyway avoiding the cast to string and recast to date now. You can still try to do a & "at 07:00" in your original code, of course. The to and fro with date and string types might be more in line with AppleScript coding habits.

I doubt that. In German, the time is added with a um instead of at, and simply appending a 07:00 to the date string works ok (ie date dateString is “some date um 07:00”).

1 Like

AH. That’s the solution — that window is just Script Editor in a DT4-shaped trenchcoat. Thanks :+1:

Changing the Script Editor settings gets me something usable in DT4. Of course, Script Editor’s background can’t be changed from white, but I tend to use Script Debugger for editing anyway.

I think I’ll leave the date handling stuff alone now that it’s working :grin:

The due date expects (and always did) a date but the rewritten AppleScript support of DEVONthink 4 uses a modern .sdef-based script suite contrary to older versions, this might trigger subtle differences like this one. But overall the new format offers more options and improves the compatibility to JXA a lot. And version 4 includes also a new command plus examples how to add reminders:

And this command accepts a string:

set theDateString to (date string of theDate) & " 07:00:00"
add reminder {schedule:once, alarm:open externally, due date:theDateString} to theRecord

P.S: If the current day is the first of the month (like today), then the reminder created by your script is immediately triggered as it’s overdue.

3 Likes

Thanks!

I did know about the reminder triggering immediately if I try to set it before the 5th, but that’s deliberate to remind me to actually do the thing rather than try to set reminders about it :slightly_smiling_face:

I’m not sure I understand. Isn’t that what the scripting dictionary is for?

If an old script gives an error/unexpected result, I would run it in Script Editor and check the log to see what’s going on. Then look up the involved commands/elements/properties in DT4’s scripting dictionary to see what’s changed.

1 Like

The thing about the scripting dictionary is that it doesn’t show a list of changes — it just shows what it now is, and you have to spot that something’s different. Especially when Can’t make “Monday, December 01, 2025 07:00:00” into type date or missing value is the sum total of what appears in the log (because I did already look there, and posted what I found in the first post :slightly_smiling_face:)

If you can look at the “reminder” page’s “due date” entry, and click through onto the definition of “date”, and see what changed between DT3 and DT4, then you’re better at this than me!

When I mentioned a list of incompatibilities, I was thinking more along the lines of a table with two columns: “what it was in DT3”, and “what you need to do instead in DT4” — something people could find the answers in quickly so they could get things working again.