{
  "version": "https://jsonfeed.org/version/1.1",
  "title": "@beardic.us",
  "home_page_url": "https://beardic.us/",
  "feed_url": "https://beardic.us/feed.json",
  "description": "Brian Boucheron's blog.",
  "language": "en",
  "authors": [
    {
      "name": "Brian Boucheron",
      "url": "https://beardic.us/about"
    }
  ],
  "items": [
    {
      "id": "https://beardic.us/optimizing-macos-screenshots",
      "url": "https://beardic.us/optimizing-macos-screenshots",
      "title": "Automatically Optimizing macOS Screenshots",
      "summary": "How to automatically optimize PNG screenshots on macOS using Folder Actions and optipng.",
      "content_html": "<p>I take a lot of screenshots at work, and I’m always annoyed that I have to manually run <a href=\"https://optipng.sourceforge.net/\"><code>optipng</code></a> over them to fully enshrink them for the web. Recently, I took a moment to automate this problem away using macOS’s <em>Folder Actions</em> feature. Folder Actions allow you to attach an AppleScript or Automator workflow to a folder, to be run when items are added to (or modified in or deleted from) the folder.</p>\n<p>If you desire the same automation magic, start by putting the following AppleScript file into <code>~/Library/Workflows/Applications/Folder Actions/</code>:</p>\n<pre class=\"astro-code astro-code-themes github-light github-dark\" style=\"background-color:#fff;--shiki-dark-bg:#24292e;color:#24292e;--shiki-dark:#e1e4e8; overflow-x: auto; white-space: pre-wrap; word-wrap: break-word;\" tabindex=\"0\" data-language=\"applescript\"><code><span class=\"line\"><span style=\"color:#D73A49;--shiki-dark:#F97583\">on</span><span style=\"color:#005CC5;--shiki-dark:#79B8FF\"> adding folder items to</span><span style=\"color:#24292E;--shiki-dark:#E1E4E8\"> thisFolder </span><span style=\"color:#D73A49;--shiki-dark:#F97583\">after</span><span style=\"color:#24292E;--shiki-dark:#E1E4E8\"> receiving theseItems</span></span>\n<span class=\"line\"><span style=\"color:#D73A49;--shiki-dark:#F97583\">\trepeat</span><span style=\"color:#D73A49;--shiki-dark:#F97583\"> with</span><span style=\"color:#E36209;--shiki-dark:#FFAB70\"> thisItem</span><span style=\"color:#D73A49;--shiki-dark:#F97583\"> in</span><span style=\"color:#24292E;--shiki-dark:#E1E4E8\"> theseItems</span></span>\n<span class=\"line\"><span style=\"color:#D73A49;--shiki-dark:#F97583\">\t\tset</span><span style=\"color:#24292E;--shiki-dark:#E1E4E8\"> fileName </span><span style=\"color:#D73A49;--shiki-dark:#F97583\">to</span><span style=\"color:#005CC5;--shiki-dark:#79B8FF\"> name</span><span style=\"color:#D73A49;--shiki-dark:#F97583\"> of</span><span style=\"color:#24292E;--shiki-dark:#E1E4E8\"> (</span><span style=\"color:#005CC5;--shiki-dark:#79B8FF\">info for</span><span style=\"color:#24292E;--shiki-dark:#E1E4E8\"> thisItem)</span></span>\n<span class=\"line\"><span style=\"color:#D73A49;--shiki-dark:#F97583\">\t\tif</span><span style=\"color:#24292E;--shiki-dark:#E1E4E8\"> fileName </span><span style=\"color:#D73A49;--shiki-dark:#F97583\">starts with</span><span style=\"color:#032F62;--shiki-dark:#9ECBFF\"> \"Screenshot\"</span><span style=\"color:#D73A49;--shiki-dark:#F97583\"> and</span><span style=\"color:#24292E;--shiki-dark:#E1E4E8\"> fileName </span><span style=\"color:#D73A49;--shiki-dark:#F97583\">ends with</span><span style=\"color:#032F62;--shiki-dark:#9ECBFF\"> \".png\"</span><span style=\"color:#D73A49;--shiki-dark:#F97583\"> then</span></span>\n<span class=\"line\"><span style=\"color:#D73A49;--shiki-dark:#F97583\">\t\t\tset</span><span style=\"color:#24292E;--shiki-dark:#E1E4E8\"> filePath </span><span style=\"color:#D73A49;--shiki-dark:#F97583\">to</span><span style=\"color:#005CC5;--shiki-dark:#79B8FF\"> POSIX path</span><span style=\"color:#D73A49;--shiki-dark:#F97583\"> of</span><span style=\"color:#24292E;--shiki-dark:#E1E4E8\"> thisItem</span></span>\n<span class=\"line\"><span style=\"color:#005CC5;--shiki-dark:#79B8FF\">\t\t\tdo shell script</span><span style=\"color:#032F62;--shiki-dark:#9ECBFF\"> \"/opt/homebrew/bin/optipng \"</span><span style=\"color:#D73A49;--shiki-dark:#F97583\"> &#x26;</span><span style=\"color:#005CC5;--shiki-dark:#79B8FF\"> quoted form</span><span style=\"color:#D73A49;--shiki-dark:#F97583\"> of</span><span style=\"color:#24292E;--shiki-dark:#E1E4E8\"> filePath</span></span>\n<span class=\"line\"><span style=\"color:#D73A49;--shiki-dark:#F97583\">\t\tend if</span></span>\n<span class=\"line\"><span style=\"color:#D73A49;--shiki-dark:#F97583\">\tend repeat</span></span>\n<span class=\"line\"><span style=\"color:#D73A49;--shiki-dark:#F97583\">end</span><span style=\"color:#005CC5;--shiki-dark:#79B8FF\"> adding folder items to</span></span></code></pre>\n<p>This AppleScript receives the path of any files added to the folder and runs them through <code>optipng</code> if the filename matches <code>Screenshot*.png</code>.</p>\n<p>Name the file whatever you like. I chose <code>optimize-screenshots</code>. Update <code>/opt/homebrew/bin/optipng</code> to the location of <code>optipng</code> on your system. This is where <a href=\"https://brew.sh/\">homebrew</a> puts it. If you don’t have <code>optipng</code>, install it with homebrew using <code>brew install optipng</code>, or check out the <a href=\"https://optipng.sourceforge.net/\"><code>optipng</code> website</a> for more options.</p>\n<p>Open your home folder in the Finder, then right-click (or <code>control</code> click) the <code>Desktop</code> folder. Click <strong>Folder Actions Setup…</strong> in the context menu.</p>\n<p>You are prompted to <strong>Choose a Script to Attach</strong>. Find your script, probably near the bottom of the list, select it, then click the <strong>Attach</strong> button. You should see a window similar to the following <strong>Folder Actions Setup</strong> interface:</p>\n<figure><img alt=\"Screenshot of the Folder Actions Setup interface, with &#39;Desktop&#39; list on the left &#39;Folders with Actions&#39; pane, and &#39;optimize-screenshots&#39; listed on the right under &#39;Script&#39;\" sizes=\"(min-width: 52rem) 48rem, calc(100vw - 2rem)\" loading=\"lazy\" decoding=\"async\" data-astro-image=\"constrained\" data-astro-image-pos=\"center\" width=\"1642\" height=\"934\" src=\"https://beardic.us/_astro/folder-actions-setup.CD8MMNGD_Z4HDzq.webp\" srcset=\"https://beardic.us/_astro/folder-actions-setup.CD8MMNGD_vMLTC.webp 640w, https://beardic.us/_astro/folder-actions-setup.CD8MMNGD_Z2jfdxD.webp 750w, https://beardic.us/_astro/folder-actions-setup.CD8MMNGD_Z2h7tb.webp 828w, https://beardic.us/_astro/folder-actions-setup.CD8MMNGD_29HXdi.webp 1080w, https://beardic.us/_astro/folder-actions-setup.CD8MMNGD_Z2vajEA.webp 1280w, https://beardic.us/_astro/folder-actions-setup.CD8MMNGD_Z4HDzq.webp 1642w\"><figcaption>Screenshot of the resulting <strong>Folder Actions Setup</strong> interface.</figcaption></figure>\n<p>This shows that <code>optimize-screenshot</code> is attached to the <code>Desktop</code> folder. Ensure that the <strong>Enable Folder Actions</strong> checkbox is checked and you’re done. The next screenshot you take will automatically be processed through <code>optipng</code>after a second or three. You’ll see a gear icon in the menu bar indicating a script is being run.</p>\n<p>If you use the Desktop folder often and don’t want an AppleScript running every time you do so, you might choose to have macOS save screenshots to a different location. Press <code>command + shift + 5</code> to bring up macOS’s interactive screenshot interface, then click the <strong>Options</strong> button and set an alternate location in the <strong>Save to</strong> section of the menu. Attach the <code>optimize-screenshots</code> script to your alternate location using the same method.</p>",
      "date_published": "2024-12-24T00:00:00.000Z",
      "tags": [
        "screenshot",
        "automation",
        "applescript",
        "macos"
      ],
      "image": "https://beardic.us/og/optimizing-macos-screenshots.png"
    },
    {
      "id": "https://beardic.us/minimum-viable-obsidian-plugin",
      "url": "https://beardic.us/minimum-viable-obsidian-plugin",
      "title": "Minimum Viable Obsidian Plugin",
      "summary": "I made a simple Obsidian plugin called Draft Indicator. You, too, can make Obsidian plugins without fiddling with TypeScript.",
      "content_html": "<p>I made an <a href=\"https://obsidian.md/\">Obsidian</a>  plugin last week. It’s called  <a href=\"https://github.com/beardicus/obsidian-draft-indicator-plugin\">Draft Indicator</a> and all it does is stick a little ✎ pencil icon next to any file that is marked as <code>draft</code>.</p>\n<figure><img alt=\"A screenshot of an Obsidian window, with two files listed in the file explorer panel. One filename, called &quot;Yes a Draft&quot; is italicized and has a small pencil icon to its right\" sizes=\"(min-width: 52rem) 48rem, calc(100vw - 2rem)\" loading=\"lazy\" decoding=\"async\" data-astro-image=\"constrained\" data-astro-image-pos=\"center\" width=\"830\" height=\"418\" src=\"https://beardic.us/_astro/draft-indicator-screenshot.CHa7Nnq__Z19SYOs.webp\" srcset=\"https://beardic.us/_astro/draft-indicator-screenshot.CHa7Nnq__ZaxlSn.webp 640w, https://beardic.us/_astro/draft-indicator-screenshot.CHa7Nnq__1kwT88.webp 750w, https://beardic.us/_astro/draft-indicator-screenshot.CHa7Nnq__Zw8hOz.webp 828w, https://beardic.us/_astro/draft-indicator-screenshot.CHa7Nnq__Z19SYOs.webp 830w\"><figcaption>A screenshot of an Obsidian vault. There is a tiny pencil.</figcaption></figure>\n<p>I thought this would be a fairly trivial bit of code to write – and it was – but when I first cloned <a href=\"https://github.com/obsidianmd/obsidian-sample-plugin\">Obsidian’s sample plugin template</a> I was overwhelmed. It’s full of ESLint and esbuild and TypeScript config files, and there are build scripts and dev servers and on and on.</p>\n<p>I just wanted to write a little blob of JavaScript.</p>\n<p>So I ripped a lot of stuff out. And I wrote my plugin in 42 lines of plain JavaScript, and it works fine and makes me happy.</p>\n<p>I took what I learned from this process and made <a href=\"https://github.com/beardicus/obsidian-simple-sample-plugin\">obsidian-simple-sample-plugin</a>, a template that implements the same API examples as the official sample plugin, but stripped down to plain JavaScript. If you have an idea for an Obsidian plugin but were intimidated by TypeScript and its associated tooling, maybe check it out.</p>",
      "date_published": "2024-05-08T15:56:19.000Z",
      "tags": [
        "programming",
        "obsidian",
        "javascript"
      ],
      "image": "https://beardic.us/og/minimum-viable-obsidian-plugin.png"
    }
  ]
}