In Python, how to set a resource fork to a file having an extension to open another application under Mac OS X

694 Views Asked by At

After having created a text file whose extension is ".log" (or ".txt") under Mac OS X, I used to force it to be opened with Excel instead of a text editor or console when clicking it, with the following code :

pathlog=os.path.join(d, "output.log")
log = open(pathlog, "w")
...
log.close()
os.system("SetFile -t 'XLS ' -c XCEL %s" % pathlog)

Unfortunateley, it used to work, but now doesn't work anymore with newer Mac OS X (I use 10.6): when I click the file, it opens the text editor. It correctly works if I name it with an unknown file extension (like ".logx"). But I'd like to keep the ".log" extension name, more speaking, not rename it ".xls" or ".csv".

In Finder, in the file properties, I have to choose "Always open with Microsoft Excel.app", which sets a resource fork for that file.

So my question is : How to write the "Always opens with" in python which adds a resource fork to a file to force it to be opened with a different application than its extension implies ?

Thanking you for your help, Eric.

1

There are 1 best solutions below

0
On

TL;DR you might not be able to do it EASILY from a script.

Here's how you can do it from the command line. Mac Creator Signature and File Types

BUT. Snow Leopard changed how creator and type codes work, so that above link is out-of-date for 10.6 and 10.7.