Forum > macOS / Mac OS X

How can I get application directory?

<< < (2/3) > >>

luigi65:
Sorry for my misinformation, but I am a newbie in Mac OSX.
This is first time that I try to porting an application from Linux to OSX.

Thanks for your precious information.

I now understand that I have to substitute the symlink with the actual executable into .app file.

Excuse me if I'm not clear in my exposition, but GetCurrentDir return / if I launch the application as double-clicking the .app in Finder or as "open myapp.app" in terminal.
If I run from IDE GetCurrentDir return the path where is the executable file (e.g. /Developer/Projects/test).

Now, if I have some auxiliaries files that my executable must use then I put this files into Contents/MacOs of the bundle, is it right?


Thanks

Phil:
Take a look at the structure of other .app bundles on your system. Typically there's a Resources folder in the bundle for additional files. You can reference it from your app via a relative path from ParamStr(0).

Also, be sure to review the extensive Apple documentation on bundles. Essentially a bundle has a place for anything you could possible want to add, including local frameworks, localizations, compiled libraries, etc.

I assume you've looked at this (from this subtopic to the end is essential reading for anyone new to OS X programming):

http://wiki.lazarus.freepascal.org/OS_X_Programming_Tips#Adding_an_icon_to_your_app_bundle

Thanks.

-Phil

Jonas Maebe:

--- Quote from: luigi65 on February 17, 2009, 11:35:36 am ---Sorry for my misinformation, but I am a newbie in Mac OSX.
This is first time that I try to porting an application from Linux to OSX.

--- End quote ---

You may want to read this information first then: http://developer.apple.com/documentation/Porting/Conceptual/PortingUnix/intro/chapter_1_section_1.html


--- Quote ---Excuse me if I'm not clear in my exposition, but GetCurrentDir return / if I launch the application as double-clicking the .app in Finder or as "open myapp.app" in terminal.

--- End quote ---

That is normal and expected. You may want to read all messages titled "specifying the relative path to a file that is located in the same folder as the application bundle? " at http://lists.freepascal.org/lists/fpc-pascal/2009-February/thread.html (note that there are two separate threads).


--- Quote ---Now, if I have some auxiliaries files that my executable must use then I put this files into Contents/MacOs of the bundle, is it right?

--- End quote ---

No, that is not correct. Where to put which files is described in the Introduction to Bundle Programming Guide, under "Anatomy of a Modern Bundle".

dusanx:
ExtractFilePath(ParamStr(0));

Edit: and ExcludeTrailingPathDelimiter(ExtractFilePath(ParamStr(0)))+'/../../somefolder' works too.

Jonas Maebe:

--- Quote from: dusanx on February 18, 2009, 12:39:10 am ---ExtractFilePath(ParamStr(0));

Edit: and ExcludeTrailingPathDelimiter(ExtractFilePath(ParamStr(0)))+'/../../somefolder' works too.

--- End quote ---

Paramstr(0) must only be used on Dos and Windows (and maybe OS/2). On all other platforms the results are unpredictable and it will not work as you expect (in the best case it will never work; in the worst case it will only fail under certain circumstances, resulting in hard-to-find bugs). Read the mailing list thread I quoted above for more information.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version