Open Multiple Documents in Different Tabs of Same Viewer/Window

I am almost embarrassed to ask this question after so many years using Devonthink - but I cannot find the answer searching documentation and the only query I can find in the Forums goes back over a decade ( Reading Multiple Files ).

Is it possible to select multiple documents and then have them all open with each one as a different tab in the same window/viewer?

I know it is possible to do this and have each one as a new window; but it would be very convenient to have the option for them to stay in one window but with different tabs.

See Data > Open in Tabs while pressing the Option modifier key. Shortcut Cmd-Opt-O.

1 Like

Thank you - that is helpful.

Can I then move those tabs to a separate window? Devonthink Help suggests I can use Window/Move Tab to New Window but I cannot find that option nor can I highlight multiple tabs with Cmd. Is this response hallucinated?

No. It’s only possible to reorder them via drag & drop.

1 Like

OK thanks

I am a bit surprised the request has not come up before

Especially as larger monitors and multi-monitors have become more common, being able to have a freefloating window with a set of related documents would be very useful.

Is this doable in a script? I may give that a try.

See menu Help > Support Assistant.

Under Install Extras in the Scipts section you’ll find the Attach Tab and Detach Tab scripts.

If you open an additional viewer window before using the Detach Tab script it should do what you’re looking for.

1 Like

Thanks @pete31 - That works to detach 1 tab but how do I detach/move multiple tabs into the new window?

Run the script a second time

1 Like

Yes that will work

I am thinking about cases where I may have 10 documents to open - would be really nice to do that with 1 click.

I, to open several DT4 files selected in different windows, use the following script:

tell application id "DNtp"
	set theSelection to the selection
	repeat with theRecord in theSelection
		open tab for record theRecord
	end repeat
end tell

tell application id "DNtp"
	if not (exists main window 1) then
		display alert "No viewer window is open. Please open one and select files."
		return
	end if
	set theSelection to the selection
	if theSelection is {} then
		display alert "No documents selected in DEVONthink."
		return
	end if
	repeat with theRecord in theSelection
		try
			open tab for record theRecord in main window 1
		end try
	end repeat
end tell

They are two different scripts: one for opening the files in separate windows and the other in separate tabs.

This opens selected records as tabs in the same new document window:

(() => {
const app = Application("DEVONthink");
const sel = app.selectedRecords();
const r = app.contentRecord();
if (sel.length > 1 || sel[0]?.id() === r?.id()) {
 const w = app.openTabFor({ record:sel.shift() }).thinkWindow();
 sel.forEach(r => app.openTabFor({record:r, in:w}));
}
})()
1 Like

@troejgaard

That works really well - many thanks

You’re welcome!
I was a bit too quick, though. If you have only one record selected and it’s displayed in the current tab, the script above doesn’t close the original tab. This should do it:

(() => {
const app = Application("DEVONthink");
const sel = app.selectedRecords();
if (sel.length > 0) {
 const tab = app.thinkWindows[0].currentTab;
 const r = tab.contentRecord();
 if (r?.id() === sel[0].id()) tab.close();
 const w = app.openTabFor({ record:sel.shift() }).thinkWindow();
 sel.forEach(r => app.openTabFor({record:r, in:w}));
}
})()

The id property is not intended for public access, I was told. Better use uuid, perhaps.

A window id is also variable.

Is it just that id is not persistent like uuid is, or is there more to it?
But sure, uuid would fill the same role here. It’s just that comparing two object specifiers that look identical doesn’t work, it always returns false. So you have to compare some property instead, at least from what I can tell. (I guess comparing the string from getDisplayString also works). I just went with id since that’s what I saw in the log.

It does work in AppleScript, however:

A think window doesn’t have a uuid and the id is mutable.

I’m not comparing windows. And I don’t need the id to be persistent in this scenario, I just need the comparison to work.

Is it just a rule of thumb to avoid using id if you can do without it?

I don’t have any mandates against it but it’s generally not used.