<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: mous-design</title>
    <description>The latest articles on DEV Community by mous-design (@mousdesign).</description>
    <link>https://dev.to/mousdesign</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3600473%2F02a0a6d8-8f43-42d1-8802-fe32c710544a.png</url>
      <title>DEV Community: mous-design</title>
      <link>https://dev.to/mousdesign</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mousdesign"/>
    <language>en</language>
    <item>
      <title>Plug in, back up, auto-eject: Time Machine for a disk you don't leave connected</title>
      <dc:creator>mous-design</dc:creator>
      <pubDate>Sun, 08 Nov 2026 07:34:20 +0000</pubDate>
      <link>https://dev.to/mousdesign/plug-in-back-up-auto-eject-time-machine-for-a-disk-you-dont-leave-connected-14gk</link>
      <guid>https://dev.to/mousdesign/plug-in-back-up-auto-eject-time-machine-for-a-disk-you-dont-leave-connected-14gk</guid>
      <description>&lt;p&gt;If your Time Machine disk lives on a dock, you know the danger: unplug your laptop and you get a “Disk Not Ejected Properly” warning. Furthermore, if you leave the disk connected with default settings, Time Machine backs up every hour, filling it with way too many snapshots.&lt;/p&gt;

&lt;p&gt;What I actually wanted was simple: when I plug the disk in, back up if it's been a while, then eject it so I can just yank the cable. So I wrote a small Folder Action that does exactly that.&lt;/p&gt;

&lt;h2&gt;
  
  
  How it works
&lt;/h2&gt;

&lt;p&gt;macOS can run a script whenever something changes in a folder. Disks mount under &lt;code&gt;/Volumes&lt;/code&gt;, so a Folder Action on &lt;code&gt;/Volumes&lt;/code&gt; fires whenever a disk appears. The script then:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Checks whether the disk that appeared is the correct disk.&lt;/li&gt;
&lt;li&gt;Checks with &lt;code&gt;tmutil latestbackup&lt;/code&gt; when the last backup was.&lt;/li&gt;
&lt;li&gt;If it's older than &lt;code&gt;MIN_INTERVAL&lt;/code&gt; (I use 12 hours), runs &lt;code&gt;tmutil startbackup --block&lt;/code&gt;, which waits until the backup is done.&lt;/li&gt;
&lt;li&gt;Unmounts the disk with &lt;code&gt;diskutil unmount&lt;/code&gt;, falling back to a forced unmount if needed.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Plug in, have a coffee, unplug. No clicking.&lt;/p&gt;

&lt;h2&gt;
  
  
  Failing visibly
&lt;/h2&gt;

&lt;p&gt;One design choice I care about: &lt;strong&gt;if anything goes wrong, the disk stays mounted.&lt;/strong&gt; A disk that's still there when you expected it gone is a visible signal that something needs a look. The reason ends up in &lt;code&gt;~/Library/Logs/backup-action.log&lt;/code&gt;. Silent failure is the worst kind of failure (for any code actually), specially for backups.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setup
&lt;/h2&gt;

&lt;p&gt;Nothing to install. It's one zsh script plus Automator (see README for details):&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Set the disk name and interval at the top of the script.&lt;/li&gt;
&lt;li&gt;Set Time Machine to back up manually (otherwise it'll keep doing its own hourly thing).&lt;/li&gt;
&lt;li&gt;Give &lt;code&gt;FolderActionsDispatcher&lt;/code&gt; Full Disk Access in System Settings / Privacy &amp;amp; Security. Without this, &lt;code&gt;tmutil&lt;/code&gt; can't do its job from a Folder Action.&lt;/li&gt;
&lt;li&gt;Create a Folder Action in Automator on &lt;code&gt;/Volumes&lt;/code&gt; that runs the script.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You can test it from Terminal first by passing the disk path as an argument, which is much nicer than plugging and unplugging while debugging.&lt;/p&gt;

&lt;p&gt;Tested on macOS 26.&lt;/p&gt;

&lt;h2&gt;
  
  
  Get it
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://github.com/mous-design/backup-action" rel="noopener noreferrer"&gt;github.com/mous-design/backup-action&lt;/a&gt;&lt;/strong&gt; (MIT)&lt;/p&gt;

&lt;p&gt;If you have a different setup (multiple backup disks, network targets) I'd be curious how you'd extend it. Issues and PRs welcome.&lt;/p&gt;

</description>
      <category>macos</category>
      <category>automation</category>
      <category>showdev</category>
      <category>shell</category>
    </item>
  </channel>
</rss>
