Modifying Date Change Script for DD/MM/YYYY Input, Primer?

Hi,

I’m working my way through a filing cabinet worth of scans, as well as old files, all of which are named starting with their date as YYYY/MM/DD. At the moment I’m trying to find the best way of changing these documents in order to set the creation data metadata field as the actual date of the documents as opposed to a scanned or added date (it doesn’t matter to me if other fields exists with those dates).

Ideally, I would be able to change the creation date metadata field from the main view as is supported with filenames, but I’ve read that this isn’t possible. Barring that I’m using the date change script with a keyboard shortcut in order to make things as speedy as possible (as opposed to the info window).

My only issue with this is one of human failings, as in I’m used to DD/MM/YYYY or YYYY/MM/DD and so have been messing up the input in this script of MM/DD/YYYY. I’ve tried swapping instances of Day and Month in the script, but so far have only managed non helpful changes.

Long story short, can anyone point to the line that’s setting the input as MM/DD/YYYY and/or to a primer on AppleScript?
Thanks,
Patrick

[Most likely line, as it has the label on the input menu as changing the section in quotes and I’ve checked that changes to it change the input menu in devonthink.
else
set defaultDate to theDay & “/” & theMonth & “/” & theYear as string
display dialog “Enter modification date in DD/MM/YYYY format:”]

If you want to get into AppleScript, https://macscripter.net/ is the oldest and most valuable AS resource on the web.

Another great resource (and a simpler dive into automating Macs) would be from our Father, Sal Sogohian :mrgreen: , https://macosxautomation.com/applescript/learn.html.

I actually suggest starting on Sal’s pages if you’re just looking for easy to read concepts. MacScripter is great but can be overwhelming if you don’t know what you’re asking or looking for. Otherwise, it’s a fantastic place to browse and learn.

Regarding the script itself, what specific script are you using?

Thanks for this, the macosxautomation site looks like a great place to start.

I’ve been using the built in script by Christian Grunenberg. I’ve also added the edit of that script by Frederiko, but all of the changes I’ve been making are to a copy of the Christian Grunenberg/built in script (accessible through the “Install DEVONthink Pro Office Extras” window).

Admittedly, all I’ve done is try to swap instances of day and month in all possible combinations. I had hoped that brute enforcing it in that way would have worked, but so far all I’ve managed to do is to change the input window and produce some strange dates. No luck on changing the input for ascending or descending date format, MM/DD/YYYY to DD/MM/YYYY.

But which script? Criss has written many scripts! :smiley:

Sorry, I was just copying the top lines in the AppleScript window. It’s labelled “Change Date.scpt”
“-- Set creation/modification date
– Created by Christian Grunenberg on Sun Mar 12 2006.
– Copyright © 2006. All rights reserved.”

It’s the script that installs/downloads from the “Install DEVONthink Pro Office Extras” window on the fourth tab.

The AppleScript coercion to a date is locale dependent. If you’re in the US, it assumes the month is first. This leads to an interesting (and funny but logical) condition where a string like “15.01.2018” coerces to March 1 of 2019 since March 2019 is technically the 15th month of 2018! :mrgreen:

It’s possible to hack this for your purposes though… and this is specific to your question (but could be adapted by others so inclined).


set newDate to do shell script "echo " & (text returned of the result) & " | sed -E 's_([0-9]{1,2})[./-]+([0-9]{1,2})[./-]+([0-9]{2,4})_\\2.\\1.\\3_' #DD.MM.YY(YY) --> MM.DD.YY(YY)”

set theDate to date newDate
```![chagedate.png|690x500](upload://hQvHrRe8qpxLRk2lzPfFYFPEeBq.png)

This is a bit more advanced coding that swaps values in the string to provide a date valid for your locale.

I finally understand why it was spitting out 2019 dates at one point :slight_smile: That was really throwing me off.

I’m Canadian and apparently there’s some difference of opinion on the date format. The federal government and most of the bit in the wikipedia article on Canadian date formats say YYYY/MM/DD, but Apple has it set as MM/DD/YYYY. It’s weird and I wouldn’t have clued in without the explanation-thanks

As for the script, i’m almost certain that I’m pasting it into the right place, but I’m getting the error on saving/compiling “Expected end of line, etc. but found identifier.” and DEVONthink is selected. Any ideas as to where I messed up with the addition?

Post a screencap, please.

Okay, there’s one of the error and one of the entire script. Any on ideas what I messed up?

Yep. As I expected, the last quote in the shell script line is a typographer’s double quote, not a straight double quote.

Apologies on the wait for a response, my Thanksgiving dinner took over things.

The script compiled with that quotation change, but within devonthink I received an error while running it:

“sh: -c: line 0: unexpected EOF while looking for matching `’’
sh: -c: line 1: syntax error: unexpected end of file”

If it’s become too convoluted don’t worry about it, I appreciate the help taking me through how things work and worst case, I can manually verify my date entries afterwards.

Thanks,
Patrick

I’m guessing you accidentally removed the single quote before the ending double quote.

Apologies on the wait, there was probably too much family around for thanksgiving weekend to make a go of this script change. Thanks again for taking the time to explain things, it’s way beyond tech support.

Also, the removal of the single quote was the problem. Not sure why I did that, maybe it’s the same cognitive bug that allows transposing ascending and descending date formats but not American ones.

Cheers,
Patrick

No worries. We’re not in a rush on the Forums! :smiley:

And you’re welcome. I appreciate opportunities to teach when people are willing and desire to learn. Cheers!