Create hyperlink to some text in NSTextView

I can create a hyperlink to some url in an NSTextView using the "Link Panel". Or I can add a link manually using the NSLinkAttributeName attribute of NSAttributedString.

I don't want to make a hyperlink to some external url though, I want to be able to create a hyperlink to some text within the NSTextView. Do you know how in Pages you can set some text as a Bookmark, and then you can make a hyperlink to that bookmark? Any ideas or examples of how to go about that?


I haven't done this in a while so take this with a grain of salt but it goes something like:

  1. You need to define a protocol for you app to handle URLs. It will look something like "myApplicationName://aPath"
  2. In the apps Info.plistfile add the protocol under CFBundleURLTypes key.
  3. Write code for the app to respond to openURL from NSWorkspace. This means the app will have to understand how to convert a URL style path to a specific location in one of its documents.

I think the best method for handling the URL path is to assign a UUID to each document and then a numeric scheme to the paragraph and sentences. The URL ends up looking like: myApplicationName://UUID/paragraphNumber/sentenceNumber/wordNumber. Alternatively you can insert hidden text to define an anchor and just search for that anchor.

Need Your Help

Filtering out service provider files from META-INF

java ant jar jersey

My application needs to run both from the command-line and a web app. The way I've chosen to implement this is to have the entire application in a single jar file (i.e. my application-specific cla...

Purposely render Adobe files unusable after a specific date

javascript powershell adobe patch corrupt

I'm looking for options which would help me render a couple of adobe files ( .indd and .pdf ) that I will send to someone unusable after a predetermined date. By unusable, I mean something along the