Extract Data from Web Page and Paste into Mac App [Example]

MACRO:   Extract Data from Web Page and Paste into Mac App [Example]

~~~ VER: 1.4    2018-03-09 ~~~


Extract Data from Web Page and Paste into Mac App [Example].kmmacros (256 KB)
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.

Built in response to this request:
How Do I Extract Shipping Address from Shopify Web Page and Paste into Pages Form?




  • Extract Data from Web Page and Paste into Mac App

Video Demo:


  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:
  1. Safari or Google Chrome

NOTICE: This macro/script is just an Example

  • It has had very limited testing.
  • You need to test further before using in a production environment.
  • It does not have extensive error checking/handling.
  • It may not be complete. It is provided as an example to show you one approach to solving a problem.

How To Use

  1. Open the web page (Safari or Chrome) to the page of interest (that you want to copy FROM)
  2. Switch to Mac app form, and click in the “Name” field.
  3. Trigger this macro
  • It will extract data from FrontMost Web page (Safari or Chrome)
  • Then Paste (type actually) in your Mac app, using TABs to move between fields.

It currently uses “Insert text by Typing” because that is what I needed to use in testing with Excel. You may be able to change to “Insert text by Pasting” with your app.


  • 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.
    (all shown in the magenta color)
    • SCRIPT: Extract Data From Front Web Page (JSB)
      • Change script to work with your web page
    • RegEx: Extract Fields from Above Web Data
      • Change as needed to extract fields you need
    • Change Number and Location of TAB blocks as needed to move to next field in your Mac App

TAGS: @JavaScript @Web @WebScrape @RegEx


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


  • 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


  • 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.

JavaScript to Extract Data from Web Page

//--- VER 2.0    2018-03-08  ---
//  Use Revised Order Web Page
//  https://fakeasstore.myshopify.com/admin/orders/326207438900

var custCardElem = document.getElementById('customer-card');

var shipAddrElem = custCardElem.querySelector('p.type--subdued');

EXAMPLE RESULTS: 5 lines of data

Dumme karl
3333 Dummetown