Advice needed: is it crazy to try and create a script to auto move files to folders based on prefix/name?

I still consider myself a beginner in AppleScript and scripting DT, but I felt this was a reasonable challenge and learning opportunity.

I would suggest looking at chrillek’s approach here: Script: Move records to groups according to tag.

However… I don’t know how many groups you have in your JD system, or how often you create new ones. It could be annoying to enter and update them all by hand, though it’s probably more performant.

Assuming you only have one group in the JD hierarchy with a name beginning with XX.XX, it seems easier to use the search command.

I don’t use JD, so I just created a few mockup groups to test. The following works, but I don’t know how well it scales:

Smart rule script (written for DT3):

-- File to Johnny.Decimal
on performSmartRule(theRecords)
	tell application id "DNtp"

		-- Get parent group or database of your Johnny Decimal system
		set JD_dir to get record with uuid "x-devonthink-item://..."
		
		repeat with theRecord in theRecords
			set theName to name without extension of theRecord as string
			
			-- Get decimal value (XX.XX at beginning of record name)
			set JD_rec to characters 1 thru 5 of theName
			
			-- Get name without `XX.XX--`
			set newName to characters 8 thru end of theName as string
			
			-- Find Johnny.Decimal group matching the file
			-- by searching and getting top result (there should only be one)
			set theResults to search "name:<" & JD_rec & " type:group" in JD_dir
			
			-- If there is a match, move file
			if theResults ≠ {} then
				set JD_group to the first item in theResults
				move record theRecord to JD_group
				-- Update filename
				set name without extension of theRecord to newName
			else -- If not, add message to log
				log message info "Johnny.Decimal location \"" & JD_rec & "\" does not exist" record theRecord
			end if
		end repeat
	end tell
end performSmartRule