Start New Macro from KM Forum Page

This is inspired by @ccstone's Keyboard Maestro Editor ⇢ Paste Dated Attribution Action v5.00 Macro

This creates a new macro and populates the macro release notes comment with details based on the forum post that is being viewed on the forum.

Example of what is generated when running this macro against a forum post page:

Screenshot of Macro

:movie_camera: :desktop_computer:

Video demo of macro in action

Start New Macro from KM Forum Page

Start New Macro from KM Forum Page.kmmacros.zip (4.2 MB)

Any chance this can be made to work in Safari? Thank you.

Yes. Use either the Execute a JavaScript in Front Browser action or the Execute a JavaScript in Safari action.

1 Like

Well done!

The reason I haven't done that is because URLs can be long and in the way, so I prefer to emplace them as Rich-Text links.

I haven't yet figured out a way to automate that...

1 Like

I haven’t paid enough attention yet so I’ll ask, what do you use as the visible text then? Would you remove the link line in the comment and just link the task title?

This is what I use to create a RTF link for pasting into my attribution action:

--------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2019/04/17 02:19
# dMod: 2021/01/16 19:00
# Appl: Google Chrome, Keyboard Maestro
# Task: Create RTF Link for Keyboard Maestro Forum Thread Title and URL and Place on the Clipboard.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Google_Chrome, @Keyboard_Maestro, @Create, @RTF, @Link, @Forum, @Thread, @Title, @URL, @Clipboard
--------------------------------------------------------

try
   set clipboardText to the clipboard as text
on error
   set clipboardText to null
end try

tell application "Google Chrome"
   tell front window
      set theTitle to its title
      
      if clipboardText ≠ null and clipboardText starts with "http" then
         
         set theURL to clipboardText
         
      else
         
         set theURL to active tab's URL
         
      end if
      
   end tell
end tell

tell application "Keyboard Maestro Engine"
   set theTitle to search theTitle for " +- .+$" replace "" with regex
end tell

--------------------------------------------------------


set shCMD to text 2 thru -1 of "
echo '<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">
<html>
  <head>
  <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
  <meta http-equiv=\"Content-Style-Type\" content=\"text/css\">
  <title>'\"$myTitle\"'</title>
  <meta name=\"Generator\" content=\"Cocoa HTML Writer\">
  <meta name=\"CocoaVersion\" content=\"1038.11\">
  <style type=\"text/css\">
    span.s1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Lucida Grande}
  </style>
  </head>
  <body>
    <span class=\"s1\"><a href='\"" & theURL & "\"'>'\"" & theTitle & "\"'</a></span>
  </body>
</html>' \\
| textutil -convert rtf -inputencoding UTF-8 -format html -stdin -stdout \\
| pbcopy -Prefer rtf
"


--------------------------------------------------------

do shell script shCMD

display notification "Link Copied to the Clipboard" with title "Google Chrome" subtitle "Script" sound name "Tink"

--------------------------------------------------------

(*

NOTES:

2020/12/18 10:24 -- Added ability to use an URL on the clipboard as the link.

*)

--------------------------------------------------------
1 Like

A couple of things, one major, one not so much:

  1. The macro that downloads has a "Type the ⌘L Keystroke" action instead of the "Type the ⌘N Keystroke" action shown in the macro displayed above. This results in the creation of an alias macro, which is not what is wanted here.
  2. In setting the comment, the Author and Url lines need an extra tab in front of the colon to even things up.

Also, the whole "wait until the favorite action has been added ..." bit was goofing things up on my computer, so I just replaced it with a pause, and all is now well.

Thanks for this idea.

The change in letters for the keyboard shortcut is because you and I are using different keyboard layouts.

Now I'm curious. So, on your keyboard, ⌘L creates a new macro? Is it a different language keyboard or something else? I.e. is it the keyboard itself, or have you reprogrammed the KBM commands to something else.
As a follow-on, what is the ⌘I keystroke in the downloaded version of the macro intended to do. That is where I was having the other problem.
Hope you don't mind my asking these things

1 Like

No. It has to do with key codes I think. I run Dvorak. A recent relevant thread starting URL (and Title) from Firefox (subroutine) - #2 by MikeTheClicker

Ahh, got it. thanks - I'll keep an eye out for those kinds of keyboard changes in your macros. Keep 'em coming - they're very useful.

1 Like

Thanks! Yeah, it’s an interesting quirk of running a different keyboard layout. Come to think of it, I think you’ve inspired me to add a default note to my macros that I share in the future noting that I’m on Dvorak and the key bindings may need to be adjusted. I also should look into how to better deal with this. Thanks @rolian !

Hah, I now understand why your macro was clearing clipboards when it didn’t look to me like the macro was even copying anything. ⌘C (copy) on your keyboard was being translated to ⌘I when the macro downloaded to my computer, which explains why that whole check action was not working for me.

1 Like