Log It • quickly save plain text snippets to one or more log files


NOTE: This entry and macro were inspired by Brian Kammer’s AUTOMATORS post titled: Quick note taking system.


If you like working in plain text (and Markdown), you might find this useful.


Keyboard Maestro Macro: Log It

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; Clipboard; SafariURL; SafariTitle SafariURL; Clipboard SafariURL; [SafariTitle](SafariURL); [Clipboard](SafariURL)

  2. Optionally change the log file 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 file name.

Logged entries can be confirmed with: Nothing; Sound; Dialog; Sound & Dialog

If Dialog or Sound & Dialog is chosen, the user can then opt to: Do Nothing; Select the log file in the Finder; open the log file using TextEdit.

EXAMPLE USE

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

USAGE
  1. (Optional) From any macOS, copy 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 three buttons: Cancel; Save Settings Only; or OK (default)

  5. If the confirmation dialog was specified to appear, select one of three buttons: Open (o); Select (s); No (default)

SETTINGS

By default, this macro will save log files to: /iCloud Drive/Log It. This can be changed using the local__Folder variable (just below this comment).

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

TESTED WITH
  • Big Sur, v11.2.1
  • Keyboard Maestro, v9.2
  • MacBookPro16,1
VERSION HISTORY

1.0 - Initial version


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


A Log It demonstration video is available here


Log It was contributed using the Keyboard Maestro Forum and can be download from this page.

1 Like

Brian Kammer’s AUTOMATORS post, mentioned above, can be found here.

This is very nice.

I suggest adding a preference setting to define the extension for the log files.

The case is: use this macro as a logger to post to a folder in an Obsidian vault (folder in iCloud). I personally have no use for .txt files. I think other users of markdown for capture log notes would have use for that option.

I modified the macro to change .txt to .md wherever needed to satisfy the logic. Works nice as a front end logger for Obsidian from anywhere.

1 Like

@anon41602260, thanks for the comment.

I could add another main dialog setting, but I could also do this: 1) add another option to the Markdown Content: Paragraph. 2) add logic to use a txt extension if Markdown Context is No, otherwise use an md extension.

I’ll give this some more thought. Feel free to comment again.Thanks again for your feedback.

1 Like

I’m leaning toward a simple solution: add a variable at the beginning of the macro that would allow a user to select the extension (txt | md). If any user has the requirement to both file type, Log It could be copied and renamed (e.g., Log It-md) and each copy could be used when needed.

1 Like

That’s simple. But since apps use different extensions for markdown and text files, the options might need to be {text, txt, md, markdown, mmd}

Thank you for being open to change. The macro is a tour-de-force and obviously took a long time to compose and test. It is a challenge to write macros that branch off into numerous options; and you’ve met the challenge.

1 Like

:+1:

Responding to feedback from @Tomas on the Keyboard Maestro forum, 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).

[ more ]

1 Like

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.


The Log It demonstration video has not been updated since Version 1.0, but everything within still applies to Version 4.0.


[ more ]


I’ve updated Log It to Version 5.2.

Version 5.0

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

Version 5.1

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

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


The Log It demonstration video has not been updated since Version 1.0, but everything within still applies to Version 5.2.


[ more ]