Christian, thank you for listening and for your thoughts …I look forward to DTpro 2 and to be be able to restore the selection!
I should mention that I found a bit of a workaround in the meantime, which is to invoke the progress indicator. Your suggesting about queueing led me to experiment with what might change that queue relation. This script still only sort of works, in that it loses focus on the bottom window in a three-pane setup. But it does at least keep the focus on the left pane. Or at least that’s my experience right now.
The script below detects the current text selection, and then opens up “research” browser windows in the background. It’s handy to look a few things up while writing…if anybody thinks it useful, I can post it to a separate forum post.
For the sake of documenting the issue though, let me make a note here…As you can see there are some comments down toward the end of the script that tried to restore the selection…none of those work. I’d like to add here again that the ability to create a record without changing the selection might be the quickest fix to all these issues. But it is probably worth mentioning that given the way that the “get selected text” is set up, it doesn’t seem like it will be able to be restored without changing the scripting vocabulary. Ideally, “get text selection” would give a list, something like “characters 23 through 50 of text of thinkwindow 1”, but right now it gives just text. I assume that we would need a “get text selection range” command or something to do a proper restore on that. Seems to me that that is an an analog to the need for a “set selection of left/top pane” commands… Sorry to add to your list, Christian, but dt is so amazingly scriptable that these little things can get you down… much appreciation for all your work.
Okay, enough of the tedious debugging kvetching, here’s the promised Create “research browsers” from current text selection script:
---Create Search Browsers from Selected Text
----this script detects the selected text of the current document and creates three records in the same group as the current document
----these records are searches at google, wikipedia, and britannica.
----version 1.0
--- This version is a bit hack-ish.
----the script has to do a little trickery to try to get devonthink pro to remember your selection.
----It basically opens up a new database window while it creates the records and then closes that window.
----you might need to change the timing of the two delay statements if your machine is too fast
try
set the_clipboard to ((the clipboard as text))
on error
set the_clipboard to ""
end try
log the_clipboard
tell application "DEVONthink Pro"
if not (exists (think window 1)) then error "No window is open."
set the_Window to viewer window 1
--get essential devonthink information
--first use a list to avoid the dreaded " variable is not defined" error
set devon_info to {selection of the_Window, incoming group, selected text of the_Window, selected text of think window 1, content record of the_Window}
log devon_info
repeat with this_item in devon_info
log class of this_item
end repeat
if class of item 3 of devon_info is not application then --tests if we have a text selection
set the_text to item 3 of devon_info
else if class of item 4 of devon_info is not application then
set the_text to item 4 of devon_info
else
set the_text to text returned of (display dialog "Please enter the text you would like to search for" default answer the_clipboard)
end if
log "selected text is " & the_text
set the_think_window to get think window 1
set the_root to root of database 1
if class of item 2 of devon_info is not application then
set insert_location to incoming group of database 1
log "setting to incoming group"
else if ((class of item 1 of devon_info) as string) is "list" then --do we have a record selected ?
try
set insert_location to first parent of content record
set the_selection to selection
on error
set insert_location to the_root
end try
end if
show progress indicator "Creating research browsers...." steps 5
----------
(* (invoking the progress indicator seems to do the same thing)
----starting part of selection workaround
set temp_window to open window for record the_root
set visible of temp_window to false
delay 4
*)
-------
log the_text
set window_count to count of windows
-------browser creation 1 : make as many of the following browser creation blocks as you wish------
set the_record to create record with {type:link, URL:("http://www.google.com/search?q=" & the_text) as string, name:(the_text & ": google " as string)} in insert_location
set window_count to window_count + 1
set window_1 to open window for record the_record
set index of window_1 to window_count
step progress indicator
-------browser creation 2 : make as many of the following browser creation blocks as you wish------
set the_record to create record with {type:link, URL:(("http://www.wikipedia.org/wiki/" & the_text) as string), name:the_text & ": wikipedia: "} in insert_location
set window_count to window_count + 1
set window_1 to open window for record the_record
set index of window_1 to window_count
step progress indicator
-------browser creation 3 : make as many of the following browser creation blocks as you wish------
set the_record to create record with {type:link, URL:(("http://search.eb.com/search?query=" & the_text) as string), name:the_text & ": britannica "} in insert_location
set window_count to window_count + 1
set window_1 to open window for record the_record
set index of window_1 to window_count
step progress indicator
---ending part of selection workaround (invoking the progress indicator seems to do the same thing)
(*delay 2
close temp_window *)
----------------
delay 1
hide progress indicator
-----reset selection graveyard-----
---the following bits of code don't seem to work.
---This one seems to be a simple bug:
if item 1 of devon_info is not application then
set selection of the_Window to the_selection
end if
set index of the_Window to 1
----The following one seems it would never work because "selected text" doesn't return a text container, but rather the contents of the selection (i.e. the actual text, not a position)
----set selected text of the_think_window to the_text
---A list of other possibilities that were guesses at what might be plausible, but they don't work either...... :-(
---set selection of window 1 to insert_location
--set selection of viewer window 1 to {content_record}
---set (selection of viewer window 1) to the_selection
--set selection of viewer window 1 to {the_record}
end tell