I have decided to release this little piece of code to help everyone who knows their way around GNU/Linux but is working on a Mac (like me!), but is also no expert at using Mac OS X.
This program unhides and can also rehide every single hidden file on Mac OS X, which are all system files without any known exception.
How is this useful? Say you wanted to add a command to your repository of bash commands. On a GNU/Linux system, you'd just add it to the directory /usr/local/bin, as root or using sudo. On Mac OS X, you'd just add it to the directory /usr/local/bin. However, this directory doesn't exist? Yes it does, it is only hidden, along with many other critical system files. To verify this, open up Terminal and type
/usr/local/bin
into the command line. As you see, this is a directory. It is only hidden.
Unhiding all the hidden directories on a Mac is simple. Just type
defaults write com.apple.finder AppleShowAllFiles TRUE
into the command line, and restart Finder (can be done in the command line via
killall Finder
). However, that's a bit too much typing for me to do on a regular basis, especially considering how often I switch between files visible and files hidden (those system files are EVERYWHERE).
So, here's my program. It has two very highly intuitive options (named "show" and "hide") for showing and hiding system files. Feel free to use and abuse it however you want. It's well commented, I hope to claim, and even addresses how to properly use argv[] (I see threads all the time where people complain about
argv[int] == "string"
not working). Copy and paste the code into a c++ file, and compile it using g++, and enjoy your joyride around the Unix core of Mac OS X!
-Albatross
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
/*
Syshider 1.0
This is a nifty little program that hides/unhides all the hidden files on
a Macintosh system. This program is also Mac OS X specific: it will NOT
run on Windows or Linux. That said, it was created specifically for Mac OS
X because there is no simple and direct way to undo the file hiding.
Be very careful about modifying the files after you've unhidden them. They
were hidden for a reason.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string>
int main (int argc, char *argv[])
{
if(!system(NULL))
{
return -1;
//Just to ensure that there is a shell.
}
/*
The following bit is required. If you omit it and the user doesn't input
an argument, you will get back a segmentation fault or some related
error, and it will not look good at all.
*/
//Check if there is nothing stored at argv[1]
if (argv[1] == NULL)
{
printf("\nUsage: syshider <show|hide>\n");
return 1;
}
if ("show" == std::string(argv[1]))
/*
Good exercise in argv usage. argv[int] == "string" will always return
false. It will always return false because you are not comparing
contents, you are comparing locations. To compare contents, use:
std::string(argv[1]) == "string"
or maybe
!strcmp(argv[1],"string")
However that last one never worked for me. Segmentation fault, always.
*/
{
printf("\nShowing system files...\n");
//Modify the system-wide defaults to show hidden files.
system("defaults write com.apple.finder AppleShowAllFiles TRUE");
//Restart Finder. No, it doesn't kill it permanently.
system("killall Finder");
printf("System files visible. Be careful.\n\n");
return 0;
}
else if ("hide" == std::string(argv[1]))
{
printf("\nHiding system files...\n");
//Modify the system-wide defaults to hide hidden files.
system("defaults write com.apple.finder AppleShowAllFiles FALSE");
//Restart Finder.
system("killall Finder");
printf("System files hidden.\n\n");
return 0;
}
else
{
//You typed in something else than "show" or "hide" as the first
//argument. Time for a refresher?
printf("\nUsage: syshider <show|hide>\n\n");
return 1;
}
return 2;
//I have no idea what happened if the program returned 2, but...
}
|
Enjoy!