Embed URL in Apple Mail Text

In a Mac Power Users podcast, David Sparks mentioned embedding a URL in Apple Mail text. I searched for a way to automate this task as it involves numerous steps. I couldn't find anything so I turned to Keyboard Maestro. The macro uses standard keyboard shortcuts.

I open Safari and go to the URL I want to embed. I then open an Apple Mail New Message and type the key word followed by ⌥⇧E. I smile every time I use this macro as it works so well.

Embed URL in Apple Mail Text.kmmacros (4.1 KB)

Hey Tom,

Let's automate that just a little more and run it directly from the Safari KM macro group.

(When you load it, it will show up in group 'Test Group'.)

-Chris

New Mail Message with Embedded Safari Link.kmmacros (4.6 KB)

Chris,

Thank you. You clearly have more expertise in macros than I do. Your approach results in a different end point. The URL is in the Subject line where my objective and macro is to embed the URL in a keyword in the body of the email. Both approaches work. Can your macro be adjusted to embed the URL in a keyword rather than put the bare URL in the subject line?

Tom

Hey Tom,

Did you try the macro?

The URL is not put into the subject field. The Safari page title is put there (although on relatively rare occasions a page title might equal its URL).

The title is also placed into the message body, and the URL is attached to it to produce an embedded link. You can of course change this to suit, and use any keyword you please.

The point is to demonstrate the technology rather than to produce a finished macro tailored exactly to your needs.

If this isn’t working on your machine then the keystrokes might need a little tweaking - as you may have Mail configured differently than I do.


This task can also be tackled with AppleScript, although unfortunately the embedded link cannot be easily achieved via script - so you still have to rely on KM-Actions for that part.

tell application "Safari"
  if front document exists then
    tell front document
      set _title to do JavaScript "document.title"
      if _title = "" then set _title to "myKeyword"
      set _url to do JavaScript "document.URL"
      if _url = "" then error "The front page in Safari has no URL available!"
    end tell
  else
    error "No document is available in Safari!"
  end if
end tell
set the clipboard to _url
tell application "Mail"
  activate
  set newMsg to make new outgoing message with properties {subject:_title, content:_title}
  tell newMsg
    set visible to true
  end tell
end tell

-Chris

Chris,

I tried your macro and it did not do the things you mentioned. I will try it again. Thank you for spending the time on this.

Tom

Hey Tom,

That macro shouldn't be overly difficult to troubleshoot, but let's take some of the variables out of the equation by eliminating a few keystrokes.

The AppleScript in this macro simply moves focus into the message body, so Cmd-A can properly select-all and then Cmd-K can bring up the 'Add Link' dialog.

If System Events isn't running on your system when this macro runs the first time there might be a delay while it starts up. The macro sets it to run continuously though, so if there is a delay it should be a one-time-event.

* Note that script files run faster than text scripts in Keyboard Maestro, and compiled AppleScripts must be saved from the Applescript Editor.app on your system.

-Chris


New Mail Message with Embedded Safari Link using SEV.kmmacros (5.0 KB)

Chris,

That macro works brilliantly! You are a wizard at Keyboard Maestro. Your macro opens a new email and establishes the keyword with an embedded link. My macro will be useful for additional keywords with embedded links in the same email. Thank you for your masterful work.

Tom