The Pug Automatic

Hide Leopard stack overlays in Finder

Written November 11, 2007. Tagged OS X, AppleScript.

A tumblelog named XD had a post on adding nice half-icon overlays to Leopard stacks (the below image is from that post).

[Screenshot]

The log does not allow comments, so I'm blogging some minor improvements to this technique:

Handle any sorting

I want my Downloads stack to be sorted by date added, not date modified as in that post. Just change the m to an a:

touch -at 202001010101.01 " Icon"

Note that I've named the icon " Icon" with an initial space. This is so that I can use the same naming scheme with stacks that I sort by name (in my case, my home folder). The reason for using a consistent naming scheme is revealed below.

Hide the overlay icon in Finder

A necessary evil to the overlay trick is that you need to keep an icon file sorted at the top of the stack. To my knowledge, you can't hide it from the expanded stack – well, you can (by renaming it to something starting with a ., like .Icon) but then it's not overlayed…

You can, however, hide it from the Finder by toggling the file's invisible bit. It will still display in the expanded stack (alas) and as an icon overlay (w00t). You can do

chflags hidden " Icon"

If you want to unhide it, do

chflags nohidden " Icon"

However, it turns out that the next time the stack refreshes – that is, the next time a file is added, renamed or removed – it will notice that the file is hidden, and you lose the overlay.

Now, this is a bit too kludgy even for me, but I couldn't resist. I made a folder action that is triggered when a file is added, renamed or removed, and that will show the icon, force a stack refresh, and then hide the action again. What this amounts to is that when the stack changes, you'll only see a short flash of non-overlayness, and then the overlay is re-applied, and does not appear in Finder.

I didn't particularly mind seeing the overlay icon my Downloads folder, but the " Icon" file next to the folders in my home directory was quite annoying.

The folder action is here: Peekaboo Stack Overlay.scpt

See this post for how to apply it.

This folder action explains why I used the " Icons" (with an initial space) name in the Downloads stack as well – the same folder action, with a hard-coded icon name, can be used for multiple stacks.

The code

(*
"Peekaboo Stack Overlay" by Henrik Nyh </2007/11/hide-leopard-stack-overlays-in-finder>
This Folder Action handler is triggered whenever items are added to or removed from the attached folder (and indirectly when they're renamed).
When that happens, it will juggle visible bits and temp files to make the stack reload while the icon is non-hidden, and then hides it again. The end result is that you can keep the icon file hidden in the Finder but still see it overlayed on the stack (and in the expanded stack, alas).
This script assumes an icon named " Icon" (with the space, so it sorts first in alphabetical stacks).
*)


on adding folder items to thisFolder
reapplyStackOverlay(thisFolder)
end adding folder items to

on removing folder items from thisFolder
reapplyStackOverlay(thisFolder)
end removing folder items from

on reapplyStackOverlay(thisFolder)
-- Something happened to reload the stack.
set folderPath to (POSIX path of (thisFolder as alias))
set iconPath to folderPath & "/" & " Icon"
set triggerFile to folderPath & "/" & ".force_stack_reload"
-- Unhide icon
do shell script "chflags nohidden " & (quoted form of iconPath)
-- Force stack to reload
do shell script "touch " & (quoted form of triggerFile)
do shell script "rm -f " & (quoted form of triggerFile)
-- Hide icon
do shell script "chflags hidden " & (quoted form of iconPath)
end reapplyStackOverlay