Automatically deleting merged files

Hi,

I am using a custom merge function that was written [url]Default filename for merged files].

I was wondering if someone could help me on how to insert a subroutine that would delete the initially selected files once they are merged.

Thanks!

Thanks for quick response, but I think you misunderstood me. I want to delete the files that were used for merging, and not the newly merged file.

I tried setting the set theDeletedRecord to delete record theSelection, but it did not work.

Check this out: https://discourse.devontechnologies.com/t/merge-and-rename-and-delete-script/18769/1

Jim: I can’t access the forum bc it says i am not authorized to read it.

Sorry. Here.

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

tell application id "DNtp"
	
	if selection is {} then error "Select some documents"
	set theSelection to selection
	set numItems to the (number of items in theSelection) - 1
	set tempName to the name of the first item of theSelection & " - and " & (numItems as string) & " others"
	set mergedName to text returned of (display dialog "What is the name for the merged documents" default answer tempName)
	set mergedRecord to (merge records theSelection in current group)
	set the name of mergedRecord to mergedName
	
	repeat with thisItem in theSelection
		set deletedItem to delete record thisItem
	end repeat
	
end tell

Be aware that “delete” is irreversible. This is why in the original case of posting this solution I did not include the “delete” code. If you use this and your files are deleted permanently, you were warned.

This link leads to a page that says:

Ugh! Sorry - I got moving too fast with so many Tickets. Apologies.

You can use korm’s suggestion. Here’s my approach, if interested.
DT_Merge and Delete SN RO.scpt.zip (2.01 KB)

Sorry to resurrect a thread from 2016, but the script below contributed by @korm almost fits my need.

tell application id "DNtp"
	
	if selection is {} then error "Select some documents"
	set theSelection to selection
	set numItems to the (number of items in theSelection) - 1
	set tempName to the name of the first item of theSelection & " - and " & (numItems as string) & " others"
	set mergedName to text returned of (display dialog "What is the name for the merged documents" default answer tempName)
	set mergedRecord to (merge records theSelection in current group)
	set the name of mergedRecord to mergedName
	
	repeat with thisItem in theSelection
		set deletedItem to delete record thisItem
	end repeat
	
end tell

I would like the resulting merged document to have the same creation date as one of the merged PDFs. Assistance with the proper lines to add would be greatly appreciated.

Thanks…

(Sorry about the formatting of the script. I thought I had it figured out, but obviously I do not)

It’s three backticks (```) , then the code, then three backticks.

What do you mean by ”one of the merged PDFs”? How would the script know which PDF you’re referring to?

Thanks, Jim…the script looks much better since you modified it.

As for the date to apply to the merged document, I would be happy with the creation date of any of the merged PDFs as they’re usually within a a fairly confined range. Today’s Date just doesn’t work for me for the merged PDF.

You’re welcome.

You need to put the creation date of a selected file into a variable, then use the variable to change the creation date of the merged file.
Here is an adjustment of the existing script…

tell application id "DNtp"
	
	if selection is {} then error "Select some documents"
	set theSelection to selection
	set numItems to the (number of items in theSelection) - 1
	set tempName to the name of the first item of theSelection & " - and " & (numItems as string) & " others"
	set tempDate to creation date of the first item of theSelection
	set mergedName to text returned of (display dialog "What is the name for the merged documents" default answer tempName)
	set mergedRecord to (merge records theSelection in current group)
	set the name of mergedRecord to mergedName
	set the creation date of mergedRecord to tempDate
	repeat with thisItem in theSelection
		set deletedItem to delete record thisItem
	end repeat
	
end tell

Perfect, Jim!! It’s just what I need. Thank you again for your assistance.

All the merged documents in Evernote were deconstructed when imported into DEVONthink. I’m not going to re-merge all of them, but it will certainly make the process a lot easier for the ones I do.

I’ll keep your comment about setting the creation date to a variable in mind for future use.

You’re welcome :slight_smile: