Create new group when moving document from inbox?

Is there a way to create a new group in DT when moving a document from the inbox, so that the document will move into the new group?

In finder, I use the “New Folder” item all the time to create a new folder to place a document in. In DT, I have to review the document, look for a group, and if there’s not already a group to move it to, then I have to create a new group in the right location, then go back and move the document into the group. Is this the only way to do it?

I don’t want to just throw everything together in one group and depend on search to retreive it later. I like using hierachical groups and want to file documents in a way that would easily transfer out of DT and into finder if I desire later.

Thanks for your help,

Jim

You can select the new document in the Inbox and right click > Group Items. This creates a new group in the Inbox with the selected items — with one item the group has the same name, with more than one, you’ll have to name it explicitly.

Then you can move the new group into the preferred location in the normal way.

Does that help?

1 Like

Yes, an AppleScript with display group selector can do that.

A simple version could look like this:

-- Move records

tell application id "DNtp"
	try
		set theRecords to selected records
		if theRecords = {} then error "Please select some records"
		
		set theGroup to display group selector "Move to:"
		
		repeat with thisRecord in theRecords
			move record thisRecord to theGroup
		end repeat
		
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
		return
	end try
end tell

But such a simple version doesn’t consider some (edge) cases. We would e.g. lose replicants if we were using the simple version with a selection while DEVONthink shows search results.

Here’s (almost) the version I use. This script additionally checks some other things but you probably won‘t notice that. With that version all potentially harmful cases are covered, I think.

-- Move records

use AppleScript version "2.4"
use framework "Foundation"
use scripting additions

property openGroup : false

tell application id "DNtp"
	try
		set theRecords to selected records
		if theRecords = {} then error "Please select some records"
		
		set theRecords_NonIndexedNonReplicants to selected records whose indexed = false and number of replicants = 0
		
		if theRecords_NonIndexedNonReplicants ≠ {} then
			set theRecords_CantMove to selected records whose (indexed = true) or (indexed = false and number of replicants > 0)
			set theGroup to display group selector "Move to:"
			if my checkLockedGroup(theGroup) = false then
				display alert "Canceled" buttons {"Ok"} default button 2 message "Moving canceled: Group is locked folder" as critical
				return
			end if
			
			show progress indicator "Moving... " steps (count theRecords) as string with cancel button
			
			repeat with thisRecord in theRecords_NonIndexedNonReplicants
				step progress indicator (name of thisRecord as string)
				move record thisRecord to theGroup
			end repeat
			
			if openGroup then
				open window for record theGroup with force
				activate
			end if
			
			if theRecords_CantMove ≠ {} then
				set theRecords_CantMove_Count to (count theRecords_CantMove)
				if theRecords_CantMove_Count = 1 then
					set theText to " Record is indexed or replicated"
				else
					set theText to " Records are indexed or replicated"
				end if
				my showRemaining(theRecords_CantMove, ("Moving: " & (theRecords_CantMove_Count as string) & theText))
			end if
		else
			display alert "Canceled" buttons {"Ok"} default button 2 message "Moving canceled: All records are indexed or replicated" as critical
			return
		end if
		
		hide progress indicator
	on error error_message number error_number
		hide progress indicator
		if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
		return
	end try
end tell

on checkLockedGroup(theGroup)
	try
		tell application id "DNtp"
			try
				if indexed of theGroup = true then
					set thePath to path of theGroup
				else
					set thePath to missing value
				end if
			end try
		end tell
		if thePath ≠ missing value then
			set theDirectory_Attributes to (current application's NSFileManager's defaultManager's attributesOfItemAtPath:(thePath) |error|:(missing value))
			if ((theDirectory_Attributes's objectForKey:(current application's NSFileImmutable)) as boolean) = true then
				set isNotLocked to false
			else
				set isNotLocked to true
			end if
		else
			set isNotLocked to true
		end if
		return isNotLocked
	on error error_message number error_number
		activate
		display alert "Error: Handler \"checkLockedGroup\"" message error_message as warning
		error number -128
	end try
end checkLockedGroup

on showRemaining(theRecords, theMessage)
	tell application id "DNtp"
		try
			set search results of (open window for record (root of inbox) with force) to theRecords
			activate
			display alert "These records couldn't be moved" buttons {"Ok"} default button 2 message theMessage as informational
			
		on error error_message number error_number
			activate
			display alert "Error: Handler \"showRemainingRecords\"" message error_message as warning
			error number -128
		end try
	end tell
end showRemaining

I use an applescript to assist with processing Inbox items
This includes title, tags, … and moving out of the Inbox
The script could also include creating a group

Just curious as to the use case for this
Most of my notes are stored as single entries in the Filing Cabinet group

Yes, thank you! That makes it much easier than doing it the way I was.

1 Like

Pete,

Thanks so much, but I know nothing about scripts! I don’t have any idea of how I’d implement this …

Jim

  • Copy script
  • Open Script Editor.app
    e.g. via Spotlight
  • Paste script
  • Save with extension scpt to desktop
  • In DEVONthink use the script menu to reveal the script folder
  • Move script into DEVONthink‘s script folder
1 Like

Thank you for the very clear description of how to do this!

1 Like