Search code examples
macoscocoaxcode4

Cocoa, output current App path


I am working on OS X application. In the code, I would like to output a path of the current Mac OS App to a variable for future use. So later I could read the files in the same folder. Could anyone tell me the command/method in the Xcode ?

Thanks very much.

UPDATE

To be more clear, I am using xcode and create a cocoa-application. My application is connected with applescript to control Mac software read files on the Mac. So I have to return the files' directory and name.

Actually I have no idea about what to do. So got stuck here.


Solution

  • To get the URL of your application, you can use:

    [[NSBundle mainBundle] bundleURL]
    

    See the NSBundle Class Reference for further information.