Destination Global Inbox in scripts without prompt

I have selected “Select group” in DEVONthink’s settings because I immediately want to sort the incoming stuff, at most PDFs from Safari webpages via the extension or Print to.

That works all just fine. Now I have set up a move action in a script and, unlike the Smart Rule move action, when I select the Global Inbox as the destination, I get prompted for the destination, the tags, etc. Which is not what I want. I have set the destination to the Global Inbox on purpose and the move action is part of a Smart Rule that should run quietly in the background.

Can you change that behaviour and make the destination setting in scripts independent from the setting for bookmarklets, services, etc.? Or is there already a way to send a record to the Global Inbox without prompting?

Could you please post the complete script?

Script will follow later. But I can report that I got stuck at another obstacle that might be related:

I tried the script with a test database, moving records from one folder to the other, creating PDFs from urls, deleting the source files etc. And it worked.

Actually it worked that good that I dared to let it out to the open. But the files it is supposed to work on are now indexed and that causes a lot of trouble. The Smart Rule the script is supposed to replace has a Move into Database action, the script not. Is there any Apple Script command for it? I did not find it in the dictionary.

See consolidate command.

Okay, here’s the script. Please don’t laugh if it contains ridiculous mistakes. I’m still an Apple Script novice and the script is not finished yet—if it is I’d gladly share it if there is any interest in it. It does work though, at least with internal groups.

What it is supposed to do:

  • It is executed by a Smart Rule, conditions: Kind is MD or Plain Text.
  • When the MD file contains just simple text (exceptions below) the scripts converts it to RTF and moves it to its destination (Global Inbox), the original MD file gets deleted.
  • When it contains an MMD footnote (starts with “[^”) it is kept as MD and moved to its destination.
  • When it contains a URL the scripts creates a paginated and clutter-free PDF from it and moves it to the destination. The original MD file gets deleted.
  • For all three of them: The script looks for a paragraph with hashtags. If found, the hashtags are turned into tags and the hashtag line gets removed.
  • When MultiMarkdownMetadataOff is true the possible/alleged MMD metadata (colon in at least the first paragraph) gets ignored. Method: I add an empty paragraph to the beginning of the text.
  • Some polishing of the MD file: double returns after every paragraph (I’m too lazy to actually type them).
  • Just planned: When MultiMarkdownMetadataOff is false the script checks the first and possibly subsequent paragraphs for “something: something” structures and turns them into actual record metadata or record custom metadata. Afterwards the MMD metadata gets deleted or not, dependent on another setting.
  • Also just planned: Allow text in MD files with URL and add the text to the created PDF. Annotations do not work with PDF according to the dictionary. Comments didn’t work either. Where to put the—commenting—text?
on performSmartRule(theRecords)
	tell application id "DNtp"
		
		set theDestination to inbox -- create location "/A Group" in database "Test Database 1"
		
		set MultiMarkdownMetadataOff to true
		
		repeat with theRecord in theRecords
			
			set thePlainText to the plain text of theRecord
			
			if (thePlainText is "") then
				delete record theRecord
			else
				
				set theParagraphs to paragraphs of thePlainText
				set theLastParagraph to length of theParagraphs -- count?
				set theName to "Test v6.0"
				set theTags to tags of theRecord
				
				set theHashtagLine to my findHashtags(theParagraphs, theLastParagraph)
				
				if (theHashtagLine is not 0) then
					set theHashtags to item theHashtagLine of theParagraphs as string
					set theHashtags to characters 2 thru (length of theHashtags) of theHashtags as string
					set theTags to theTags & my splitText(theHashtags as string, " #")
					set theParagraphs to my removeHashtags(theParagraphs, theLastParagraph, theHashtagLine)
				end if
				
				set theBeginning to ""
				if (length of item 1 of theParagraphs ≥ 4) then set theBeginning to characters 1 thru 4 of item 1 of theParagraphs as string
				
				if (theBeginning is "http") then
					
					set theURL to item 1 of theParagraphs
					set theNewDocument to create PDF document from theURL in theDestination name theName with readability and pagination
					set tags of theNewDocument to theTags
					delete record theRecord
					
				else
					
					set thePlainText to my plainTextRevisited(theParagraphs)
					if MultiMarkdownMetadataOff then set thePlainText to return & thePlainText
					set plain text of theRecord to thePlainText
					
					set MultiMarkdownFootnotes to offset of "[^" in thePlainText
					
					if (MultiMarkdownFootnotes is 0) then
						
						set theNewRecord to convert record theRecord in theDestination to rich
						set tags of theNewRecord to theTags
						delete record theRecord
						
					else
						
						set tags of theRecord to theTags
						move record theRecord to theDestination
						
					end if
					
				end if
				
			end if
			
		end repeat
		
	end tell
end performSmartRule


on splitText(theText, theDelimiter)
	set AppleScript's text item delimiters to theDelimiter
	set theTextItems to every text item of theText
	set AppleScript's text item delimiters to ""
	return theTextItems
end splitText


on findHashtags(theParagraphs, theLastParagraph)
	repeat with p from 1 to theLastParagraph -- count?
		if (length of item p of theParagraphs ≥ 2) then
			if ((character 1 of item p of theParagraphs is "#") and (character 2 of item p of theParagraphs is not " ")) then return p
		end if
	end repeat
	return 0
end findHashtags


on removeHashtags(theParagraphs, theLastParagraph, theHashtagLine)
	set theInterimParagraphs to {}
	repeat with p from 1 to theLastParagraph
		if (p is not theHashtagLine) then set theInterimParagraphs to theInterimParagraphs & item p of theParagraphs
	end repeat
	set theLastParagraph to theLastParagraph - 1
	return theInterimParagraphs
end removeHashtags

on plainTextRevisited(theParagraphs)
	set theInterimPlaintext to ""
	repeat with p from 1 to count of theParagraphs
		if (item p of theParagraphs is not "") then set theInterimPlaintext to theInterimPlaintext & item p of theParagraphs & return & return
	end repeat
	return theInterimPlaintext
end plainTextRevisited

It’s probably this line, the inbox is a database but not a valid destination (group):

		set theDestination to inbox -- create location "/A Group" in database "Test Database 1"

Changing it to this should work:

		set theDestination to root of inbox

Thank you, that did it. That simple!

It’s always the syntax I’m fighting with. Lots of trial and error, most of the time I get it right after several attempts, but sometimes not.