MACRO: Log It, v5.2—Quickly Save Plain Text Snippets to One or More Log Files


PURPOSE

This macro provides a method to quickly save plain text snippets to one or more log files. A user can add snippets quickly because the macro writes directly to the text log files, i.e., the user is not required to interact with a separate macOS application.

In addition, using settings included on the main dialog of the macro, a user can customize the logging behavior:

  1. Define the Content to preload:
    Nothing; Selection; Clipboard;
    SafariURL; SafariTitle SafariURL; Selection SafariURL; Clipboard SafariURL;
    [SafariTitle](SafariURL); [Selection](SafariURL); [Clipboard](SafariURL);
    ChromeURL; ChomeTitle ChromeURL; Selection ChromeURL; Clipboard ChromeURL;
    [ChomeTitle](ChromeURL); [Selection](ChromeURL); [Clipboard](ChromeURL)

  2. Optionally change the Log Filename each day.

  3. Replace, Prepend, or Append to an existing log file.

  4. Optionally add a Timestamp Prefix to every snippet saved.

  5. Optionally apply Markdown syntax: Bold; Italic; Bold Italic; Blockquote; Inline code; Syntax Highlighting

  6. Optionally Shorten a URL.

  7. Specify a Content Suffix which effectively acts as a delimiter between captures snippets.

The main dialog also provides a field that allows the user to change the Log Filename.

Constructed snippets written to log files can be confirmed with: Sound; Dialog; or Sound & Dialog.

If Dialog or Sound & Dialog are chosen, the user can then opt to: Open (the log file using the default text editor), Select (the log file in the Finder), or do nothing.

DEMONSTRATION

The following video includes more information including five example uses of Log It: youtu.be/Zp-8BHhxPLY. Although several options have been added since the recording, everything within the video still applies.

EXAMPLE APPLICATION

When reading webpages, a user could save several excerpts by simply selecting portions of each webpage and invoking this macro.

USAGE

  1. (Optional) From any macOS, select some text.
  2. Launch this macro. The main dialog will be displayed.
  3. (Optional) Change one or more settings in the main dialog.
  4. Select the one of four buttons: Cancel; Save Settings Only; Write to Clipboard; OK. The default, OK, writes the constructed snippet to a log file. Alternatively, Write to Clipboard, updates the macOS Clipboard, not a log file.
  5. If the confirmation dialog was specified to appear, select one of three buttons: Open; Select; No

WRITING TO CLIPBOARD

The primary purpose of this macro is to write text to log files. However, the main dialog includes a Write to Clipboard button that, when selected, the content will be written to the Clipboard rather than a log file. Moreover, if ⌥(Option key) is down when the Write to Clipboard button is selected, the Timestamp Prefix and Content Suffix will be excluded.

BYPASS MAIN DIALOG

To bypass the Log It main dialog, trigger the macro by adding the ⌥(Option key). This can be particularly useful for logging several text snippets in quick succession.

SETTINGS

  1. By default, this macro will save log files to: /iCloud Drive/Log It. This can be changed using the local_Folder variable.
  2. By default, this macro will create log files with a txt extension. This can be changed using the local_Extension variable.
  3. local_DICT. See below: MULTIPLE INSTANCES OF LOG IT

RESETTING

Many of the variable values set in the main dialog persist from one use to the next. To reset Log It to the default values, launch it by adding ⌘(Command key).

MULTIPLE INSTANCES OF LOG IT

The following Log It values are saved in a KM Dictionary and persist, that is, they will be retained from one run to the next: Auto New Each Day, Start With, No Selection Use Clipboard, Mode. Add Timestamp Prefix, Markdown Content, Shorten URL, Content Suffix, Log Filename, Confirm With

If Log It is simply duplicated (e.g., suppose one wants to write to more than one folder), the values above will be shared between the two copies. To maintain independent settings, change the value of local_DICT from the default value of jsLI_dict, e.g., to jsLI_dict2.

ACKNOWLEDGEMENTS

Log It was inspired by Brian Kammer's Automators post titled: Quick note taking system, https://talk.automators.fm/t/quick-note-taking-system/4912.

TESTED WITH

  • Keyboard Maestro, v10.0.2
  • Monterey, v12.2.1/MacBookPro16,1
  • Mojave 10.14.16/Macmini6,2
  • High Sierra 10.13.6/iMac11,1445

