Using Hookmark in Microsoft OneDrive with Microsoft Office Apps

As of Hookmark 3.1 (Integration v. 168, 2021-05-25), if you open Microsoft Office files that are in OneDrive and then invoke Hookmark, you will get this message: No linkable item found in <App>, where <App> is Word, Excel or PowerPoint.

To get around that, you have two main options:

Option 1: disable OneDrive syncing; use hook://file/ always

You can disable OneDrive syncing in the OneDrive Sync window. In OneDrive > Preferences > Office > File collaboration section: disable "Use Office application to sync Office files that I open".

See also Use Office applications to sync Office files that I open – Office Support.

This option will enable Hookmark to work in that context, and to use hook://file/ URLs rather than office specific URLs like this: [<filename>](ms-word:ofe%7Cu%7Chttps://d.docs.live.net/de6333572e703b8/filename.docx).

This also has the advantage that if you move the file out of OneDrive, the links will continue to work (that way you’re not locked into OneDrive). And Hookmark will use these same URLs in Finder. That is, whether you invoke Hookmark in Finder or the Office App, Copy Link will give you the same result, and therefore, you will see the same links ‘hooked’ to the document (if any).

However, if you need to keep OneDrive sync on all the time then consider the next two options.

Option 2: Keep sync on, but invoke Hookmark in Finder

Instead of invoking Hookmark in the Microsoft app, select the file in the Finder then invoke Hookmark. You can then paste the links anywhere. If you want to be able to navigate from the Office file in OneDrive to some other location, you can paste the other location’s URL in the document’s File > Properties > comments field. (Don’t rely on Finder comments, because OneDrive might not sync them.)

Option 3. Replace Hookmark’s Get Address with the following

If you really want to invoke Hookmark in Office for documents in OneDrive and get Microsoft specific URLs, then simply replace Hookmark’s Get Address script for the respective app with the following. The example is for Word. Do the same thing for the other MS Office apps if you like.

 tell application "Microsoft Word"
    set activeDoc to active document
    set activeDocName to name of activeDoc
    set activeDocPath to path of activeDoc
    set fullURL to posix full name of activeDoc
    if fullURL does not start with "http" then
        return "file://" & POSIX path of fullURL
    end if
end tell

set appURL to "ms-word:ofe|u|" & fullURL

Here’s how.

That script will return a hook://file/ or a MS specific URL, depending on what MS’s API returns. I.e., if the file is in OneDrive, OneDrive sync is on, and you invoke Hookmark in a MS Office app, you should get a MS specific URL.

Powerpoint script

Here is a Get Address script for Powerpoint that behaves in same way as the Word script above, returning a ms-powerpoint URL if needed.

tell application "Microsoft PowerPoint"
    set activeDoc to active presentation
    set activeDocName to name of activeDoc
    set activeDocPath to path of activeDoc
    set fullURL to full name of activeDoc
    if fullURL does not start with "http" then
        return "file://" & POSIX path of fullURL
    end if
end tell
set appURL to "ms-powerpoint:ofe|u|" & fullURL

Robustness

Regarding Options 1 and 2: in our tests, if you rename OneDrive files directly on https://onedrive.live.com`,hook://file//` links to them will still work. That’s handy.

And of course, one would expect option 3 to lead to robust links, so long as the files are kept in OneDrive and OneDrive Sync is enabled.

Technical background

Hookmark connects with your favorite apps through their API (application programming interface). In particular, to construct a link, Hookmark asks the current app for the location and name of the foreground document. If you are editing a file with a non Microsoft Office app, Hookmark will use whatever URL scheme it normally would. That will typically be a hook://file/ URL, which is valid in Dropbox, Finder, OneDrive, and many other local file storage systems.

Unfortunately, for files residing locally in a OneDrive folder, the location that Microsoft Office apps return when Hookmark asks for their address depends on whether OneDrive is running or not. If OneDrive is running and OneDrive’s "Use Office application to sync Office files that I open" is enabled, Microsoft Office apps return a URL with an odd URL scheme. Otherwise, Microsoft Office apps return a typical file:// URL, which Hookmark converts to a hook://file/ URL.

For more information

For a discussion of this topic, visit Microsoft OneDrive Word Document Issues — Hookmark Forum