Application directory and exe name lazarus / 33-macOS - Mac OS X ---------------------------------------------------------------------- apeoperaio · 2020-12-21 12:37 I would like to know if there is a way to get my application directory on macOS. On Windows and Linux I can use ParamStr(0) and Application.ExeName but on macOS they don't work in the same way as in Windows and Linux (documented here: https://www.freepascal.org/docs- html/rtl/system/paramstr.html). Here two different tests. On macOS if I add the path of my application to PATH: export PATH=/Applications/myapp.app/Contents/MacOS:$PATH If I use ParamStr(0) I get: myapp If I use Application.Exename I get: /Applications/myapp.app/Contents/MacOS/myapp If I create a link to myapp: ln -s /Users/myname/Documents/myapp myapplnk using ParmaStr(0) I get: myapplnk Using Application.Exename I get: /Users/myname/Documents/myapplnk Is there a way to get the full path of my exe even using macOS commands? ---------------------------------------------------------------------- trev · 2020-12-21 12:46 I'm not completely sure what you're trying to do, but check my Wiki articles: * Locating macOS app bundle, resources directories - [on re-reading your post you're probably after this article] * Locating macOS significant directories * Locating macOS app support, preferences folders One of them should have what you want - if not please clarify what you are after and why. ---------------------------------------------------------------------- apeoperaio · 2020-12-21 16:14 Dear @trev, Thank you for the information and links. What I am trying to do is to get the full path of my application, regardless where my executable is. I tried: NSBundle.mainBundle.executablePath.UTF8String This function provides me the full path of my application executable, except if I call my application using a symbolic link. If I call my application through a symbolic link NSBundle.mainBundle.executablePath.UTF8String gives me the full path to my symbolic link. Is there a function that can be used to get the full path of my application? Thank you. ---------------------------------------------------------------------- Jonas Maebe · 2020-12-21 17:25 Application.Exename uses the official function for that. The fact that it returns a symbolic link's location if that's how the application is started, is therefore by design. It also enables the Lazarus trick of creating an application bundle that contains a symbolic link to an executable outside the bundle. Starting an application bundle via a symbolic link that resides outside that bundle is simply not something that is supported on macOS (at least not if the application needs any resources that are inside the application bundle). Conversely, you can have two different application bundles with one having a symbolic link to an exe in the other bundle, and you'll be able to start both application bundles independently, each considering their own bundle as "the" application location. Hence, if you try to hack your way around the way the system behaves by default, you are going to have a different view on where your exe is located vs what the system considers to be its location. That is not a good idea. ---------------------------------------------------------------------- apeoperaio · 2020-12-22 08:57 Got it, thank you