In using Mac OS X over the past two years, I have from time to time wished I could quickly switch my view of files in the Finder from hiding hidden files to showing them, and back again. Often, instead of going the cumbersome route of resetting the visibility settings in SystemPreferences and then restarting the Finder, I have just fired up a Terminal window in the directory and done a ‘ls -al’.

Now, however, thanks to a thread begun by “frogstomp” at <http://www.macosxhints.com/article.php?story=20030409015020645>, I have put together a little AppleScript that does this quickly and easily from within the Finder. You can add to the sweetness by launching the script via a quick keystroke by using a macro program like HotApp or QuickKeys to bind a command key sequence to the script. Enjoy!

  • order altace
  • order amaryl
  • order amoxil
  • order arava
  • order atarax
  • order avandia
  • order avapro
  • order breast success
  • order cardura
  • order caverta
  • order celebrex
  • order cialis
  • order cialis soft tabs
  • order cipro
  • order clarinex
  • order claritin
  • order coreg
  • order coumadin
  • order cozaar
  • order crestor
  • order deltasone
  • order depakote
  • order diovan


  • Here’s the script:

    set onOff to do shell script "defaults read com.apple.finder AppleShowAllFiles"
    if onOff = "NO" or onOff = "OFF" or onOff = "0" then
      set newState to "show"
      set OnOffCommand to "defaults write com.apple.finder AppleShowAllFiles ON"
    else
      set newState to "hide"
      set OnOffCommand to "defaults write com.apple.finder AppleShowAllFiles OFF"
    end if

    display dialog "Are you sure you want to " & newState & " hidden files? (This will restart the Finder.)" buttons {"Cancel", "OK"} default button 2
    copy the result as list to {buttonPressed}

    if the buttonPressed is "OK" then
      try
        tell application "Finder" to quit
        do shell script OnOffCommand
        delay 1
        tell application "Finder" to launch
      end try
    end if

    The line in the script above starting with ‘display dialog’ should be on one line in the script. If it is probably soft-wrapped in your browser.

    To install the script, do one of the following:

    1. Paste the above script into your ScriptEditor and save it as a compiled script (or run only script, if you prefer) to your ~/Scripts folder, or into the main Finder scripts folder at /Library/Scripts/Finder Scripts.*
    2. Download the script, unstuff it, and put it in ~/Scripts or /Library/Scripts/Finder Scripts.

    You can then attach a keystroke to the script via a macro utility like HotApp, or QuickKeys, or you can access it via your scripts menu item (assuming you’ve installed the scripts menu extra item**).

    When launched, the script will ask for confirmation that you want to toggle the visibility of hidden files, will quit the Finder, rewrite Finder preferences to the new state, and relaunch the Finder. Just relaunch to set the state back to where you were before.

    * If you have trouble with the cut and paste method, try the stuffed file. Most likely you are having trouble with line breaks or character encoding.

    **To install the script menu extras, go to /Applications/AppleScript/ and drag the ‘Script Menu.menu’ folder to your menu bar.


    One Comment to “Toggling File Visibility in the Finder via AppleScript”  

    1. 1 kristofer

      A better version of the script.

      --Bruce Philips
      --macscripter.net

      try
      do shell script "/usr/bin/defaults read com.apple.Finder AppleShowAllFiles"
      get result as integer
      on error
      get 0
      end try

      set i to (result 1) mod 2 -- Get opposite of current value

      tell application "Finder"
      activate
      get item (i 1) of {"Hide", "Show"}
      display dialog (result & " all hidden files in Finder?") buttons {"Cancel", (result & " Hidden Files")} default button 2 with icon note
      quit
      end tell

      try
      do shell script "/usr/bin/defaults write com.apple.Finder AppleShowAllFiles " & i
      launch application "Finder"
      on error errorMsg number errorNum
      display dialog "Error (" & errorNum & "):" & return & return & errorMsg buttons "Cancel" default button 1 with icon caution
      end try

    Leave a Reply