Automatic Merge Documents script for tagged files?

This is a problematic word…

  1. Because “automatic” implies some continuously running process.
  2. Because “automatic” can often do unexpected (and sometimes disastrous) things unless the variables and data are highly srtuctured and always uniform.

I hear you and really do appreciate that. Truly. Nevertheless, I’m wondering if there might be a way to still accomplish this in some way – that is, to create a script that allows one to merge documents in select tags, and to update a merged output as new files are included in those tags.

What do you think…? I realize this is potentially tough, but I sense it might still be achievable.

Thanks again!

Not without some User intervention, no it’s not possible. At the minimum it would require a Smart Group to either make a selection and run the script, or potentially writing a Triggered Script. (The Triggered script is about as automatic as it would get.)

That’s super helpful and interesting… I’ve created SmartGroups, but find that I’m not quite setting them up right (e.g., I either don’t quite command them to do what I want or I’m unable to filter for the right matches). Anyway, if I follow you correctly, you’d suggest I: (1) Create smart folders to group files for particular tags, and then (2) one could (presumably) reconfigure the Merge Documents script into a trigger script so that it would create some degree of an auto-merge affect for files collected within the smart group. Have I understood you correctly?

Thanks!

So you have files tagged “Merge Me” and you want all those files to be merged into a document “I Am the Merger”. Then a new file comes along, or two or ten, and you tag the new files “Merge Me”. By that action, you expect something somewhere to be triggered and all the new file(s) to the end? the beginning? the middle? of your “I Am the Merger” document. And so forth. Endlessly, I suppose.

No question that you have a reason for this procedure, but why not just navigate to the “Merge Me” tag group from time to time and merge everything that’s there at that time?

This script will do something like what you want. Attach it to the tag. It is a triggered script, and requires you to manually click that tag group. It will merge all the child records of that tag at that time. Manual clean up is still needed. There is no automatic job scheduling in DEVONthink scripting, and it would be a big one-off time suck to try to manage that job.

on triggered(theRecord)
	try
		tell application id "DNtp"
			set theSelection to every child of theRecord as list
			set theResult to merge records theSelection
		end tell
	end try
end triggered

You make a lot of important points, @korm… Thank you for those. I had a feeling there might have been a problem w/ this kind of approach. In fact, it might represent more of a workflow problem that I’m trying to sort out.

In short, I’m using this tagging script for my annotated files:

[url]Make an Annotation with Links, Notes, Tags v2]

…and @Frederiko’s workflow approach, some of which is described here:

[url]Make an Annotation with Links, Notes, Tags v2]
and here…
[url]Put up Example page]

He shared more w/ me about it, and further described how he uses the Merge Documents script for tagged files (after he’s completed the annotation, review & organizational process). All of that is great, and the merged document is terrific. (Can’t wait to try your script @korm!)

But…while I’m refining my DTP process (thanks to many members here!), I’m increasingly using Scrivener as my writing platform. So…I’ve been trying to consider a way in which I can have certain tagged files automatically merged in some way so that I can integrate them (hopefully sync them, somehow) w/ my Scrivener doc. I realize that last part of what I just wrote in that sentence is likely problematic, and probably contains some technical flaw (I’m still figuring out how one can best sync / integrate files between Scrivener & DTP). But I thought that if I could figure out the first part of this puzzle, I could eventually solve the second part of it…

Anyway, that’s the convoluted reasoning behind this. As always, I welcome any other ideas / suggestions you might have – even for an alternative approach. Thanks, guys!

A good place to talk with folks about using DEVONthink with Scrivener is the Literature and Latte forum.

Thanks for that suggestion, @korm. I’m already on that, and have been trying to figure out how best to work with the two apps (and integrate them, wherever possible). But I need to first find a solution to merge documents for tagged files (i.e., tagged files via the “annotation files for each citation plus notes+tags” script) since that’s an intrinsic DTP function.

Anyway, to that end, based on the discussion here it seems that that SmartFolder + Trigger script solution is the best route, correct? Happy to consider other approaches.

Once I settle on that process, I need to figure out how best to sync updated merged files w/ the Scivner project file. I’ll happily share that info if the folks at Literature and Latte relay it first!

Thanks again, guys.

My honest view is to forget about automating the process. Scrivener has no automation support. Before DT I had a thousand lines of python code for playing with Scrivener’s xml but I don’t recommend it because Scrivener doesn’t scale well enough to make the effort worthwhile.

Put DT on left side of screen & Scrivener on right. Use Scrivener for writing, which its great at, but not for storing or planning your research. If you really need to you can drag files from DT into Scrivener, or add a link to a DT document in the Scrivener Reference pane.

Frederiko

