setfile
ATTRIB for OS X!



I don't know if anyone's noticed, but when you install the apple developer tools, as well as the usual applications, examples, documentation, etc, there are some cute CLI tools, that is; command line interface tools, or in other words.. tools of the terminal! If you're scared of the terminal for some reason, this might be a great opportunity to face your fears. You can't do much harm altering simple file attributes. *snigger*

The one we want is in /Developer/Tools. Do this in the terminal..

cd /Developer/Tools

"cd" is change directory. Now you are in that folder, you can run them with the --h switch, like this..

RezWack --h

and get some useful information about what each of the tools actually does. Many are purely for developers, but some are more generally useful, like the wonderful SetFile. The best way I can think to describe it like attrib for OS X, and if you've never used DOS you won't have a clue what that is either! anyway..

setfile: a swiss-army-knife for file attributes

SetFile is so damned handy I renamed it to "setfile" (typing caps in the terminal just feels wrong) and put it into my PATH (specifically, in /usr/local/bin, though that probably won't be in your path unless you are the kind that installs 3rd party unix binaries. If you want info on how to change your path, grab the "darkstat for OSX" distribution for more info, (darkstat also lives in usr/local/bin which is an excellent place to keep all your own wee tools) If you don't have the dev tools installed, you can download a copy of setfile here.

As a work-around for folks who don't have /usr/local/bin on there system and don't want to mess about with PATH statements, you could do a very nasty thing (this is evil) and drop it into /usr/sbin which should already be in your path, like this:

  1. unzip setfile.gz (stuffit expander is good)
  2. drop it on your desktop, and
  3. do this in the terminal..
sudo mv ~/Desktop/setfile /usr/sbin/setfile
sudo chmod +x /usr/sbin/setfile
Once you have it installed in your PATH (the chmod +x command makes it executable), type setfile in the terminal (you might need to open a fresh terminal window), and you'll see this..

setfile [option...] file...

  -a attributes # attributes (lowercase = 0, uppercase = 1)*
  -c creator # file creator
  -d date # creation date (mm/dd/[yy]yy [hh:mm[:ss] [AM | PM]])*
  -m date # modification date (mm/dd/[yy]yy [hh:mm[:ss] [AM | PM]])*
  -t type # file type


  Note: Period (.) represents the current date and time.
  Note: [yy]yy < 100 assumes 20th century, e.g. 19yy
  Note: The following attributes may be used with the -a option:
  A Alias file
  V Invisible*
  B Bundle
  S System (name locked)
  T Stationary
  C Custom icon*
  L Locked
  I Inited*
  N No INIT resources
  M Shared (can run multiple times)
  E Hidden extension*
  D Desktop*

Note: Options/attributes marked with an asterisk (*) are allowed with folders

or in english..

setfile -a V somefile.jpg

would make somefile.jpg . . . invisible!

In the Terminal, type..

setfile -a V   <-- there's a space at the end of that!

then simply drag somefile.jpg onto the terminal. The filename, with full path, is pasted into place! Oh Macness!!!

Which answers the long-standing "How do I make something invisible without using 3rd party apps?"

Perfect for those hot disks..





be su, be happy

Installing the dev tools now!!!


You need them for more fun having in your OS X terminal of.


;o) corz.org

Welcome to the comments facility!


previous comments (two pages)   show all comments

Andy Fragen - 25.05.05 3:21 pm

setfile is amazing. Just what I was looking for. I had about 10,000 JPEGs that were transferred out of a proprietary database and when exported had unknown values for the creation dates. Combined with EXIFutils I was able to cobble together an AppleScript to pull the date from the filename and set it as creation date with setfile then add it as capture date with EXIFutils.

My only comment would be why not conform to ISO8601 date/time standards? Not a big deal as EXIFutils uses it's own format as well.

Thanks.

Andy


conor - 07.11.05 3:02 am

doesn't work:

nottelling:/Volumes/iPod root# /Users/pandt/Desktop/setfile -a V sbin lib mnt proc sys dev etc tmp usr var home
su: /Users/pandt/Desktop/setfile: Permission denied


Oh and dont worry i wuzn't trying to hide apple macintosh files just ipl files


corz - 07.11.05 12:23 pm

first do..

chmox +x /Users/pandt/Desktop/setfile

or better still, follow the instructions above!

;o)
(or


conor - 24.11.05 4:03 am

still visible even when i relaunch finder


corz - 24.11.05 2:04 pm

Off the top of my head, perhaps you have a recent version of OS X and need an updated setfile. Grab the latest dev tools and see if it works. If so, mail me a copy, I'll bung it here.

I haven't played with recent versions of OS X, my mac is “en panne”, like the Pool tables in every single Hotel in France.

;o)
(or


J. Hider - 16.04.08 12:34 pm

What's wrong with adding a . to the beginning of the name? Granted, it's not the proprietary HFS+ way, but the Unix/BSD way, but it works just as well.

Hide:
mv filename .filename

Unhide:
mv .filename filename



corz - 16.04.08 11:38 pm

Well, firstly, there's the "more typing" part. It looks nice on paper, but you still have to get into that directory to do something so cute. With setfile, you simply type one command, and then drag-and-drop your file. It's been a long time since I've been near a Mac, but I'm pretty sure Mac users prefer this kind of approach.

Then there's the trouble folk will get into when, thinking this dot thing is a cool idea, they try to do it in the Finder, instead. Ouch!

Also, it's pretty ugly, and folk might not want the name of the file to change. But of course, technically, there's nothing "wrong" with your method of making files invisible; it's the method I use on my own *nix boxes; but only because there isn't a better one.

Anyway, it was just one example of setfile's many tricks, which is what the page is about.

;o)
(or


BrocknessMonsta - 22.06.08 6:21 pm

Does it matter if the -a is uppercase or lowercase?
On another site that was explaining this stuff it mentioned that -a means 0 and -A means one...


corz - 23.09.09 7:38 pm

BrocknessMonsta, It is explained fully in the article, above (help output).

;o)
Cor


Phyre - 16.03.10 9:03 pm

Worked perfect for me, thanks! I tried using it before and didn't realize it needed a space.


Mawan A. Nugroho - 28.09.12 4:17 am

For users of Mac OS X, we can also use the built-in command CHFLAGS. For example:

chflags -R nohidden /Volumes/flashdisk/*


First, confirm that you are human by entering the code you see..

(if you find the code difficult to decipher, click it for a new one!)


gd verification image