Skip to content

Instantly share code, notes, and snippets.

@jpoehls
Created June 26, 2012 20:04
Show Gist options
  • Save jpoehls/2998520 to your computer and use it in GitHub Desktop.
Save jpoehls/2998520 to your computer and use it in GitHub Desktop.
Toggle hidden files in Finder. (AppleScript)
-- Save this to your documents and tell Alfred to look for (and execute AppleScripts).
-- There has never been an easier to way to toggle hidden files in Finder.
try
set state to do shell script "defaults read com.apple.finder AppleShowAllFiles" as string
if state is "0" then
do shell script "defaults write com.apple.finder AppleShowAllFiles -bool TRUE"
else
do shell script "defaults write com.apple.finder AppleShowAllFiles -bool FALSE"
end if
end try
tell application "Finder" to quit
delay 1
tell application "Finder" to launch
@unlox775
Copy link

unlox775 commented Dec 15, 2016

This does not work first time, when the prefs file does not exist, or when prefs exist, but the setting does not. Try this:

set state to 0
try
set state to do shell script "defaults read com.apple.finder AppleShowAllFiles" as string
end try
if state is "1" then
do shell script "defaults write com.apple.finder AppleShowAllFiles -bool FALSE"
else
do shell script "defaults write com.apple.finder AppleShowAllFiles -bool TRUE"
end if
tell application "Finder" to quit
delay 1
tell application "Finder" to launch

@zaazz
Copy link

zaazz commented Jul 19, 2017

Thanks for the super handy script. You can make an app for it using Automator so it runs without opening Script Editor.

A small tweak: using "kill all finder" keeps your current finder windows open.

set state to 0
try
set state to do shell script "defaults read com.apple.finder AppleShowAllFiles" as string
end try
if state is "1" then
do shell script "defaults write com.apple.finder AppleShowAllFiles -bool FALSE"
else
do shell script "defaults write com.apple.finder AppleShowAllFiles -bool TRUE"
end if
do shell script "killall Finder"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment