Hiding Files in OS X

Just a quick post which might help anybody who wants to be able to hide files in Finder on their mac.
The chflags command lets you set a hidden flag that prevents a file from appearing in Finder (not the same as prepending the name with a . which is the typical way of hiding files in a unix based system)
This automator service creates a context menu in Finder to hide files easily. To show them again requires Terminal since you clearly can’t click a file you can’t see!
To show files the command is chflags nohidden [FILE]
(or add sudo if needed)
the code is as follows.
on run {input, parameters}
set myfilepath to (last item of input) as text
set command to "sudo chflags hidden \"" & POSIX path of myfilepath & "\""
do shell script command password "MY PASSWORD" with administrator privileges
end run

Code as above in Applescript action
If you don’t want your password saved in plain text in the automator file then simply remove the password “…” part and you will be prompted each time.

EDIT: It is also possible to manually add a Keychain item containing your password and have applescript use that instead. I don’t have the code to hand but if you’re interested then let me know.