Scripts for the toolbar: Attach tab & Detach tab

Here are two very simple little scripts that I find very useful to have in the toolbar.

Detach

This one will close the tab (in the think/viewer window) & open it in a new document window.

tell application id "DNtp"
	
	set theRecord to (content record of think window 1)
	set theTab to current tab of front window

	close theTab
	open tab for record theRecord
	
end tell

Attach

This one will close the document window (or the current tab in the document window) and open it in the first think window behind it (could be another document window or a viewer window).

tell application id "DNtp"
	
	set theRecord to (content record of think window 1)
	set theURL to the reference URL of theRecord
	set theTab to current tab of front window
	
	close theTab
	open tab for record theRecord in think window 2
	
	do shell script "open " & theURL	
	
end tell

If you prefer, you can download them.
Download: Attach tab.scpt
Download: Detach tab.scpt

Both are also present in the DEVONthink Window Manager for Alfred.

4 Likes

Thanks for the quite useful scripts! Here are some minor revisions which add error handling:

-- Detach tab

tell application id "DNtp"
	try
		if not (exists think window 1) then error "No window open."
		if not (exists content record) then error "No tab open."
		
		set theRecord to content record
		close current tab of think window 1
		open tab for record theRecord
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
	end try
end tell
-- Attach tab

tell application id "DNtp"
	try
		if not (exists think window 1) or not (exists think window 2) then error "Two windows are required."
		if not (exists content record) then error "No tab open."
		set theRecord to content record
		set theURL to the reference URL of theRecord
		close current tab of think window 1
		open tab for record theRecord in think window 2
		do shell script "open " & theURL
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
	end try
end tell
1 Like

Thanks a lot, Chris :slight_smile:

P.s.: I’ve updated the download files with Chris’ version.

We’ve just added them to the support assistant to make this easier :wink:

2 Likes

Hi

Just looking at the attach tab script, why do we need this line? Thanks!

Not sure about this as it’s from the original script by @Bernardo_V

This is for bringing the record/tab to the foreground.

The open tab for record theRecord in think window 2 command will leave it at the background. The following line, do shell script "open " & theURL, will bring it to the fore.

Thanks. I would never have known how to bring a tab to become the current tab because it seems that tab has no index property in DT dictionary! :+1: :+1:

1 Like

Never done this but it should be possible by setting it via id . However at the moment there seems to be a bug Open tab for doesn’t return a tab

Thank you so much for writing this script and including this feature - very useful to me! I see that you have some buttons in the first post - how did you get those buttons to appear?

You’re welcome. Just add the script to ~/Library/Application Scripts/com.devon-technologies.think3/Toolbar (change the icon if you want). Restart the program and then customize the toolbar.