Andy from Webcrunch

Subscribe for email updates:

How Toggle Hidden Files on a Mac without the Command Line
Portrait of Andy Leverenz
Andy Leverenz

December 24, 2014

Last updated November 5, 2023

How Toggle Hidden Files on a Mac without the Command Line

If you develop any sort of application, more often than not you use a tool or framework to help you along the way. Languages such as Ruby, Node.js, or even Git make use of files on your system that aren’t visible by default. Why getting easy access to these files isn’t an option beats me...

Normally, to edit these files you either need to know the path to the file by heart or use a script on the command line to show these files.

This post is a short tutorial to show you how to toggle hidden files on your mac with by creating an easy to use application.

The Old Way

Plain and simple, the old way works. The only issue with it is that it is incredibly hard to remember. Some of you who have ever executed this script may recognize it below.

defaults write com.apple.finder AppleShowAllFiles -boolean TRUE
killall Finder

which when executed shows the hidden files. To undo this you would run

defaults write com.apple.finder AppleShowAllFiles -boolean FALSE
killall Finder

which hides the hidden files, leaving you back where you started.

While this is all valid, it’s easy to forget. Some other resources across the web have introduced their own methods. Some of which make use of the .bash_profile file on your Mac or creating a function to run when needed.

The New Way

Rather than depending on the command line, why not create a small application to do the work for you?

Automator

If you have never used the Automator application on a Mac you are not alone. I rarely had needed to use it before but sometimes, especially for a case such as this, it just makes sense. Follow along below to create an application for toggling hidden files.

Find the automator app within your applications folder and launch it.

Applications/Autmator.app

Step 1 - Create a Service

Create a service upon launching Automator

When Automator launches you are greeted with the screen above. Our application type will be a service Service.

 Search for "Run AppleScript"

After that do a search in the search field for Run AppleScript. Double click on Run AppleScript and you will see some code appear in the pane to the right which looks like this.

on run {input, parameters}
  (* Your script goes here *)
  return input
end run

Step 2 – Customize AppleScript

Add the code below where you see the placeholder ( Your script goes here )

if (do shell script "defaults read com.apple.finder AppleShowAllFiles") is equal to "0" then
    do shell script "defaults write com.apple.finder AppleShowAllFiles 1"
  else
    do shell script "defaults write com.apple.finder AppleShowAllFiles 0"
  end if
    tell application "Finder" to quit
      delay 2
    tell application "Finder" to launch

The code entered looks all too familiar to the “old” way I mentioned earlier. At the heart of the function, the script is checking to see if there is an alternate boolean value (if it’s true or false).

Step 3 - Test the Script

test the script

Before creating an application out of this, it is probably wise to check the code runs correctly. Go ahead and press the play button to verify the files and folders appear or disappear once you click again.

You should see your Finder do a delayed-type of flash which is a good indicator that everything is working. Though, to really verify, open up your main hard drive and you’ll notice some opaque folders you now have access to.

Step 4 - Make it an Application

Up until now everything we have done seems like a lot of work and it was, but this keep in mind is the only time you will have to do this. To make things final we need to create a small application out of this script.

Save the project as something clever for your app name. I chose something easy like Toggle Hidden Files. From here you need to select File/Convert To from the File menu.

file to convert to

Then when the type of application window appears choose Application.
You will create a new project and from here you can save out to an actually application. Be sure to select Application from the file format option like below:

Save the new project as an application file format

I saved my application to the desktop to keep it handy for any working situation where I need to have my hidden files present. You’ll notice it has the same app icon as Automator but if you want a custom icon you can create one and replace it using another app called LiteIcon if you please.

Application Complete!

Good job. You just made yourself a cool little Mac app. Now you won’t have to always do a Google search for the script to make all this happen as I used to ;).

Do you use Automator for other things within your designing or developing workflow? Share your tips or tricks in the comments

Link this article
Est. reading time: 5 minutes
Stats: 502 views

Categories

Products and courses