MACRO: Log It, v5.1 – 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 tex 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 βŒ₯ (the 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 βŒ₯ (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.

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 ⌘ (the Command key).

MULTIPLE INSTANCES OF LOG IT
The following Log It values 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 a user wants to write to more than one folder), the values above will be shared between the two copies. These instructions on the Keyboard Maestro forum outline the process to create Log It instances that maintain independent values.

ACKNOWLEDGEMENTS
Log It was inspired by Brian Kammer's Automators post titled: Quick note taking system, bit.ly/2NjPaXO.

TESTED WITH
β€’ Monterey, v12.1; Mojave 10.14.16
β€’ Keyboard Maestro, v10.0.2
β€’ MacBookPro16,1, Macmini6,2

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 - fixed the revision date in the macro header comment. No functional changes since v5.0.

DOWNLOAD Macro File:
Log It.kmmacros (221 KB)
Note: This macro was uploaded in a DISABLED state. It must be ENABLED before it can be run. If it does not trigger, the macro group might also need to be ENABLED.

Macro-image



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 global variables, i.e., variables that retain their values between macro invocations
  • determines if the macro trigger included βŒ₯; 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.

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

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.

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.

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

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.

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

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.

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.

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.

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.

1 Like