When %FrontDocumentPath% meets OneDrive

Hi,
I can't get the file path with %FrontDocumentPath% when the file is on a mounted drive like OneDrive.
Is there any workaround?
Thanks.

Welcome to the KM Forum!

The KM wiki for %FrontDocumentPath% token states that:

The %FrontDocumentPath% token returns (v11.0+) the path of the document associated with the front window if the Application supports this property.

So my question is: what is the app you're trying to use this token in and does it support this property?

Sorry,
It's Microsoft Word.
I've tried using this token to get file paths on local drive and it worked fine.

OK. I've just run a test and can get the file path when it's open in Word.app. Here is my test macro:
image

and the output is:

= Local__Test =
/Volumes/Users SSD/MovedUsers/taj/Library/CloudStorage/OneDrive-Personal/631602_letter-of-authority-word (1).docx

Are you using Word.app or the web app version of Word?

Word.app

I've just updated my previous post because I was testing with a local file. The update is a file on my OneDrice and the output is:

= Local__Test =
/Volumes/Users SSD/MovedUsers/taj/Library/CloudStorage/OneDrive-Personal/631602_letter-of-authority-word (1).docx

Since I don't normally use OneDrive I suspect your "mounted volume" is somehow different to mine.

This is how my OneDrive appears in the Finder sidebar:

image

but I understand that this is something that the OneDrive.app is responsible for.

Please correct me if I'm wrong (I have an uncomfortable feeling right now...)

I tried it on Google Drive and the token works fine now.
I think you're right, the problem might be on OneDrive.app.
CleanShot 2025-04-15 at 19.36.00@2x

And this is what I got when I try your test Macro:
Null.

Ok.

Looking at Word.app window, what (text) appears in the window title? It should be the document file name I think (I can't check that as I'm at lunch right now).

For me, OneDrive documents aren't "on disk" as far as AppleScript is concerned, and their full path is actually an https:// Sharepoint link. I suspect that KM is struggling with the same problem.

What do you need the document path for? There may be a workaround...

1 Like

@tiffle
Filename and last modified time.

@Nige_S
To reveal the files. I usually open the files with Alfred. After the files are edited, I want to send the files to my customer or colleague. And it cost time to search or open Finder and locate the files.
And Word's AutoSave only works on OneDrive.

@yikechiu if Sharepoint is involved, as @Nige_S asks, then I can't help further as I don't have that environment here.

1 Like

I came home and try the same Macro on my another computer, and a error message appeared:
CleanShot 2025-04-15 at 22.49.41@2x

@tiffle
Thanks anyway.

You should insert a Display Text action in your macro before the action causing the error to see what the path actually looks like. It should give you a clue as to what's going wrong.

Try the following in Script Editor, with a OneDrive-hosted document open in Word:

tell application "Microsoft Word"
	full name of document 1
end tell

Does the returned value start with https://?

If so, the path up to and including /Documents/ can be replaced with local path to your OneDrive folder and you can then use that to reveal the file in Finder. You'll need to edit the path in the first line. This does rely on you not having any folders named "Documents" in the path, or you will have to change how you do the split!

set localPathBase to "/Users/yourUserName/Library/CloudStorage/OneDrive-Personal/"

tell application "Microsoft Word"
	set thePath to full name of document 1
	set AppleScript's text item delimiters to "/Documents/"
	set thePath to text item 2 of thePath
end tell

tell application "Finder" to reveal file (POSIX file (localPathBase & thePath) as alias)

Troubleshoot in Script Editor first so you get better error reporting, then pop the finished script into a KM "Execute an AppleScript" action.

1 Like

Ah, Problem is solved!

The Finder window aren't at front so I thought it failed at first, but after I check Finder again, I'm sure it works!

Thank you so much, @Nige_S .
And thank you @tiffle .

1 Like

The path is correct, else you'd get an error and not that dialog.

Note that the script doesn't pop the Finder -- you can do that with an activate command or with a KM action.

Edit: Slow pony is slow! I see you've solved it yourself -- nice one!

1 Like

This has to be /Users/yourUserName/Library/CloudStorage/OneDrive-Personal/Documents/
or '/Documents/' won't show in the path.

It doesn't for me.

For me, the top-level of the "local" personal OneDrive is /Users/yourUserName/Library/CloudStorage/OneDrive-Personal/. The corresponding "My Files" directory in the "cloud" OneDrive is at https://xxxxx-my.sharepoint.com/personal/yyyy_example_com/Documents/.

But maybe different tenancies, particularly Enterprise-level (which I'm under) and personal, have different rules. The point is that you can replace the path for the cloud "base directory" with that for the local one -- you just have to find out what those two paths are for you.

Which you have -- that's really a note for future-me (and anyone else who stumbles across this).

2 Likes