I wrote a little app to toggle the hiding/showing of hidden files in the OS X Finder, and I’m going to tell you about it. You can find it here (download link) or on my Projects page. The largest part of this application is the icon. The executable file itself is actually just a shell script, the entire source of which is as follows:
#!/bin/sh
if [ `defaults read com.apple.finder AppleShowAllFiles` = "false" ]; then
defaults write com.apple.finder AppleShowAllFiles true
else
defaults write com.apple.finder AppleShowAllFiles false
fi
osascript -e 'tell application "Finder" to quit'
# Finder often tries to open too quickly (causing weird problems)
# so I tell it to wait a second.
sleep 1
osascript -e 'tell application "Finder" to activate'
After seeing that, you might wonder how I got a stupid little shell script all packaged up so nicely in a .app. I’m running low on ideas to blog about, so I guess I’ll explain!
Basically, every OS X application bundle is really just a bunch of files thrown into a folder. The application you see is just a directory with “.app” appended to the end. To view the contents of an app, simply select it in Finder, click the gear in the toolbar, and select “Show Package Contents”. The two things needed to make an application run are the executable (which resides at MyAppName/Contents/MacOS/executablegoeshere) and an Info.plist file. The executable is the code that runs and the Info.plist just tells the OS what everything in the bundle is. If you open up the plist, you’ll see it’s basically an XML document telling the OS what my executable is called, what the icon is called, and giving my app a unique identifier (com.dylanedwards.houdinifile).
No comments yet.
Leave a comment!
<< Still Alive!

