Dear DTP programmers,
Why is it so hard to fix this? Your inattention to such a simple problem has forced me to solve it myself, with an AppleScript workaround. The actual code is between lines of asterisks (don’t copy the asterisks into your scripts).
(1) Make a folder called “Other” in your HOME SCRIPTS FOLDER (~/Library/Scripts/). Save the following therein as “DT_props.scpt”:
property newDevonList : {}
property oldDevonList : {}
SAVE THE FOLLOWING THREE SCRIPTS IN YOUR DTP SCRIPTS FOLDER (~/Library/Application Support/DEVONthink Pro 2/Scripts):
(2) This one SAVES all open window information. Save the following as “saveWins.scpt”:
set scripts_path to (path to scripts folder) as string
set propScriptPath to scripts_path & “Other:DT_props.scpt”
set propScript to load script file propScriptPath
set win_list to newDevonList of propScript
tell application “System Events” to set visible of process “DEVONthink Pro” to true
tell application id “com.devon-technologies.thinkpro2”
copy win_list to old_list
copy win_list to new_list
copy windows to raw_wins
set all_wins to {}
repeat with next_win in raw_wins
try
set next_id to id of next_win
if next_id is not -1 then
log "MADE IT"
set end of all_wins to next_win
end if
end try
end repeat
set next_props to {}
repeat with next_win in all_wins
set counter to 0
set prop_index to 0
set next_id to id of next_win
set next_name to name of next_win
set next_bounds to bounds of next_win
try
set next_root to root of next_win
on error
set next_root to -1
end try
-- ERROR: Can’t make «class DTpr» id 2.147483645E+9 of ...
-- log "NEXT ROOT: " & next_root
try
log "NEXT ROOT: " & next_root
end try
if next_name is not "" then
log "GOOD WINDOW"
set next_props to {next_id, next_name, next_bounds, next_root}
-- Find index of prop-list to replace.
repeat with next_old_prop in old_list
set counter to counter + 1
if (item 4 of next_old_prop is next_root) then
set prop_index to counter
exit repeat
(* This was making too many dupes.
if (item 4 of next_old_prop is next_root) and ¬
(next_old_prop contains next_name) then
set prop_index to counter
exit repeat
*)
end if
end repeat
if prop_index is 0 then
set end of new_list to next_props
else
set item prop_index of new_list to next_props
end if
end if
end repeat
end tell
set newDevonList of propScript to new_list
store script propScript in file propScriptPath with replacing
show_list(new_list)
on show_list(the_list)
set show_string to “”
repeat with next_list in the_list
set next_id to item 1 of next_list
– set next_name to item 2 of next_list
set AppleScript’s text item delimiters to {" — “}
set next_name to item 2 of next_list
if text item 1 of next_name is “KantDiss” then
try
set next_name to text item 2 of next_name
end try
end if
set AppleScript’s text item delimiters to {”"}
– set AppleScript’s text item delimiters to {" “}
set next_bounds to (item 3 of next_list)
set x1 to item 1 of next_bounds
set y1 to item 2 of next_bounds
set x2 to item 3 of next_bounds
set y2 to item 4 of next_bounds
set next_root to item 4 of next_list
set show_string to show_string & next_name & " "
– " (” & x1 & “,” & y1 & " • " & x2 & “,” & y2 & “)” & return
end repeat
display dialog show_string
end show_list
(3) This one RESTORES all window sizes and positions. Unopened windows are, of course, ignored. Save the following as “restoreWins.scpt”:
set scripts_path to (path to scripts folder) as string
set propScriptPath to scripts_path & “Other:DT_props.scpt”
set propScript to load script file propScriptPath
set win_list to newDevonList of propScript
tell application “System Events” to set visible of process “DEVONthink Pro” to true
tell application id “com.devon-technologies.thinkpro2”
copy windows to raw_wins
set all_wins to {}
repeat with next_win in raw_wins
try
set next_id to id of next_win
if next_id is not -1 then
log “MADE IT”
set end of all_wins to next_win
end if
on error
set next_id to -1
end try
end repeat
repeat with next_old_list in win_list
set old_id to item 1 of next_old_list
set old_name to item 2 of next_old_list
set old_bounds to item 3 of next_old_list
set old_root to item 4 of next_old_list
set counter to 0
repeat with next_win in all_wins
set counter to counter + 1
try
set next_root to root of next_win
on error
set next_root to -1
end try
-- if (name of next_win is old_name) and (next_root is old_root) then
if (next_root is old_root) then
if (name of next_win is old_name) then
set bounds of next_win to old_bounds
end if
(*
-- Prevents all orphans from getting same resize.
if (next_root is -1) then
if (name of next_win is old_name) then
set bounds of next_win to old_bounds
end if
else
set bounds of next_win to old_bounds
end if
*)
(*
if counter is 1 then
set all_wins to (items (counter + 1) thru end) of all_wins
else if counter is (count of all_wins) then
set all_wins to (items 1 thru (counter - 1)) of all_wins
else
set all_wins to (items 1 thru (counter - 1) of all_wins) & (items (counter + 1) thru end) of all_wins
end if
*)
log "COUNT: " & (count of all_wins)
end if
end repeat
end repeat
end tell
(4) This one SHOWS all open window information. Save the following as “showWins.scpt”:
set scripts_path to (path to scripts folder) as string
set propScriptPath to scripts_path & “Other:DT_props.scpt”
set propScript to load script file propScriptPath
set win_list to newDevonList of propScript
show_list(win_list)
on show_list(the_list)
set show_string to “”
repeat with next_list in the_list
set next_id to item 1 of next_list
– set next_name to item 2 of next_list
set AppleScript’s text item delimiters to {" — “}
set next_name to item 2 of next_list
if text item 1 of next_name is “KantDiss” then
try
set next_name to text item 2 of next_name
end try
end if
set AppleScript’s text item delimiters to {”"}
– set AppleScript’s text item delimiters to {" “}
set next_bounds to (item 3 of next_list)
set x1 to item 1 of next_bounds
set y1 to item 2 of next_bounds
set x2 to item 3 of next_bounds
set y2 to item 4 of next_bounds
set next_root to item 4 of next_list
set show_string to show_string & next_name & " "
– " (” & x1 & “,” & y1 & " • " & x2 & “,” & y2 & “)” & return
end repeat
display dialog show_string
end show_list
Come on programmers! How hard can this be to fix? I can’t believe no one can figure this out. Would you like to send me the code? Please let me know. The fact that I have to run a position-saving and a position-restoring script manually is really sad. This problem is over six months old and NOTHING has been done. Each update is as dysfunctional as the last.