If the only KM Variable you are having problems with is %DropBoxLink% then I'm pretty sure the issue is due to how DropBox works.
When you click on the menu item in Finder to create & paste the DropBox public link to the Clipboard, it can take up to 3+ seconds before the Clipboard is updated. So you nee a Pause Until action the Clipboard has been updated. For an example, see:
BTW, there are better methods to get the Dropbox link.
I'll post back here in a bit when I have found mine.
property ptyScriptName : "Get Dropbox Public Link of Selected Finder Item"
property ptyScriptVer : "3.0" -- CHG Extract code for Finder Only
property ptyScriptDate : "2019-08-26"
property ptyScriptAuthor : "JMichaelTX" -- based on script by @ccstone
(*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PURPOSE:
• Get the Public Link for any DropBox item currently selected in the Finder
• Since 2017-09-01 public links have been disabled for all DropBox users
• So the prior methods of getting a Public Link not longer work.
• This is based on the DropBox UI in the Finder Toolbar.
RETURNS:
• URL of Public Dropbox item to the Clipboard
REQUIRED:
1. macOS 10.11.6+
2. Mac Applications
• Dropbox
* Finder
REF: The following were used in some way in the writing of this script.
1. https://www.dropbox.com/help/files-folders/public-folder
2. Based on script by Chris Stone (@ccstone)
https://forum.keyboardmaestro.com/t/how-do-i-execute-dropbox-copy-public-link/1772/7
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*)
use framework "Foundation"
use scripting additions
property LF : linefeed
try
--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
set gCurrentApp to path to frontmost application as text -- use for dialogs
set maxWait to 2.0 -- sec
set delayInt to 1.0E-3
set elapsedTime to 0.0
set cbTest to "WAITING"
set the clipboard to cbTest
tell application "Finder" to set finderSelectionList to selection as alias list
if length of finderSelectionList = 0 then error "No files were selected in the Finder!"
set fileAlias to item 1 of finderSelectionList
set filePath to POSIX path of fileAlias
if (filePath does not contain "/Dropbox/") then
error "fItem MUST in the the Dropbox folders. Invalid path:" & linefeed & filePath
end if
tell application "System Events"
tell application process "Finder"
set frontWin to (first window whose role is "AXWindow")
tell frontWin
set dbGrp to first group of first toolbar whose help contains "Dropbox"
# Alternate Method #
(*
IF you prefer speed over reliability, then use next statement instead of prior.
Position of the Dropbox Group/Menu may vary by macOS and how you have configured the Finder.
(uses < 0.01 sec less time in my testing, but YMMV)
set dbGrp to group 5 of toolbar 1
*)
tell dbGrp
tell menu button 1
perform action "AXPress"
tell menu 1
--- Delay Until Menu Item Shows ---
repeat until (exists menu item "Copy Dropbox Link")
delay delayInt -- short delay needed to show menu
set elapsedTime to elapsedTime + delayInt
if (elapsedTime > maxWait) then error ("Max Time Exceeded Waiting for Dropbox Menu to show: " & elapsedTime)
end repeat
click menu item "Copy Dropbox Link" -- to the Clipboard
end tell
end tell -- menu button 1
end tell -- dbGrp
end tell -- frontWin
end tell
end tell
--- Delay Until Link is on Clipboard ---
(*
NOTE: You wouldn't think this is necessary, but in my testing
I found it could take almost 1 sec for the Dropbox Mac
service to put the link on the clipboard.
*)
set elapsedTime to 0.0
set dbLink to "TBD"
repeat until (dbLink starts with "http")
delay delayInt -- short delay needed for DropBox Service
try
set dbLink to the clipboard as text
on error
set dbLink to "TBD"
end try
set elapsedTime to elapsedTime + delayInt
if (elapsedTime > maxWait) then error ("Max Time Exceeded Waiting for Dropbox Link to be put on Clipboard: " & elapsedTime)
end repeat
set scriptResults to dbLink
--~~~~~~~~~~~~~ END TRY ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--» ON ERROR
--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
on error errMsg number errNum
if errNum = -128 then ## User Canceled
set errMsg to "[USER_CANCELED]"
end if
set scriptResults to "[ERROR] [MACRO CANCELLED] " & errMsg
tell application gCurrentApp
display notification scriptResults ¬
with title (ptyScriptName & " " & ptyScriptVer) ¬
sound name "glass"
end tell
--» THROW ERROR ~~~~~~~
error scriptResults
end try
--~~~~~~~~~~~~~~~~END ON ERROR ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
return scriptResults
--~~~~~~~~~~~~~~~~~~ END OF MAIN SCRIPT ~~~~~~~~~~~~~~~~~