2

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.

hippietrail
  • 15,848
  • 18
  • 99
  • 158
Eric H.
  • 2,152
  • 4
  • 22
  • 34
  • 1
    Why aren't you creating a CSV format file? – S.Lott Dec 29 '11 at 12:36
  • Because I'd like to keep the ".log" name, more significant in my project. – Eric H. Jan 02 '12 at 09:43
  • You can keep `.log` and use CSV. Really. – S.Lott Jan 02 '12 at 13:43
  • 1
    What's wrong with the "Always opens with" manipulation? I don't get the question at all. Please **update** the question to explain more fully what you want to have happen. It appears you want some kind of double-click magic to happen, but don't want to agree with the file name extension rules that make that happen. Keeping `.log` clearly doesn't work. All you can say is that it's "significant" to keep it. But you didn't **update** the question to explain precisely why you reject a working solution. – S.Lott Jan 02 '12 at 17:04
  • And my question is "Since `.csv` works, what's wrong with that?" – S.Lott Jan 03 '12 at 23:07
  • Eric H.: apparently, you don't read what I write. Your question is confusing. "So my question is : How to write the "Always opens with" in python ?" If you want to know how to set Mac OS X Finder properties, you should probably revise your question to eliminate all of the parts which confused people like me and focus on the part you want. How to set the Mac OS X Finder Property. If that's what you really want. – S.Lott Jan 04 '12 at 15:17
  • "it doesn't work (neither CSV format nor .csv extension". Sadly. `.csv` files launch a spreadsheet for me. So, I have trouble completely understanding your problem. – S.Lott Jan 04 '12 at 15:45
  • My problem is the following : 1) I write ".log" files with a python program. I **want** to keep the ".log" extension (or ".txt"); I don't want to rename them ".csv" or ".xls". 2) As a python programmer, I'm asking if there are instructions, probably dealing with resource forks, that mimic the manual operation OS X "Always opens with" that forces a file to be opened a file with another application that the extension (now) makes. My question deals with python capabilities (on Mac OS X). – Eric H. Jan 05 '12 at 06:21
  • "My problem is the following..." belongs in the question, not in the comments. Please **update** the question, rather than adding comments to it. Also, the "I don't want to rename them ".csv"" deserves some explanation. Renaming them actually works. Please explain why the `.log` name is **so** important. And. Please **update** the question rather than adding yet more comments. – S.Lott Jan 05 '12 at 12:52

1 Answers1

0

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.

tkone
  • 22,092
  • 5
  • 54
  • 78