Hey JM,
Well.. It's possible but a PIA.
Scripting the contextual-menu with System Events is broken in list-view but seems to work in icon-view. Nevertheless if you want to install the Dropbox toolbar-button it's pretty easy.
This won't be quite right, because the parameters depend upon where you put the Dropbox button in the toolbar. (This is tested on 10.10.4 — different versions of OSX can have subtle or not so subtle variations.)
tell application "System Events"
tell application process "Finder"
set frontWin to (first window whose role is "AXWindow")
tell frontWin
tell menu button 1 of group 6 of toolbar 1
click
tell menu 1
click menu item "Copy Public Link"
end tell
end tell
end tell
end tell
end tell
However it's pretty pointless to use Dropbox's UI for this, because the result can be easily duplicated.
[EDIT: DropBox broke the ability to create a public link this way in late 2017 — ccs]
Here's what a public link copied from the Finder using Copy-Public-Link looks like (I've changed the user-number):
https://dl.dropboxusercontent.com/u/00000000/Developers/Stairways_Software/Keyboard%20Maestro%20ScreenShot%20Issue.mp4
Here's what a link from the Dropbox site looks like:
https://www.dropbox.com/sc/7x9xe87mjhedxwd/AAAHb_1v_IfHSUYcOyfph19va
So, if you're giving the link to someone else the scripted method is going to be better, because it anonymizes the link just like the latter example.
If you don't care who sees your static user number the job is simple to do with basic AppleScript.
You replace dbBaseURL
with your address by getting copying a public link once with the Dropbox UI, and you're ready to go to town.
------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2013/04/29 23:22
# dMod: 2015/08/05 23:58
# Appl: Finder & Script-Runner
# Task: Copy Public Dropbox URLs from selected files to the Clipboard.
# Libs: None
# Tags: @Applescript, @Dropbox, @Public, @URL, @Clipboard
# Test: Mavericks, Yosemite.
------------------------------------------------------------
try
set dbBaseURL to "https://dl.dropboxusercontent.com/u/00000000/" # User must supply.
set dbPubStr to ((path to home folder as text) & "Dropbox:Public:")
set AppleScript's text item delimiters to "/Dropbox/Public/"
tell application "Finder"
set _sel to selection as alias list
if _sel ≠ {} then
set hfsPath to item 1 of _sel as text
if (hfsPath does not contain dbPubStr) or (hfsPath = dbPubStr) then
error "Selection not in Public Dropbox folder."
end if
repeat with i in _sel
set contents of i to (dbBaseURL & (text item 2 of (get i's URL)))
end repeat
set _sel to joinList(_sel, linefeed) of me & linefeed
set the clipboard to _sel
end if
end tell
on error e number n
stdErr(e, n, true, true) of me
end try
------------------------------------------------------------
on joinList(_list, _delimiter)
set {oldTIDS, AppleScript's text item delimiters} to {AppleScript's text item delimiters, _delimiter}
set joinedList to _list as string
set AppleScript's text item delimiters to oldTIDS
return joinedList
end joinList
------------------------------------------------------------
on stdErr(e, n, beepFlag, ddFlag)
set e to e & return & return & "Num: " & n
if beepFlag = true then
beep
end if
if ddFlag = true then
tell me
set dDlg to display dialog e with title "ERROR!" buttons {"Cancel", "Copy", "OK"} default button "OK"
end tell
if button returned of dDlg = "Copy" then set the clipboard to e
else
return e
end if
end stdErr
------------------------------------------------------------
-Chris