[Pythonmac-SIG] Spotlight Importing without .py
Nicholas Matsakis
matsakis at mit.edu
Sat Jan 21 08:01:28 CET 2006
http://www.apple.com/downloads/macosx/spotlight/pythonmetadataimporter.html
I really dig the Spotlight Metadata Importer for python, but it only works
for files ending in ".py" which excludes various shell scripts I have
written that have no filename extension. Anyone have a super elegant
solution to this problem?
Here's my thoughts on the matter. To my knowledge, Mac OS X has only
three ways of knowing the type of a file: the HFS type code, the filename
extension, and the presence of an executable bit on a file* (in order of
precidence). I've already nixed filename extensions and the executable bit
only seems to be able to identify something as a "Unix Executable File".
So, that leaves HFS type codes. The first question is whether this is an
HFS type code lying around from the days of yore that identified a python
executable script? If not, would anyone mind if I registered one? (Once
we've got a suitable type code, modifying the Spotlight Metadata Importer
to claim it is no big deal).
The more challenging part is to actually affix that type code on all
extension-less python executables; As far as Mac OS X is concerned these
files have no type, so there isn't a trivial way to write a script that
would search for them and tag them. Using spotlight, you can at least
limit your search to text and executable files, but you would still need
to example their contents individually to know whether they should be
tagged. This script would have to be run periodically or, if you put all
such scripts in a common location you could create a launch item for it.
As a crazy alternative to all of the above, the python metadata importer
could be written to work in conjunction with spotmeta
(http://www.fluffy.co.uk/spotmeta/) to additionally run on all text or
executable files and only add the python metadata if the file actually is
a python file. Not that I'm suggesting this be done or anything, but I
think its an interesting idea. Hopefully Leopard will provide a more
elegant solution to this problem.
Nick Matsakis
* The saddest part of this story is that /usr/bin/file has been on Mac OS
X since day one and understands perfectly well what a "a python script
text executable" is. Yet, when the Finder encounters a file without an
extension or HFS code rather than, say, looking at the file to see what
kind it is, it absolves all responsibility and forces you to find an
application that might open it.
More information about the Pythonmac-SIG
mailing list