VERSION HISTORY

1.0 Initial version

2.0 a) Added a setting for the file extension; the default is txt. Some users might want to create files with an md or some other extension. b) Added option Always to the Auto New Each Day setting.

3.0 a) Added and option to bypass the main dialog by adding ⌥(Option) when launching. b) For loading the default settings, the modifier was changed from ⌥(Option) to ⌘(Command).

4.0 a) For Start With added these options: ChromeURL; ChromeTitle ChromeURL; Clipboard ChromeURL; [ChromeTitle](ChromeURL); [Clipboard](ChromeURL); b) Updated this comment to include the section: MULTIPLE INSTANCES OF LOG IT; c) Bug fix: With Start With corrected the Clipboard SafariURL option: %Clipboard%, not %SystemClipboard% was mistakenly used.

5.0 a) Added button/option: Write to Clipboard. b) Added Start With options: Selection, Selection SafariURL, [Selection](SafariURL), Selection ChromeURL, [Selection](ChromeURL). c) Added option: if nothing selected replace Selection with Clipboard.

5.1 No functional changes since v5.0. Fixed the revision date in the macro header comment.

5.2 All persistent values are now saved to a single KM Dictionary named jsLI_dict, where js are my initials and LI refers to the name of this macro. For more information about this approach to saving values, refer to Dialog with Dynamic Popup List. In cases where multiple copies of Log It are required (with independent settings), this macro can be copied and the value of local_DICT can be changed in the copy.


Download: Log It.kmmacros (226 KB)

Macro-Image


Macro-Notes
  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.

System Information
  • macOS 14.3.1 (23D60)
  • Keyboard Maestro v11.0.2


Even if you have no use for the Log It features as described above, if you are a Keyboard Maestro beginner, you might find that this macro is a useful learning tool. It includes actions that:

  • set default values for macro settings; these settings are saved to a single KM Dictionary and retain their values between macro invocations
  • determines if the macro trigger included ⌘(Command); if so, reset the macro settings to default values
  • check if a file previously exists
  • remove a trailing slash in a folder path (if it includes one)
  • check if a folder exists; check if it contains 0, 1, or more files
  • check if a file can be written to a folder
  • check if a filename is in format: YYYY-MM-DD
  • check if a filename is in format: YYYY-MM-DD some suffix
  • check if a folder includes additional files, i.e., files in addition to the text file being currently used
  • display a main dialog that is context sensitive (displays differing text; addition variable fields; different variable choices)
  • can conditionally shorten a URL using tinyurl.com (without requiring an API)

Log It includes many Keyboard Maestro standard actions; in addition, it includes several simple uses of the Run Shell Script and the Run AppleScript actions.

8 Likes

This is great, well done!

1 Like

Wow! What an outstanding Macro!
:+1:

Thanks for sharing.

1 Like

Responding to feedback from @quorm on the Mac Power Users Forum, I've updated Log It to Version 2.

  • Added a setting for the file extension; the default is txt. Some users might want to create files with an md or some other extension.
  • Added option Always to the Auto New Each Day setting.
2 Likes

Excellent. Thank you for version 2.

1 Like

15 posts were split to a new topic: Debugging – System Clipboard Token Not Working

Hi Jim:
Is there a way to: execute the Macro WITHOUT the dialog box coming up?

1 Like

Responding to feedback from @Tomas, I've updated Log It to Version 3.0.

  • Added and option to bypass the main dialog by adding ⌥ (Option) when launching.

  • For loading the default settings, the modifier was changed from ⌥ (Option) to ⌘ (Command).

2 Likes

Hi @Tomas. Please give Version 3 a try. Of course, you'll need to display the main dialog one time to change the Confirm With setting.

Confirm With

Jim: Many, many thanks for version 3 - this is great! I really appreciate the effort you have put into this.

I hope I am not trying your patience but:

  1. Is there a way to have two versions of the macro with different "Starts With" entries? I tried duplicating the macro, giving the 2nd one a different "Start With" type, and a different hot key, but it seems that the Start Type change will also change the 1st version of the macro.

  2. If wanted to change the Start With browser from Safari to say Firefox, is all I have to do is change every instance of "Safari" in the macro to "Firefox"?

1 Like

You're welcome, @Tomas.

Note that SafariURL and SafariTitle are Keyboard Maestro Tokens. There are no corresponding tokens for Firefox.

