Paste Script Block in KM Forum

Use Case

  • Make it easy to copy a script from your editor app, and then paste into the KM forum.

Example Output

image

MACRO:   Paste Script Block in Forums and Apps

~~~ VER: 3.1    2018-04-11 ~~~

updated 2018-04-11 15:46 GMT-0500

  • Major rewrite to provide for any script language
  • Replacing TABS is now optional, and you can specify how many spaces
  • Choose to Replace All Tabs, or Only at Beginning of Line

DOWNLOAD:

Paste Script Block in Forums and Apps.kmmacros (23 KB)
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.


ReleaseNotes

Author.@JMichaelTX

PURPOSE:

  • Paste Text as Forum Code Block

REQUIRES:

  1. KM 8.0.2+
  • But it can be written in KM 7.3.1+
  • It is KM8 specific just because some of the Actions have changed to make things simpler, but equivalent Actions are available in KM 7.3.1.
    .
  1. macOS 10.11.6 (El Capitan)
  • KM 8 Requires Yosemite or later, so this macro will probably run on Yosemite, but I make no guarantees. :wink:

How To Use

  1. Trigger this macro with a Typed String, in the format:
";km.sb.<lang> "
	where <lang> are the characters for the language you want.
         **Note you _must_ enter a SPACE at the end.**
         It can be any of these predefined languages, or your own:
         `as js ss bash html xml text`


FOR Example:
	";km.sb.as "		-- Paste AppleScript Block
	";km.sb.js "		-- Paste JavaScript Block
	";km.sb.ruby "		-- Paste Ruby Block
	";km.sb.anything "	-- Paste Block using language your type
  1. It will then Ask You if you want to replace TABs
  2. Then the Text is paste into the Forum in a Code Block

MACRO SETUP

  • Carefully review the Release Notes and the Macro Actions
    • Make sure you understand what the Macro will do.
    • You are responsible for running the Macro, not me. ??
      .
  1. Assign a Trigger to this maro..
  2. Move this macro to a Macro Group that is only Active when you need this Macro.
  3. ENABLE this Macro.

TAGS:

USER SETTINGS:

  • Any Action in magenta color is designed to be changed by end-user

ACTION COLOR CODES

  • To facilitate the reading, customizing, and maintenance of this macro,
    key Actions are colored as follows:
  • GREEN -- Key Comments designed to highlight main sections of macro
  • MAGENTA -- Actions designed to be customized by user
  • YELLOW -- Primary Actions (usually the main purpose of the macro)
  • ORANGE -- Actions that permanently destroy Variables or Clipboards,
    OR IF/THEN and PAUSE Actions

USE AT YOUR OWN RISK

  • While I have given this limited testing, and to the best of my knowledge will do no harm, I cannot guarantee it.
  • If you have any doubts or questions:
    • Ask first
    • Turn on the KM Debugger from the KM Status Menu, and step through the macro, making sure you understand what it is doing with each Action.

3 Likes

Macro in OP updated/replaced.

Just posted a major update to this macro.

As always, please feel free to post your questions, comments, issues, and/or suggestions concerning it.

For some reason this is not working for me? Was there an update to the forum that stoped this from working?

I use it many times a day, and never have a problem.
I'm running Keyboard Maestro 8.2.3 on macOS 10.12.6.

Please be more specific than "is not working". Where does it fail?
Can you provide a screenshot at that point.
Have you tried using the Macro Debugger to step through the macro, one Action at a time?

What versions of KM and macOS are you running?

I'm probably just not using it right, I had used another version in the past and that stopped working. I have it in the clipboard and run the macro and it fails. I am on macOS 10.13.6 (current version) and Keyboard Maestro 8.2.4 (latest version). I am probably just doing something wrong or not reading the instructions properly.

I have assigned a hot key to trigger it so it will paste in the clipboard AppleScript code so that probably doesn't work with your macro I am guessing.

I was able to get Paste AppleScript as Markdown working so I think I am good. Thank you Michael.

  1. Make sure you are using the latest version I posted above.
  2. Did you read and follow the "How To Use"?

If you want to use it ONLY to paste an AppleScript script block, triggered by a hot key, then you will need to modify the macro. Should be easy.

I am using the latest version just downloaded it again today before I posted.
I did read all of what you posted both on the forum and in the Macro itself.

Thanks for your help I am all set.

So the macro is working for you now?

Unfortunately, no but I gave what I could and already have Chris' macro working. No doubt I am just not smart enough to figure out how to use it properly and I only ever use AppleScript so I should be all set. I found yours before I found the otherone and tried to get it to work. My apologies for engaging you and then giving up.

It is not hard at all to use my macro to paste AppleScript.

Click in the KM forum post block, and then
Just use a trigger of:
";km.sb.as "

without the quote marks, and make sure there is a SPACE at the end.

Could you please try that, using the macro unchanged?

If there is a problem with my macro, I need to identify and fix it for the benefit of other users.

Thanks.

How would I paste a bash script?

Exactly as you would expect:
;km.sb.bash

1 Like

Thank you!