"Executing" a File

  • I want to be able to programmatically open or "execute" a random file.  For
    example, if I open a .jpg, it would open in Preview.  If I open a .doc, it
    would open in Word.  And so on.  Basically, just execute the default "open
    action" for the file.

    (Forgive me for this, but) in Windows code, I can just tell .NET to "open" a
    file, and it will do the default action.  NSTask seems to need an
    executable.  How do I find that executable?

    Thanks.
  • [[NSWorkspace sharedWorkspace] openFile: pathToFile];

    On 4-Oct-07, at 10:48 PM, Chris Williams wrote:

    > I want to be able to programmatically open or "execute" a random
    > file.  For
    > example, if I open a .jpg, it would open in Preview.  If I open
    > a .doc, it
    > would open in Word.  And so on.  Basically, just execute the default
    > "open
    > action" for the file.
    >
    > (Forgive me for this, but) in Windows code, I can just tell .NET to
    > "open" a
    > file, and it will do the default action.  NSTask seems to need an
    > executable.  How do I find that executable?
    >
    > Thanks.
  • Thank you.  I knew it had to be simple, but an hour of searching the docs
    didn't help.  Got it working now.

    > From: Guy English <guy.english...>
    > Date: Thu, 4 Oct 2007 22:53:32 -0400
    > To: cocoadev <cocoa-dev...>
    > Subject: Re: "Executing" a File
    >
    > [[NSWorkspace sharedWorkspace] openFile: pathToFile]
previous month october 2007 next month
MTWTFSS
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Go to today