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
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
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.
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.