I haven't used Dropbox in years, but the challenge with this (as I recall) is that when you select that menu item in Finder it actually generates the link (or maybe retrieves it?) in real time. It's not something stored directly with the file, it seems.
I asked ChatGPT about it, and it said that there's an official Dropbox command line client available. Once that's installed, you can get a link via AppleScript with this:
tell application "Finder" to get the URL of the selection
Here's the ChatGPT transcript so you can see what it said:
As noted, I stopped using Dropbox a long time ago, so I can't test this, but it makes logical sense. Of course, it's a LLM so there's a 72.57% chance the answer is completely fictitious.
Closer to 100% -- the official Dropbox command line client is Linux-only, and I've a feeling the homebrew installer is the usual Mac Dropbox app with no CLI/scripting provision.
I would love to be proven wrong about that. Please? Someone?
Ah dang, I bet all the cool stuff broke when Dropbox switched (when Apple essentially made it required to do so) to using the file provider API, which is very much tied to the GUI. Sorry :(.