Path to application on Mac? lazarus / 23-Operating Systems ---------------------------------------------------------------------- Spoonhorse · 2022-12-31 09:23 I’m using Lazarus on the Mac for the first time, trying to port/finish a little app in preparation for porting a bigger app. In order to locate the resources for the app, I figured I needed to know where it was located. (If I’m wrong, and I’m setting y’all an XY problem, please let me know.) But whether I use Paramstr(0) or the more approved Application.ExeName, then on the Mac instead of getting the actual file path /Users/myname/Documents/Hamsters/project1, I instead get /Users/myname/Documents/Hamsters/project1.app/Contents/MacOS/project1 This doesn’t exist. Any advice? Thanks for your help. ---------------------------------------------------------------------- Leledumbo · 2023-01-02 11:01 https://wiki.freepascal.org/Multiplatform_Programming_Guide#On_Unix_th ere_is_no_.22application_directory.22 ---------------------------------------------------------------------- wp · 2023-01-02 11:23 I'm not a mac specialist, but this questions might be related to application bundles: https://wiki.freepascal.org/Multiplatform_Programming_Guide#macOS_2 ---------------------------------------------------------------------- Spoonhorse · 2023-01-02 14:09 Thank you both. OK, Macs are weird, converting my Big Project's source from Windows to Windows-and-Mac is going to be a doozy I can see. I think I can finish off this little one now though. ---------------------------------------------------------------------- Spoonhorse · 2023-01-02 14:24 It still seems strange though. In both this little practice project and in the big one, what I want to do among other things is (a) include some example files of the type that the app uses, accessible from the File menu of the app (b) include a file that remembers which file you have open and opens it when you open the app, so I can ship it "remembering" that it's looking at '/examples/example1.foo' in the app directory. This has all been a great deal of trouble to try to get it to work under all circumstances and yet it seems such an obvious and modest thing to want to do. All I need is for the app to be able to find out where it is. Why should this be difficult? ---------------------------------------------------------------------- wp · 2023-01-02 15:54 Quote from: Spoonhorse on January 02, 2023, 03:24:40 pmAll I need is for the app to be able to find out where it is. Why should this be difficult? The application is in Application.Location. ---------------------------------------------------------------------- DonAlfredo · 2023-01-02 18:11 I use this. Its not an example of elegance, but it works. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function SafeGetApplicationPath: String;var  StartPath: String;  {$ifdef Darwin}  x:integer;  {$endif}begin {$ifdef LCL} StartPath:=Application .ExeName; {$else} StartPath:=Paramstr(0); {$endif} {$ifdef Darwin} // we need the .app itself !! x:=pos('/Contents/MacOS',StartPath); if x>0 then begin   Delete(StartPath,x,MaxInt);   (*   x:=RPos('/',StartPath);   if x>0 then   begin     Delete(StartPath,x+1,MaxInt);   end;   *) end; {$endif} if FileIsSymlink(StartPath) then begin   try     StartPath:=GetPhysicalFilename(StartPath,pfeException);   except   end; end; result:=StartPath;end; ---------------------------------------------------------------------- Spoonhorse · 2023-01-03 01:50 wp --- alas, that gives the same results on the Mac as everything else I've tried. ---------------------------------------------------------------------- Spoonhorse · 2023-01-03 01:57 Don Alfredo --- thanks. That works! I shall put it with the other useful code snippets I don't quite understand ... ---------------------------------------------------------------------- PascalDragon · 2023-01-03 20:32 Quote from: Spoonhorse on December 31, 2022, 10:23:48 amIn order to locate the resources for the app, I figured I needed to know where it was located. (If I’m wrong, and I’m setting y’all an XY problem, please let me know.) But whether I use Paramstr(0) or the more approved Application.ExeName, then on the Mac instead of getting the actual file path /Users/myname/Documents/Hamsters/project1, I instead get /Users/myname/Documents/Hamsters/project1.app/Contents/MacOS/project1 This doesn’t exist. That is the correct path, because on macOS an App is in fact simply an archive that contains the binary and other required resources. Which also provides the answer to your question: the resources are supposed to be located inside the App archive as well (except if you have multiple Apps sharing the same resources; that would probably be a task for a Framework then). ---------------------------------------------------------------------- JollyHong · 2026-07-23 12:10 I'd also suggest creating a small test project to reproduce the issue before changing your main code. It usually makes debugging much easier and helps confirm whether the problem is project-specific or something more general.