Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Useful utilities - GetFileInfo and SetFile UNIX
Stuck (almost uselessly) in /Developer/Tools/ are two rather incredible little guys you should immediately link (ln -s) right into /usr/bin/. They are GetFileInfo and SetFile.

For more on how to use these tools, including exactly how to create the links and how to hide a given volume on the desktop (for example), read the rest of this article.

The first thing to do is to link the tools into the standard bin directory. Type this in your Terminal window:
 sudo ln -s /Developer/Tools/GetFileInfo /usr/bin/getinfo
sudo ln -s /Developer/Tools/SetFile /usr/bin/setfile
Note that we're assuming you have the Developer Tools installed! Now type rehash to make sure the system is aware of the new applications.

Let's say you created a separate partition to hold your swap directory. For clarity's sake, you called it swap. The dedicated swap partition thing is going great, but you are annoyed by the appearance of swap on your desktop and you don't want to hide all your drives. Just swap. Well, here we go:
getinfo /Volumes/swap
You should see something like this:
directory: "/Volumes/swap"
type: ""
creator: ""
attributes: avbstclinmed
created: 10/05/2001 22:31:07
modified: 10/18/2001 20:10:53
That lower-case "v" on the attributes line denotes a "0" (as opposed to "1") for the attribute "is invisible." That is quite easy to fix, with SetFile, which we cleverly ln'ed into a useful location:
sudo setfile -a V /Volumes/swap
A getinfo of /Volumes/swap should now reveal a V in the attributes line. A quick relaunch of the Finder is now all that stands between you and an invisible swap partition.

Attributes aren't the only handy part of SetFile, though. Executing SetFile with no options, arguments, or target files will return the proper usage guidelines, along with some rather extensive notes (I suppose that makes up for the lack of manual pages). Attributes, file creator, creation date, modification date, and file type are all at your fingertips.
  • Currently 3.00 / 5
  You rated: 3 / 5 (4 votes cast)

Useful utilities - GetFileInfo and SetFile | 5 comments | Create New Account
Click here to return to the 'Useful utilities - GetFileInfo and SetFile' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Very useful indeed
Authored by: eagle on Oct 19, '01 10:10:26AM
I wrote a QnD (Quick-and-Dirty) script (link) to recognize .doc and .xls files by their extension. Combined with SetFile and ScriptGUI, I can now double-click on MS Office files and have them auto-load into AppleWorks and be properly translated for me. Very cool. All made possible by the SetFile Developer tool.

[ Reply to This | # ]
Use rindex to eliminate loop
Authored by: houchin on Oct 19, '01 01:34:21PM

Great idea!

To improve the script, why don't you just use rindex to get the last period, instead
of looping through the filename. Also, you should probably verify that the files
does have an extension. Here's some code to replace the while loop at the beginning:

$start = rindex($file, ".");
die "Unknown file extension: $file\n" if ($start == -1);
$ext = substr($file,$start + 1);

(due to problems with backslashes in comments, make sure it's $file[backslash]n in the die statement

[ Reply to This | # ]
Use rindex to eliminate loop
Authored by: eagle on Oct 20, '01 02:48:35PM

Thanks for the suggestion. I didn't know about rindex(). I have changed my code per your recommendation.

[ Reply to This | # ]
alternative method
Authored by: sekalreed on Oct 19, '01 02:55:20PM
you could also just add the developer tools to your path by adding the following to your
set path=($path /Developer/Tools .)
save your file, run
and you should be able to just run SetFile, GetFileInfo, MvMac, or any other commands inside /Developer/Tools. this also has the advantage of automatically adding any new commands Apple might place in this directory.

[ Reply to This | # ]
Useful utilities - GetFileInfo and SetFile
Authored by: cpbaldwin on May 12, '06 09:27:32PM

This don't work for me, here is the output from my terminal window.

panther:~ root# getinfo /Groups
directory: "/Groups"
attributes: avbstclinmed
created: 10/26/2004 17:09:37
modified: 10/26/2004 17:09:37
panther:~ root# setfile -a V /Groups
panther:~ root# getinfo /Groups
directory: "/Groups"
attributes: avbstclinmed
created: 10/26/2004 17:09:37
modified: 10/26/2004 17:09:37
panther:~ root#

It don't matter if I'm admin or root, it just don't work.

[ Reply to This | # ]