I thought it’s possible to have multiple groups of the same name that live next to each other in the hierarchy. So let’s assume there would be some kind of script, that creates (sub)groups based on the string GroupA/GroupB/GroupC. That script would then go and create a structure like this in DevonThink:
GroupA
GroupB
GroupC
The second time I run this script, using the second string (“GroupA/GroupB/GroupD”), I would want the hierarchy not to look like this:
tell application id "DNtp"
set groupNames to {"Group C", "Group D"}
repeat with groupname in groupNames
create location ("/Group A/Group B/" & groupname)
end repeat
end tell
I think I get the problem here. If you create the whole path/location each time you run your script, then yes, DT will do as you asked and create each group in the location specified each time.
The trick is checking to see if the location exists already in the midst of your location creation. Roughly:
try
get record at
on error
make new record at
end try
The question, then, is how you want to determine whether or not to create a new group vs use a previously created one.
@BLUEFROG Thanks, but this seems not dynamic enough. I basically look for a functionality like mkdir -p (man page).
@ryanjamurphy I think you’re on the right track with your idea.
I tried to put what has been posted together in pseudoscript, putting into square brackets, what I don’t know how to do.
tell application id "DNtp"
set groupNames to [make string to array such as first element is first part until slash, etc.]
repeat with groupname in groupNames
[if element exists as a group do nothing
else create element:
if element is not first element of groupNames
get last element and create group as a subgroup to it
else
create location
save current location as last location]
end repeat
end tell
EDIT: last refers to last seen not last in the array.
I think so. I have a universal hierarchy which is the same in every context where such a thing makes sense (filesystem(s), Zotero, Mailboxes, etc.) this hierarchy grows with time, when new things are added. I would like to be able to have an easy way to “instantiate” parts of the hierarchy if I have documents in DT that need to be filed away. Does this make sense? It would be great to get a pop-up, paste a string of the described form in there and DevonThink (or a script) creates the appropriate (sub)groups, if needed and otherwise only adds the “leaf group”.
Yes. That would mean maintaining the hierarchy in more than one spot. That’s not what I want to do. My notes system holds the “blueprint” for the whole hierarchy and tools like DevonThink use the parts of the hierarchy that they actually need.
What you see is a KeyboardMaestro Macro, which prompts the user for a string of the form as described and then simply adds (sub)groups to the database root, if they don’t exist already. This is exactly what I needed.
Let’s assume that I would like to archive my email and my tax files in a DevonThink database, then I would need to create the following (sub)groups in my dedicated DT-DB:
xx-Archive
Mails
Taxes
I would not need anything else in that DB, but I would also like to not reinvent the wheel with every other instance I want to file something. If later I would like to archive some Pictures in the same DB, I would already know where they would go: xx-Archive/Pictures, naturally.
But xx-Archive/Pictures might also be useful somewhere else (maybe old screenshots accompanying published blog posts should be filed away on the server there?).
Obviously, these examples are a little far fetched, but I hope you get the idea.