Locating invisible items in folder

Maybe I’m re-inventing the wheel, but…

after trying to find short/simple code to identify invisible items in a folder without going thru the ponderous “… visible of info for…” I decided to let Applescript do the heavy lifting.

tell application "Finder"
		set x to target of front window as string
	on error
		display dialog "No finder window open" buttons {"Cancel"} giving up after 3
	end try
	-- Since there is no "List Folder without Visibles," make two lists

	set y to list folder (x as alias) with invisibles
	set z to list folder (x as alias) without invisibles
	--Isolate invisibles by comparing lists and create a new list minus the visibles

	set the_list to {}
	repeat with this_item in y
		if z does not contain this_item then set the_list to the_list & this_item
	end repeat
	--Isolate a single item for more information
	set theItem to choose from list the_list with prompt "Invisible items in \"" & (name of (x as alias)) & "\"" OK button name "Select" cancel button name "Done"
	if theItem is false then return [i]-- you hit cancel button[/i]
	display dialog "You selected" & return & "\"" & theItem & "\", which is a " & (kind of (x & theItem as alias))
end tell

Model: iMac G4
AppleScript: 1.9.3
Browser: Firefox
Operating System: Mac OS X (10.3.9)

surely just saying “choose file” is enough, leaving out the “without invisibles” part?


tell app "Finder"
choose file
end tell

Call me lazy, but I didn’t want to have to sift thru all the non-invisibles. Plus, aside from the dotted filenames, “Choose File” doesn’t neatly indicate which files are invisible or not. All started with trying to find stray hidden window background pictures in folders full of regular pics. (I’m untidy in addition to lazy.)

This also seems to work, and it doesn’t require a repeat loop.

tell application "Finder"
		set theFolder to target of front Finder window as alias
	on error
		set theFolder to desktop as alias
		-- Or handle this however you want
	end try
end tell

tell application "System Events"
	set invisFiles to path of files of theFolder whose visible is false or name starts with "."
end tell

tell application "Finder"
	get name of theFolder
	set userSelection to choose from list invisFiles with prompt "Invisible items in "" & result & "":" OK button name "Select"
	if result is false then error number -128 -- User canceled.
	-- Do what you want with the input
	return userSelection
end tell

When getting the front window in Finder, you should look for Finder windows (see my script). Otherwise, you could end up with, say, a Get Info window.

ahhh… I keep forgetting that “System Events” can work miracles. Somewhere in there is the code for turning base metals into gold if only I could stumble upon it. thanx for the help.

in a terminal paste this: defaults write com.apple.Finder AppleShowAllFiles YES

restart the finder :slight_smile:


You are missing the point of the thread.

Its not so you can see Invisible items populated all over the place as I suspect your command does.

Its so you can only see them when and from where you want, without changing any system settings.

Cool. Thanks for the scripts.

I haven’t done it, but I suspect that it would be straight-forward to run ls -a (with leading dots), ls -A (without leading dots), and diff in a shell script to get them too. Of course I never make anything invisible except by saving it with a dot, so this won’t find files you’ve set ‘visible’ for.