It's about the code 

Facebook Twitter Gplus LinkedIn RSS

Apple Script: Show and Hide Hidden Files on Mac

I need to show hidden files quite often and rather than leaving the hidden files visible all the time, e.g. .localized and .DS_Store files showing on desktop, I rather toggle hidden file visibility on and off. The terminal command for this is:

$ defaults write com.apple.Finder AppleShowAllFiles TRUE
$ killall Finder

applescript logo image - rights by respective owner
The first line here sets hidden files visible and the second line refreshes Finder. Change the boolean to ‘FALSE’ in order to hide the files again.
This works great but its a pain and I just wanted to make it simple and fast. I’m aware of Hidden Files but wasn’t able to install at the time of this post due to redirection to iCloud, which I don’t use. As a result, I decided to just write a simple Apple Script as an application that I can keep in my dock.
Here is the script:

display dialog "Show Hidden Files..." buttons {"SHOW", "HIDE"} default button 2
copy the result as list to {buttonpressed}

try
	if the buttonpressed is "HIDE" then do shell script "defaults write com.apple.finder AppleShowAllFiles FALSE"
	if the buttonpressed is "SHOW" then do shell script "defaults write com.apple.finder AppleShowAllFiles TRUE"
end try

do shell script ("killall Finder")

The first line launches a dialogue with button options for SHOW or HIDE. The button press result is placed in a variable, ‘buttonpressed’ and then checked in a try condition. Finder is then refreshed.
Simply compile the script and Save As an application.

 

One Response

  1. [...] Apple Script: Show and Hide Hidden Files on Mac (dougr.net) [...]

Home AppleScript Apple Script: Show and Hide Hidden Files on Mac
credit