Hacks, Hazel, macOS

Roundabout Syncing

I don't mean for this blog post to only be more complaining. It's just my dumb solution to a Finder bug I've been running into for years. And also a great example of how a little bit of automation can go a long way. (And an even better example of how unique the macOS ecosystem is that tools like this can exist - and how scared I am that (despite assurances) we seem to be headed in a direction where powerful and clever apps are not wanted.)

Anyway, something must have broken in Finder around when Apple integrated iCloud Drive into macOS Sierra in 2016. That's when I noticed that the files on my Desktop would stop appearing on...my Desktop.

The bug first caught my attention when I'd take a screenshot and expect it to, you know, be saved to the Desktop. Except the file would never show up. But at some point, I noticed that the files were there. I could ls them in Terminal. They just weren't visible in the GUI.

Missing Finder Files

I also saw this happening when I'd save files directly to the Desktop from other apps. More curiously, I could force the missing files to appear if I created a new folder on the Desktop. Boom! Something would refresh, I'd see all my files, and I'd delete the temporary folder.

After a while, I eventually realized this bug only happened when I had iCloud Desktop and Documents syncing turned on. That was a bit of an aha! moment for me. Because it seemed to jive with how iCloud Drive just sort of has a "hope for the best" approach to file syncing.

When something goes wrong, you never know about it. Just silent failures with no error messages. (Modern Apple is allergic to error messages.) No way to recover or force a sync to kick-off. At least with Dropbox, you can quit the app and relaunch to get a fresh start. But with iCloud baked into the system, often your only recourse is a system restart.

This all seems like a symptom in line with Gruber's article from last year titled "What You See in the Finder Should Always Be Correct". He writes

Everything the Finder displays should be correct all the time...the visual representation of the file system in the user interface should be treated with almost the same amount of attention...It creates mistrust in an aspect of the system that the user should, ideally, trust completely.

And concludes with this perfect analogy.

The Finder should treat every bit of information it displays as though it's as important as your bank account balance.

And that's precisely it. I lost trust in the Finder in recent years as I caught bugs like what he described and my own.

But I was stuck. I mean, wow, I loved having my Desktop synced. It was such an excellent addition to my workflow when it worked. It just killed me that having that feature enabled meant I couldn't be sure if what macOS displayed reflected reality or not.

(A synced Desktop has become such an integral part of how I work with my active project files that it led to this ridiculous experiment.)

While thinking about writing this post, I quipped a snarky tweet a few days ago

Tweet screenshot

If I could go back in time and alter any tech industry decision at my whim, it would be to convince Steve Jobs to acquire Dropbox. It turns out that a folder that syncs reliably is a really awesome feature and would make things so much easier.

It was a reference to my solution to the problem that I mentioned without much context last Summer

Tweet screenshot

sudo rm -rf ~/Desktop
ln -s \~/Dropbox/Desktop/ ~/Desktop
sudo chflags -h schg ~/Desktop

Not for the faint of heart, but it works. And I haven't caught Finder reporting inaccurate / delayed data since turning off iCloud Drive.

For those who don't speak nerd, that's me deleting my Desktop folder and replacing it with another folder inside Dropbox.

And you know what? The missing file bug goes away, and I still get the convenience of a synced Desktop folder.

But there was still a missing piece. The other significant part about having my Desktop synced through iCloud was how easy it made shuttling files from iOS to my Mac.

Many times during the day, I'll export a file from an iOS app and drop it into iCloud → Desktop in Files.app so I can grab it quickly on macOS and do something with it. I do this all the time with iOS screenshots to capture bug reports and store them on my Desktop to triage later.

So, switching to Dropbox sync made Finder more reliable, but it meant that files I saved from iOS would appear buried in the regular iCloud Drive folder on my Mac - not nearly as convenient a location.

I tried saving files on iOS into Dropbox's section of the Files.app, but that didn't sync reliably unless I opened the Dropbox app on my phone to force a sync.

Because that's the funny dichotomy here. On macOS, for whatever reason, I haven't found iCloud Drive syncing to be very reliable despite having all the resources of an always-on, not power-constrained OS. But on iOS, because it is more resource-constrained and doesn't allow arbitrary background processes, Dropbox doesn't sync reliably - even though iCloud Drive on iOS typically works great for me since it's baked into the system with extra privileges.

Getting to the point of this blog post, here's my solution.

Hazel.

I've swapped out both my iMac and laptop's Desktop and Documents folders for alternate locations inside Dropbox using the scary shell script above. This gives me the super awesome, fast, and versioned syncing that I trust. And also keeps Finder in line.

On my phone or iPad, when I want to export a file to my Mac, I save it into Files.app → iCloud → Desktop, since that results in faster and more reliably syncing.

Then, I have Hazel watching that iCloud folder on my (always on) iMac with a rule that moves any file from my iCloud Desktop folder to the one inside Dropbox. (And renames the file if there is a duplicate.)

Hazel Screenshot

Within a few seconds (given the appropriate bandwidth), the file from iOS is available on all my devices right where I want it.

I hate to say it, but it works great.