Guest
2012-11-13, 06:12 AM
Code:
-- JUMPS TO TARGET OF BOOKMARKS - USE IN CONJUNCTION WITH CreateBookMks.scpt
-- If, before you run this script, you select a bookmark from the bookmarks section at the end of the document,
-- then the script will immediately select the target of the bookmark.
-- Otherwise, the script will first offer a menu of the available bookmarks.
property pSection : "Bookmarks"
property pTitle : "Go to"
property pVer : ".05"
-- .02 Uses hoist/unhoist to jump to relevant page before selecting
-- .03 Allows for the presence of comment text after the id in the note of a bookmark
-- .04 Slight adjustment to menu to facilitate keyboard use (and error handling when bookmark list is empty)
-- .05 Aims to use a menu unhoist to scroll to the bookmarked row
GoTo()
on GoTo()
tell application id "OOut"
if (count of documents) < 1 then return
tell front document
set blnFound to false
set refSeln to a reference to (selected rows where (class of its parent is row) and (topic of its parent is pSection))
if (count of refSeln) > 0 then
set strID to note of (first item of refSeln)
if strID ≠ "" then set blnFound to my SelectRow(strID)
end if
if not blnFound then
set refBookmarks to a reference to (rows where its level = 1 and its topic = pSection)
if (count of refBookmarks) > 0 then
set rowBookMarks to last item of refBookmarks
set refMarks to a reference to (children of rowBookMarks)
if (count of refMarks) < 1 then
activate
display alert "No bookmarks found"
return
else
set lstMarks to topic of refMarks
activate
set varChoice to choose from list lstMarks default items {first item of lstMarks} ¬
with title pTitle with prompt (texts 1 thru -2 of pSection) & ":"
if varChoice = false then return
set strID to (note of first item of (refMarks where topic = (first item of varChoice)))
my SelectRow(strID)
end if
else
activate
display alert "No bookmarks found"
return
end if
end if
end tell
end tell
end GoTo
on SelectRow(strID)
tell application id "OOut"
if (count of documents) < 1 then return false
activate
tell front document
try
set oTgt to row id strID
on error
activate
display alert "Row " & strID & " not found in active document"
return false
end try
if level of oTgt > 1 then
set oAncestor to last item of ancestors of oTgt
set expanded of oAncestor to true
set expanded of rows of oAncestor to true
end if
select oTgt
hoist oTgt
--unhoist
activate
tell application id "sevs" to click my GetMenuItem("OOut", {"View", "Unhoist"})
select oTgt
return true
end tell
end tell
end SelectRow
-- RETURNS A REFERENCE TO A CLICKABLE MENU ITEM
-- E.G. set mnuZoomFit to GetMenuItem("OGfl", {"View", "Zoom", "Zoom to Selection"})
on GetMenuItem(strAppCode, lstMenu)
set lngChain to length of lstMenu
if lngChain < 2 then return missing value
tell application id "sevs"
set lstApps to application processes where its creator type = strAppCode
if length of lstApps < 1 then return missing value
tell first item of lstApps
-- GET THE TOP LEVEL MENU
set strMenu to item 1 of lstMenu
set oMenu to menu strMenu of menu bar item strMenu of menu bar 1
-- TRAVEL DOWN THROUGH ANY SUB-MENUS
repeat with i from 2 to (lngChain - 1)
set strMenu to item i of lstMenu
set oMenu to menu strMenu of menu item strMenu of oMenu
end repeat
-- AND RETURN THE FINAL MENU ITEM
return menu item (item -1 of lstMenu) of oMenu
end tell
end tell
end GetMenuItem
on GUIEnabled()
tell application id "sevs"
if UI elements enabled then
return true
else
activate
display dialog "This script depends on enabling access for assistive devices in system preferences" buttons "OK" default button "OK" with title pTitle & " " & pVer
tell application id "sprf"
activate
set current pane to pane id "com.apple.preference.universalaccess"
end tell
return false
end if
end tell
end GUIEnabled
Last edited by RobTrew; 2012-11-13 at 12:29 PM..
Reason: Aims to scroll to bookmarked row by using menu unhoist rather than the scripted unhoist command