Pasting Text from Variable using "Send Mail" action is a step behind?

Hi Guys,

I have no doubt this has been covered but I'm struggling to find an answer.

I'm having trouble inserting text from a variable using the "Send New Mail Message" action.

When Mail opens the new message the text is from the variables previous state. If I paste manually or re-run the macro there's no issue.

Any idea where I'm going wrong here? Feels like this should be simple...?

Thanks in advance.

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.

1 Like

@Faz here's my DropBox solution -- an AppleScript.
This script tells Dropbox to give us the public link, and waits until it is on the Clipboard.

You can just put this script in an Execute an AppleScript action.

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

  • 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.
  • URL of Public Dropbox item to the Clipboard

  1.  macOS 10.11.6+
  2.  Mac Applications
      • Dropbox
      * Finder 

REF:  The following were used in some way in the writing of this script.

  2. Based on script by Chris Stone (@ccstone)
use framework "Foundation"
use scripting additions

property LF : linefeed

  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
      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 ~~~~~~~~~~~~~~~~~

Perfect! Thank you so much.

Replacing the actions I used to grab the link fixed this and now functions much faster.

I really must learn more about creating scripts.