Can a service capture a Safari URL to an existing OO outline?

Another Circus Ponies refugee here.

One feature I loved was a Safari service that captured the URL of the currently open Safari tab and put it into a pre-defined slot in an existing notebook. This worked whether or not CP Notebook was open, and was much quicker than cutting and pasting. I had several services for different notebooks, all accessible from the Safari services menu.

In OO, I’d like to capture URLs as children of an ‘Inbox’ parent, but I would settle for just putting them as the first or last items in an outline.

Can I get this functionality in OO? Or build it with an Applescript?

1 Like

Plus 1! Plus 1!

I don’t know CP but if the OmniOutliner document is open then the script below should do what you describe. Change “Inbox” to whatever your name is for the parent. I just run the script from within Script Editor or from the script menu. But it can be placed within a Run Applescript action in a Automator Service if you want it in the Safari > Services menu or want to attach it to a keyboard shortcut.

SG

property refRowName : “Inbox”

tell application “Safari”
set selText to (do JavaScript “”"+window.getSelection();" in document 1)
tell current tab of window 1 to set {theURL, theTitle} to get {URL, name}
end tell

tell application “OmniOutliner”
tell document 1
try
set refRow to row named refRowName
on error
display dialog "Can’t find a row named " & refRowName buttons “cancel”
return
end try
set newChild to make new row at refRow
tell newChild
set topic to theTitle
set topic cell’s text’s style’s attribute “link”'s value to theURL
set note to selText
end tell
set refRow’s expanded to true
end tell
end tell

1 Like

Wow, SGill. Thanks!

Tried your script which worked a treat. Particularly pleased that your script captured the name of the url as well as the url itself. Classy. Really appreciate your help.

Now that you’ve shown me the idea I think I can modify the script to open a specific OO document rather than using the frontmost OO document, . Then I can make several of them for different notebooks, and I’ll have the full function of the CP Notebook clipping services.

Drat, OS update (10.11.5?) broke SGill’s fine solution.

SGill’s solution used javascript. OS 10.11.6 requires “allow javascript from apple events” - a setting somewhere.

I can’t find anything that explains this new setting, or suggests whether it’s appropriate: I suppose it closed some security hole. Is there a way to recast SGill’s solution without the use of javascript?

Thanks for the heads up on this.

If you want to capture the text you have selected in Safari then I think you need the JavaScript. If you don’t need the text but just want the title and URL then you could do without the JavaScript. You would delete two lines:

set selText to (do JavaScript "\"\"+window.getSelection();" in document 1)

and, further down:

set note to selText

However, it’s easy to allow JavaScript. Just go to the Develop menu in Safari and select ‘Allow JavaScript from AppleScript Events.’ If your Develop menu isn’t showing in your menu go to Safari > Preferences > Advanced and check ‘Show Develop menu in menu bar.’

When you’re browsing elsewhere and want to turn off JavaScript just in case, then just toggle it off in the Develop menu.

SG