I would also like to script links and couldnt find a way to do so. Perhaps someone of the DEVON staff could answer to this question.
Anyway if scripting links is not possible today it would be a good feature for a future release
Louise.
Well maybe this is what you want… Hackish, but whas funny !
How To:
This scripts assumes that
you have two windows open, one with a record named “RECORD1” , and another with a record named “RECORD1,comments”
“RECORD1” is the frontmost
you have something selected
the link to contextual menu is enabled
Side effects:
clipboard contents are lost
It will link the selection to RECORD1,comments; paste the selection in it and leave you staring at the end of RECORD1,comments
If it doesn’t find the second window, it’ll create a new record named “RECORD1,comments” in the top group
You have some customisations on the top of the code if you want to tinker a bit…
set commentSuffix to ",comments"
set commentsSeparator to "-----"
set comeBackToSource to false
to split(someText, delimiter)
set AppleScript's text item delimiters to delimiter
set someText to someText's text items
set AppleScript's text item delimiters to {""} --> restore delimiters to default value
return someText
end split
tell application "DEVONthink Pro"
activate
tell application "System Events"
keystroke "c" using command down
end tell
end tell
tell application "DEVONthink Pro"
activate
set srcw to front window
tell front think window
set src to content record
set n to name of (content record)
end tell
set w to first think window whose name contains n & commentSuffix
try
w
set tgt to (content record) of w
on error
set tgt to create record with {type:rtfd, name:n & ",comments"}
open window for record tgt
end try
set full_path_txt to location of tgt
set full_path to (my split(full_path_txt, "/"))
--remove first and last element
log (full_path)
set lastindex to (length of full_path) - 1
if lastindex > 2 then
set full_path to (items 2 through lastindex) of full_path
else
set full_path to {}
end if
set last_type to (name of tgt)
end tell
try
tell application "System Events"
set p to the first process whose name is "devonthink pro"
tell p
tell window 1
tell scroll area 2
tell text area 1
perform action "AXShowMenu" --> Menu comes up fine.
delay 0.1
keystroke "Link to"
delay 0.1
key code 124
repeat with p in full_path
log (p)
keystroke p
delay 0.1
key code 124
end repeat
keystroke last_type
key code 36
end tell
end tell
end tell
end tell
end tell
end try
tell application "DEVONthink Pro"
open window for record tgt
delay 0.2
tell application "System Events"
key code 125 using command down
key code 36
keystroke commentsSeparator
key code 36
keystroke "v" using command down
end tell
if (comeBackToSource) then
open window for record src
end if
end tell