Updating a KM macro for less UI engagement

Hi and good day,

Due to the computer is sometimes slow to respond to UI cammands, the script below is failing in about 30% of the cases, pauses help (one pause has 3.5 seconds!!) but still problems sometimes. This macro (&AS script) will not be unfamiliar to some of our colleagues on this list. :smile:

What it does:
This macro lets the user copy the title of a webbtext (Serial Clipboard1) and (in this case) one more paragraph (Serial Clipboard2) from either Safari or Chrome and save it into a TextEdit* document with capture date/time and url, and to collect it to a folder (_INPUT).
(*for better styling, but TextWrangler would do if simpler.)

Serial AutoPaste TE 2C AS

The Hot Key ⌃7 is pressed

  • Execute AppleScript

    set appPath to path to frontmost application as text
    set AppleScript’s text item delimiters to {":", “.”}
    set frontApp to text item -3 of appPath
    if frontApp = “Safari” then
    tell application "Safari"
    set _url to URL of front document
    end tell
    else if frontApp = “Google Chrome” then
    tell application "Google Chrome"
    set _url to URL of active tab of front window
    end tell
    end if
    – Just to demonstrate the value of variable _url.
    – tell current application to display dialog _url
    Save trimmed to variable ‘url’.

  • Activate TextEdit

  • Pause Until All Conditions Met

    • Condition iconApplication ‘TextEdit’ is at the front
  • Type the ⌘N Keystroke

  • Pause for 1.5 Seconds

  • Apply Style to Named Clipboard ‘Serial Clipboard1’

    • Set font to Lucida Grande.
    • Set size to 24.
    • Set foreground to Swatch
  • Paste from Named Clipboard ‘Serial Clipboard1’

  • Type the Return Keystroke

  • Insert Styled Text by Pasting

    • capt. %ShortDate% %ShortTime%
    • URL: %url%
  • Type the Return Keystroke

  • Type the Return Keystroke

  • Insert Styled Text by Pasting

  • Apply Style to Named Clipboard ‘Serial Clipboard2’

    • Set font to Lucida Grande.
    • Set size to 18.
    • Set foreground to Swatch
  • Paste from Named Clipboard ‘Serial Clipboard2’

  • Type the Return Keystroke

  • Insert Styled Text by Pasting

    • .-.
  • Execute AppleScript

    tell application "TextEdit"
    1st paragraph of text of first document
    end tell
    Save trimmed to variable ‘tettle’.

  • Speak Text With Voice ‘Veena’ at Default Rate

    • Title: %Variable%tettle%
  • Select Menu Item in TextEdit

    • Select: File ⇢ Save As…
    • Stop macro if menu cannot be selected.
  • Pause for 4 Seconds

  • Comment ‘added time’ from 1.5 to 2.5 sec to 4. sec

  • Insert Text by Pasting

    • %Variable%tettle%
  • Pause for 1.5 Seconds

  • Type the ⇧⌘G Keystroke

  • Pause for 3.5 Seconds

  • Insert Text by Pasting

    • ~/Documents/_INPUT/
  • Type the Return Keystroke

  • Pause for 1.0 Seconds

  • Type the ⌘S Keystroke

  • Pause for 1.0 Seconds

  • Type the Home Keystroke

  • Pause for 1.5 Seconds

  • Type the ⌘W Keystroke

  • Pause for 2.0 Seconds

  • Activate Last Application

Hey Omar,

Am I to take it that this was posted for me? :smile:

The script below is very preliminary, but it's working.

It writes RTF copied from Safari directly to a file in _INPUT.

It does not enlarge the text but writes it as it finds it, and the added title and url will be of the same style.

I am not currently accounting for name collisions either but I will add that later.

Try it, and let me know if it's anything close to what you're wanting.


Copy Text to a RTF file.kmmacros (5.5 KB)

1 Like

I just scoped out Google Chrome, and I can get RTF out of it — so I’ll make a few improvements later today.


Hey Omar,

I found that Keyboard Maestro's ability to work with RTF is pretty good, so I abandoned the AppleScript elements for now.

The goal of this macro is to make a RTF clipping of the selection in Safari or Google Chrome in a specific directory: ~/Documents/_INPUT/

The file name follows the page title and uses a time-stamp to avoid naming collisions.

A header is added showing a time-stamp, the title, and the url of the page in question:

2015/40/14 11:40
how to show lines in common (reverse diff)? - Stack Overflow

Formatting and URLs of the copied text are preserved.

Give it a try, and let me know what you think.


Edit: 2015/05/16 16:23:

  • Fixed typo in ICU date format.
  • Added action to apply format to copied text (initially disabled).

Safari OR Google Chrome { Copy to Clipping File }.kmmacros (20.9 KB)

2015/05/16 16:28

Edited post #4 — 1 fix — 1 enhancement.



This macro copies a RTF clipping from the selection in Google-Chrome or Safari to a folder

I've added some user-setting and various options.



The clipping has a styled-text header with page-title, date, and Url included.

Links and formatting are retained.

The user can choose to zoom the clipping for readability — or set a specific Font-Size — or set a specific Font & Size.

I have attempted to make this at least a little user-friendly by adding comments and creating a few user-settings at the top.

Some actions are grouped using a repeat-action solely for that purpose. (KM7 will have a more formal way to create groups - thanks Peter!)

The body-text-zoom-level has a specific task — set to 0 (zero) for no-zoom — set to n for the number of times to zoom the body-text.


Safari OR Google Chrome { Copy to Clipping File } { v1.01 }.kmmacros (27.1 KB)

Hey Folks,

A few changes made.


  • Created 'Safari or Google Chrome' Macro Group.
  • Changed macro name to reflect above.
  • Added User Preference for Destination Directory.
  • Added User Preference for Body Text Size.
  • Changed checks for destination directory from Execute Shell Script to plain KM functions.
  • Added Update Destination Directory AppleScript to make the new file show up a little faster.

Ordinarily I want the body of the clipping to exactly match the text in the web page. But…

I added an 'Apply Style to BODY TEXT…' action to change the font to Lucinda Grande and there is a user-setting for the size of the text.

The Font Name is hardcoded, so I cannot make that a user-preference (above) — it must be set in the following action.

You can disable that one action to leave the font, size, and styles of the clipping alone.


Safari or Chrome { Copy Selected-Text to Clipping File } { v1.05 }.kmmacros (31.8 KB)

With Safari update (around vs. 9 / OS El Capitan) for the macro to pick up the page title, it is necessary to check > Safari > Develop > ”Allow JavaScript for Apple Events.” Thanks to Chris S. for pointing this out!

Here is a slightly tweaked version {1.05tw}, mainly bigger font size, and a pop-up window to see immediately the results of the macro.

Keyboard Maestro “Safari or Chrome { Copy Selected-Text to Clipping File } { v1.05tw}” Macro

Safari or Chrome { Copy Selected-Text to Clipping File } { v1.05tw}.kmmacros (33 KB)