The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniOutliner 3 for Mac (http://forums.omnigroup.com/forumdisplay.php?f=9)
-   -   Creating and jumping to bookmarks in OmniOutliner (http://forums.omnigroup.com/showthread.php?t=20643)

RobTrew 2011-04-09 02:34 AM

Creating and jumping to bookmarks in OmniOutliner
 
Clickable internal links may be hard to implement in OO3, but it is quite easy to create simple bookmarks, and return to them automatically.

Two scripts attached below.

[B]CreateBookMk.scpt[/B]
[LIST][*]Select a row in an OO3 document, and run the script.[*]Respond to the prompt for a bookmark name.[/LIST]
[B]GotoBookMk.scpt[/B][LIST][*]Run the script.[*]Choose a bookmark by name from the menu which appears.[*](The script will jump to the corresponding row)[/LIST]
A special section entitled [I]Bookmarks[/I] is created at the end of the document. The note of each bookmark row contains the id of its target row.

Note that if you select a bookmark row before running [I]GotoBookMk.scpt[/I], it will bypass the menu and jump straight to the bookmark target.

[COLOR="White"]--[/COLOR]

RobTrew 2012-11-13 06:11 AM

[CODE]-- CREATES BOOKMARKS - USE IN CONJUNCTION WITH GotoBookMk.scpt

property pSection : "Bookmarks"
property pVer : ".01"
property pTitle : pSection & tab & pVer

CreateBookMark()

on CreateBookMark()
tell application id "OOut"
if (count of documents) < 1 then return
-- GET THE ID OF THE FIRST SELECTED ROW
tell front document
set refSeln to a reference to selected rows
if (count of refSeln) < 1 then return
set strID to id of first item of refSeln

-- GET A NAME FOR THE BOOKMARK
activate
set strMark to text returned of (display dialog pSection & " name:" default answer "" with title pTitle)

-- FIND/CREATE A BOOKMARKS SECTION
set refBookmarks to a reference to (rows where its level = 1 and its topic = pSection)
if (count of refBookmarks) < 1 then
set rowBookMarks to make new row at end of rows with properties {topic:pSection}
else
set rowBookMarks to last item of refBookmarks
end if

-- ADD A BOOKMARK (STORE ID IN NOTE)
make new row at end of children of rowBookMarks with properties {topic:strMark, note:strID}
end tell
end tell
return true
end CreateBookMark[/CODE]

RobTrew 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


[/CODE]

hmarstra 2012-11-13 11:23 AM

Great scripts. I made too many test-bookmarks. Can you please tell me how to erase some of the bookmarks. I havent figured out where they are stored

RobTrew 2012-11-13 11:26 AM

I'm glad that seems useful.

You should find an extra row at the end of your document called bookmarks, and you can delete some of its child rows.

hmarstra 2012-11-13 11:27 AM

Sorry .... found it. Read your post again

hmarstra 2012-11-13 12:08 PM

Using the script with Quickeys so I can trigger them with keyboard.
One small thing. When you use second script it does highlight the bookmark you have saved, but the scrollbar doesnt always jump to the right place.

Have you experienced this?

RobTrew 2012-11-13 12:31 PM

Ver .05 (above) may now fix that.

(Instead of the [I]unhoist[/I] command in the scripting interface, it triggers the menu system's View > Unhoist, which seems to scroll, at least on my system, to the right part of the file).

hmarstra 2012-11-13 01:57 PM

Works perfectly

hmarstra 2012-11-15 01:35 AM

Would it be difficult to make a version of the second script that would just be a fixed bookmark for a given place in a OO document.

Could be handy to make 2-3 such duplicate scripts for your most frequently used locations in your document. Then it would be a one-click operation rather than going via the list-of-bookmarks interface


All times are GMT -8. The time now is 07:43 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.