If you want to prepopulate the Log It main dialog with a Firefox URL, you can use the clipboard:

  1. In Log It, set Start With to Clipboard.
  2. In Firefox on the page of interest, move to the address bar (⌘L) and copy the URL (⌘C).
  3. Launch Log It.

If you want a Markdown link from a Firefox webpage, I recommend using Copy as Markdown Link by @ComplexPoint. It’s awesome!

  1. In Log It, set Start With to Clipboard.
  2. Open Firefox and navigate to the page of interest.
  3. Run Copy as Markdown link
  4. Launch Log It

@Tomas, after considering the above, if you still need a second copy of Log It (with independent settings), let me know and I’ll provide instructions.

Jim - Thanks for the explanation about Firefox vs Safari with Log It.

If it's not too much of a pain in the neck, could you send me the instructions for a second copy of Log It? I think it could be useful....

Thanks again

1 Like

2022-02-12 UPDATE: With Log It, v5.2, the steps in this post have been superseded by a much simpler method.

For more information, refer to the macro header comment, section MULTIPLE INSTANCES OF LOG IT.

Just curious, how will you use a second copy?

I found this post by @JMichaelTX. In it he provides a macro named: BETA Change KM Variable Prefix (rename) to Local in All Actions @DEV.kmmacros. I tested it and it seemed to work quite well for Log It.

Instructions:

  1. Download and enable BETA Change KM Variable Prefix (rename) to Local in All Actions @DEV.kmmacros. It will install in a group named [KM]. It can remain there.

  2. Create a Hot Key Trigger for the downloaded macro.

  3. Make a copy of Log It, rename it (e.g., Log It B), and place the copy in the [KM] group.

  4. In the Keyboard Maestro editor, select the renamed Log It and launch the downloaded macro using the Hot Key Trigger set above.

  5. When the macro dialog opens, enter the following:

CurrentPrefix : jsLI__
NewPrefix : jsLI_2__

Note: The first prefix needs to be exactly as specified. Both prefixes need to end with two underscores (__).

  1. Review the dialog that summarizes your specifications.

The macro will create a copy of the renamed Log It and after a few seconds of execution will display a window summarizing the changes. Note that you will want to keep the macro you renamed, not the backup created by the macro.


FYI: These are the Log It values that persist and can be found in Keyboard Maestro > Preferences > Variables

jsLI__Add Timestamp Prefix
jsLI__Auto New Each Day
jsLI__Confirm With
jsLI__Content Suffix
jsLI__if nothing selected replace Selection with Clipboard
jsLI__Log Filename
jsLI__Markdown Content
jsLI__Mode
jsLI__Shorten URL
jsLI__Start With

this is almost a full-fledged note app!
it works in the same way like the app Daygram(https://www.daygram.today/) i use on my phone.
big thanks, jims!

1 Like

You're welcome, @xsmk; glad you like it. In Keyboard Maestro, @peternlewis has created an incredible tool that can be used in many creative ways.

2 Likes

I've updated Log It to Version 4.0.

  • For Start With added these options: ChromeURL; ChromeTitle ChromeURL; Clipboard ChromeURL; [ChromeTitle](ChromeURL); [Clipboard](ChromeURL)

  • Updated this comment to include the section: MULTIPLE INSTANCES OF LOG IT; c) Bug fix: With Start With corrected the Clipboard SafariURL option: %Clipboard%, not %SystemClipboard% was mistakenly used.

3 Likes

Hi Jim:

Many thanks for v4 of Log It - I really appreciate all you work/help with this. For your info - I had wanted more than 1 version of Log It so I could copy/paste different content types into different logs without having to go through the Input window...

1 Like

I've updated the OP with Version 5.0 of Log It.

  • Added button/option: Write to Clipboard.

  • Added Start With options: Selection, Selection SafariURL, [Selection](SafariURL), Selection ChromeURL, [Selection](ChromeURL).

  • Added option: if nothing selected replace Selection with Clipboard.

1 Like

I've updated the OP with Version 5.2 of Log It.

5.2 All persistent values are now saved to a single KM Dictionary named jsLI_dict, where js are my initials and LI refers to the name of this macro.

For more information about this approach to saving values, refer to Dialog with Dynamic Popup List.

In cases where multiple copies of Log It are required (with independent settings), this macro can be copied and the value of local_DICT can be changed in the copy.