Thanks so much for this, @Frederiko. It’s a super useful way of thinking about workflow – and I really appreciate your thoughtful advice, as always. I agree that separating out DTP and Scrivner in the way that you’ve described seems like the way to go.

And yet…it still seems like it would be worth pursuing the first part of the query – i.e., a way to create some kind of automated process that merges documents in select tags into a unified “merged document,” and to update that merged document as new files are included in those tags…should this be achievable (and if one is able to address some of the potential pitfall that @korm and others pointed out). Essentially, I’m seeking a way to build on the workflow steps you (@Frederiko) generously described w/ the “Make an Annotation with Links, Notes, Tags v2” script (on and off the forum) – but just trying to create a more efficient / quasi-automated process for the “merge documents” part of that process. Make sense?

Thanks so much again for all of your incredible help and suggestions… Really helpful stuff – all of it!

This script works great! Thanks, @korm!

Quick question… Can direct the trigger script to save the output for merged items in another group (folder)? It’s not a problem if that’s not the case. If not, I suppose I could create Smart Groups to cull these merged documents by referencing “merged documents” name - does that sound about right? Also, is there a simple way to change the name of the merged documents so that it might include the name of the tag (in some way)? Again, no worries if it’s not possible - or if this is too troublesome. Just asking… I’m already loving this scrip. Huge thanks!

Oh, quickly… What’s the best place where these kinds of trigger scripts should be saved? Thanks again…

Thanks!

Yes – you can modify the script anyway you wish.

Same answer – anywhere you wish. There’s no “best place”. I save mine here – but just because I’m lazy


~/Library/Application Support/DEVONthink Pro 2/Scripts/Triggered

OK, thanks. I’ll look through the forum and try to figure out how to hobble something together. I’ve tried my hand at merging scripts, and it’s…pretty ugly! But I’ll give it a shot, and paste what I came up with here. Hope that’ll advance this process. And thank you again for your help @korm. It’s already super helpful.

Just to be clear, I was mostly wondering if it was best to accomplish the naming and file-saving tasks through a trigger script or through some other means (e.g., Smart Groups). That’s all.

Gotcha. Just didn’t want to store scripts in a place that might interfere w/ their functionality. Appreciate your help, again.

OK, thanks. I’ll look through the forum and try to figure out how to hobble something together. I’ve tried my hand at merging scripts, and it’s…pretty ugly! But I’ll give it a shot, and post what I come up with. Hope that’ll advance this process. And thank you again for your help @korm. It’s already super helpful.

Just to be clear, I was mostly wondering if it was best to accomplish the naming and file-saving tasks through a trigger script or through some other means (e.g., Smart Groups). That’s all.

Gotcha. Just didn’t want to store scripts in a place that might interfere w/ their functionality. Appreciate your help, again.

Just a quick question… Would it make sense to apply a trigger script on the merged file to automatically rename it (i.e., creating a or using a renaming script, so that it references the tag name of the files)? I thought that might be an easy solution. And one could perhaps cull these merged files by creating a Smart Groups folder that would reference the names (by tag - referenced names). Good solution or do you think there’d be an easier way to go? Just wondering before I set out to design this setup.

Thanks again…

I suggest starting a temp database and testing various options there. This way you can be flexible and agile in your attempts and not feel pressured to commit to a certain direction too quickly. (This will also keep you from borking your good data with a process that you committed to too quickly. :mrgreen: )

Thanks very much for your suggestion, @BLUEFROG. I’ve actually tested it quite a bit, and think it’s fluid (and mutable enough) to set up this system in the way that I’m comfortable with. Right now, I’m trying to figure out what kind of code to include into @korm’s trigger script so that I can change the merged file name so that it includes the tag name (e.g., instead of “6 merged documents” I’d like the file name to read "6 [tag name] merged documents - or some such naming schema). Of course, I’d still love also change teh script so I could direct it to save the file in a particular group (i.e., in a folder outside of of the tag to which it belongs)… Right now, changing the naming schema is the higher priority. Thanks again for your help and suggestion!

Just wondering if it’s possible to slightly amend this script so that it only creates a merged document when new documents are added to the tag. Thanks again for everyone’s help… Really appreciate it!

This would only be possible if you were periodically selecting the Tag you are monitoring, thus triggering the script. At this point in time (and technology) you are always going to need some User intervention with this.

Thanks for this. But I might be using tags in a different way than most DTP users. As I said at the top of the post, I’m using the following tagging script for my annotated files:

[url]Make an Annotation with Links, Notes, Tags v2]

…and @Frederiko’s workflow approach, some of which is described here:

[url]Make an Annotation with Links, Notes, Tags v2]
and here…
[url]Put up Example page]

As part of that process, one has to periodically tinker w/ and refine the files contained in the tags. It’s really a smart process. I was just seeking out the script as way to expidiate certain parts of the workflow process…