select or action on the latest import/ first doc in inbox

Hi,
first of all I hope, that this posting will not be regarded as double post. I already asked it in the German board, as my english is as bad that i doubt to be able to express myself well.
As i did not get an answer there i try my luck here. I hope its ok, otherwise i excuse honestly!

I am busy to make DEVONthink Pro fit to my office workflow, what does great, as i see it.

I rarely batch import but do it file by file and on the other hand quickly forget :slight_smile:) ,
So my workflow is to immediately after the import work on the files.
I move the files into a collection folder that I have defined , and, from there move them automatically into the respective database and its inbox. After that the “information” panel pops up (i don’t know ow to call another label by script that only offers renaming and tagging, that is what i need).

I wrote an aplescript and defined as folder action.
Open DT , start right DB , bring window to the front , OCR if necessary, all that works fine. Also to open “show info” for editing name and tags works,

but I still have to manually set the currently imported document as selected (by mouse / trackpad) , because it is not marked.

Can I automate this step somehow?
So that DEVONthink automatically " highlights " or marks the document or “chooses” , which was currently and recently imported, or is on first place in the active databases inbox
or DEVONthink automatically opens “show info” panel on this latest imported or first placed document of active database inbox?

My script knowledge is not good enough, to achieve that.

I hope, i could describe, what i meant…

Thank you!
Christoph

You would need to use GUI scripting – AppleScript commands that tell the user interface to do actions. macscripter.net and macosxautomation.com both have examples. Or, your could merely press the keyboard shortcut for Tools > Show Info… (depending on your localization) immediately after you run your script.

Some actions are already available and not worth automating :wink:

First of all thanks for your reply.

What i wrote about “information” was meant to be the “show info” , i corrected that above. Sorry, i use a german localization and did not know the correct term in english.

I can open it and do so, but it is open for the inbox, as the inbox is selected after the import.
My try is to set that selection to the document so the “show info” is showing the info of the imported file instead of the info of the inbox (what is done by cmd opt 1). I am looking for a way to address the latest import or top placed file in this inbox.

this is, what i use at the moment:


on adding folder items to this_folder after receiving added_items
	try
		if (count of added_items) is greater than 0 then
			tell application id "DNtp"
				launch
				open database "/path/to/my/database"
			end tell
			repeat with theItem in added_items
				try
					set thePath to theItem as text
					if thePath does not end with ".download:" and thePath does not end with ".crdownload:" then
						tell application id "DNtp"
							if thePath ends with ".pdf" then
								set theRecord to ocr file thePath to incoming group
							else
								set theRecord to import thePath to incoming group
							end if
							if exists theRecord then tell application "Finder" to delete theItem
							set miniaturized of windows to false
							activate
						end tell
						tell application "System Events" to keystroke "1" using {command down, option down}
						tell application "System Events" to keystroke "i" using command down
					end if
				end try
			end repeat
		end if
	end try
end adding folder items to

I believe you would want to set the focus by doing something like this


set theTab to open tab for theRecord in think window 1

I would put that as the last statement just before the DEVONthink tell ends.

yes something like that. Sounded great!

unfortunately this too does not work I cannot see that it takes any effect. The selection is not altered at all, unlike in the “keystroke” setting i use at the moment to - at least- select the inbox of the actual database.

in apple scripts function library of DTPO I found the property of record: addition date
i would understand how o work with it when its selected, but how to set it as selected ?

isn’t there any way to select a file in inbox?
or to open a tag and rename dialogue of the file after its import?

If we scan to DEVONthink, the settings allow to set such a routine.
to open something like that on an imported file is my idea, to avoid clicking

A word of advice: When scripting you should not think about selections unless they are made before the script runs. Also, don’t think about views, like how a window is sorted, trying to select the topmost item, etc.
GUI scripting is notoriously finicky and unreliable. It is always better to deal with files based on metadata, whether it be a name or deeper metadata. Does this mean some things can’t be automated? Sometimes… but as korm points out, sometimes it not worth automating.

Hello Jim,

thanks for your advice and hints. I already had understood korm and your hint too about “worth” of automation and are sorry if I bored or disturbed. That has not been my intention, sorry.
It is just that for me it would be worth it and hoped, that one of you knows a way how to adress the most recently imported file to show a dialogue for renaming and tagging like it works, in case they are imported by scan.

I have not been aware of the fact that it is impossible or not worth the effort for others,

However, I am grateful for the effort both of you took, to answer me. Many thanks for that and a happy Easter

Christoph

“Open Tab” should be working – here are some examples:

devon-technologies.com/scrip … 642#p49846

and the Merge Highlights scripts available from Scripts > More Scripts…, or if you’ve already installed them, from Scripts > Data

I spent a few hours trying to make your script work and ran out of time. I think that trying to make the Folder Action Dispatcher, System Events, Finder, and DEVONthink all work together to cause a document to open and then Get Info appear might be causing a conflict. I have not been able to discover a solution in that direction.

However, the following script will work to import the document(s), then prompt for name and then prompt for the tags (for one or more documents). It just doesn’t turn the focus to the last one renamed. That part has me stumped. Since you don’t want any more help, I’ll just stop here. :confused:

on adding folder items to this_folder after receiving added_items
	try
		if (count of added_items) is greater than 0 then
			tell application id "DNtp"
				launch
				open database "/path/to/database"
			end tell
			repeat with theItem in added_items
				try
					set thePath to theItem as text
					if thePath does not end with ".download:" and thePath does not end with ".crdownload:" then
						tell application id "DNtp"
							if thePath ends with ".pdf" then
								set theRecord to ocr file thePath to incoming group
							else
								set theRecord to import thePath to incoming group
							end if
							
							-- we change the record's name
							set theName to the name of theRecord
							set theNewName to display name editor default answer theName
							set the name of theRecord to theNewName
							
							-- we add tags to the record
							set theTag to display name editor "Add Tags" info "Tags (separated by semicolons):"
							set {od, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ";"}
							set theTags to text items of theTag
							repeat with theRecord in theSelection
								set tags of theRecord to (parents of theRecord) & theTags
							end repeat
							set AppleScript's text item delimiters to od
							
							-- we eliminate the old file in the file system
							if exists theRecord then
								tell application "Finder" to delete theItem
							end if
						end tell
					end if
				end try
			end repeat
		end if
	end try
end adding folder items to

I am so grateful korm!

of course i want and need more help :slight_smile: I just got afraid to appear impolite regrading the last postings.

I will try to combine and develop the approach, you offered. And will keep you informed if i succeeded? But please if you like to develop too, i would appreciate so high!!

many thanks!!

Christoph

it is the tagging, that does not take effect and thereby stops the script.

If i leave it out, it runs so far.

unfortunately still the recent import is not selected, so i have to go manually there, to finish my work.
I am astonished, that its so difficult to set a selection there.

The tagging works fine over here. Check your code.

I wouldn’t be astonished. You are trying to do a task with code that can be done already with the keyboard with no additional work – so it is sort of like writing a program just because we can, not because we need to.

Anyway, enough time spent already. I’m signing off from this thread. Good luck.

if so, i would not know the shortcut (if it would exist, i could call it)

i use the three divided workspace usually.
I can move by keyboard, as soon as i set the mark of highlight in the upper right area, the one above the preview.
but how to change from the folder column right into that area i do not know. Is there a shortcut?

I really appreciate your patience korm. I wish i can ever try to help you too.

and again you have been right corm.

switching to the twin split view allows to enter the inbox with a shortcut.

I call it and get my file selected to edit it.

You helped me a lot. Many thanks for your kind, patient and competent help