After having imported thousands of notes from Evernote, Bear Writer and some more apps, I am glad I could preserve and import all creation and modification dates from these notes apps.
One thing that bothers me though is that all folders created by those apps during export have the same datestamp for the folders (“groups” in DT speak).
Now I am working a lot with those dates (sorting the content or the folders by date created to see the chronology.
In order to re-create and attach the date-created to the groups, I would like to
select a bunch of groups and
then programmatically check the contents of these groups:
2a Get the oldest item in the current group
2b Get it’s date created
2c Assign that date to the current group
process next selected group
My AppleScript knowledge is too weak to get this going.
Can anyone give a me a few ideas for how to iterate the contents of a selected group?
What I see in the “Script Editor” > “Open Dictionary” > “Devonthink” is
Ok, I seem to have it. This code snippet in JXA is a good starting point for me:
app = Application('DEVONthink 3');
app.includeStandardAdditions = true;
var sel = app.selection();
// assume a group or a bunch of groups are selected
sel.forEach( el => {
var groupName = el.name();
//console.log(groupName);
//console.log(el.kind());
// so if the selected item was a group ...
if (el.kind() === "Group") {
// process the children
console.log("------- CHILDREN OF GROUP ----------");
el.children().forEach( c => {
// if the child itself (items within group)
// are not groups
if (c.kind() !== "Group") {
//Process the items...
console.log(c.name());
};
});
};
});
I’ll post the code once I’m done.
Here is a working solution
Select a group or a bunch of groups, then run this script:
/*
Created: Thursday, 4. June 2020 22:17
Author: Ugur T.
Redate groups
by taking the oldest create-date
of the children (items).
*/
app = Application('DEVONthink 3');
app.includeStandardAdditions = true;
var sel = app.selection();
sel.forEach( el => {
// assume a group or a bunch of groups are selected
let groupName = el.name();
let dateCandidate = el.creationDate();
// so if the selected item was a group ...
if (el.type() === "group") {
console.log("------- PROCESS CHILDREN OF GROUP ----------");
el.children().forEach( c => {
// if the child itself (items within group) aren't groups
if (c.type() !== "group") {
// get and compare date
if (dateCandidate > c.creationDate()) {
dateCandidate = c.creationDate();
}
};
});
};
console.log("Oldest datestamp in group: " + dateCandidate);
el.creationDate = dateCandidate;
});
How do you navigate the help? In trying to replicate your search result, I searched for “record” (so success; see screenshot below), “dictionary” (no success either). It means I have to RTFM I guess, every topic in it Search isn’t of any help it seems.
A word of caution, straigt from the DT3 JavaScript dictionary: kind [Text] The human readable and localized kind of a record. WARNING: Don’t use this to check the type of a record, otherwise your script might fail depending on the version and the localization.
type (“bookmark”/"feed"/"formatted note"/"group"/"html"/"markdown"/"PDF document"/"picture"/"plist"/"quicktime"/"rtf"/"rtfd"/"script"/"sheet"/"smart group"/"txt"/"unknown"/"webarchive"/"xml", r/o) : The type of a record.
I therefore suggest that you change your first ifcondition to el.type() === "group"
(In fact, the script as it is doesn’t work in my German locale
As to the help problem: Jim is quoting from the manual. In my installation, it is the first item in the Help menu (see Screenshot).
Re: Search in Help. It’s broken on my system it seems. Yes, I can see the “DEVONthink Help” entry in Help menu, but I cannot search for anything in it. Just trying to re-index with Spotlight, maybe that’ll help.