Referenced by - a GUI script

This little script will create a link, then put the doc that you linked from as an internal reference in the doc you link to. There have been some obstacles, so this not very elegant, but reasonably quick on my Mac. Any improvements welcomed!

activate application “Scrivener”
tell application “System Events”
tell process “Scrivener”
keystroke “b” using {control down, option down, command down}
key code 123 using {control down, command down}
keystroke “e” using {control down, option down, command down}
keystroke “l” using {command down}
click menu button “dummy” of group 1 of group 1 of splitter group 1 of splitter group 1 of window 1
click menu item “Add Internal Reference” of menu 1 of menu button “dummy” of group 1 of group 1 of splitter group 1 of splitter group 1 of window 1
click menu item 3 of menu 1 of menu item “Add Internal Reference” of menu 1 of menu button “dummy” of group 1 of group 1 of splitter group 1 of splitter group 1 of window 1
keystroke “b” using {control down, option down, command down}
key code 124 using {control down, command down}
keystroke “r” using {control down, option down, command down}
delay 0.1
click button 3 of splitter group 1 of splitter group 1 of splitter group 1 of window 1
end tell
end tell

I should add that this is written for items in the research folder. To quicken things, the script will temporarily outdent your item, then put it back as the last item of the research folder. For this to work, your research folder must be the second folder, after Draft.