Easy Backup (Export) & Restore of Selected Macro

backup
applescript
macros

#1

Continuing the discussion from Feature requests: Easy way to backup and restore macros, separate windows for macros, turn off auto-save:


Use Case

  • I also have long wanted an easy KM Macro Backup/Restore system.
  • So, in collaboration with Chris @ccstone, we developed the backup script, and Macro.
    • I have to say this runs very very fast, taking << 1 sec.
  • The below macro provides the Backup part
  • Easy to Restore Using Finder and/or Path Finder
    • Set Finder to your Backup Folder
    • Filter using the Spotlight Search box at the top right
    • View the filtered list in order by time stamp
    • View the contents of selected files using either Quick Look, or the Path Finder Preview panel
    • Double-click on the .kmmacros file you want to restore
      • ADDS (does not overwrite) the Macro to the same Macro Group
    • Edit as needed
  • See below for how to use, and examples of output.

Examples of Output

Standard Notification when Done

image

Example List of Backup Files

image


MACRO:   Export (Save) Selected Macro @KM

~~~ VER: 2.2    2019-03-23 ~~~

DOWNLOAD:

Export (Save) Selected Macro @KM.kmmacros (22 KB)
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.
It was also uploaded with

  • a trigger of S, which is NOT used by the Keyboard Maestro.app.
  • In a Macro Group activated ONLY when KM is frontmost.

As always, please feel free to post any questions, issues, and/or suggestions that you may have about this macro.


ReleaseNotes

Author.@JMichaelTX based on Script by @ccstone

PURPOSE:

  • Export Current Macro being Edited to a Backup Folder
    • Macro File is Macro Name & Time Stamp
    • Illegal File Chars ("/" and ":") replaced with "╏"

HOW TO USE

  1. Select a Macro for Editing in the Keyboard Maestro.app
  2. Trigger this macro.

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.
    .
  • REVIEW/CHANGE THE FOLLOWING MACRO ACTIONS:
    (all shown in the magenta color)

    • Set Local__BackupFolder -- POSIX path to folder you want to save all macro backups.
      image
  • SCRIPT CHANGES:

    • If you want to use the script without passing the BackupFolder path to it from KM, then you will need to change this property statement in the script:
### USER SCRIPT SETTINGS ###
-- HFS Path to Your Macro Backup Folder --
property ptyExportFolderHFS : "CHANGE:To HFS Path:Of your:Backup Folder:" ###JMTX ADD


REQUIRES:

  1. KM 8.2+
  2. macOS 10.11.6 (El Capitan)

TAGS: @Macros @Backup @Save @AppleScript

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 a modest amout of 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.

image


#2

Is there a way to tweak this macro so you can backup/export:

  1. More than 1 macro at a time

  2. An entire folder/group of macros at one time

Thanks


#3

Yes. You just need to modify the script to work the the macro selection, or the macro group.
Not hard, but I don't have the need or the time to develop at this time.

See Scripting the Keyboard Maestro editor for some examples of how to do this.


#4

Unfortunately this is beyond me to do...