Forum > Operating Systems

Path to application on Mac?

<< < (2/2)


--- Quote from: Spoonhorse on January 02, 2023, 03:24:40 pm ---All I need is for the app to be able to find out where it is. Why should this be difficult?

--- End quote ---
The application is in Application.Location.

I use this. Its not an example of elegance, but it works.

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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;

wp --- alas, that gives the same results on the Mac as everything else I've tried.

Don Alfredo --- thanks. That works! I shall put it with the other useful code snippets I don't quite understand ...


--- Quote from: Spoonhorse on December 31, 2022, 10:23:48 am ---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/

This doesn’t exist. >:D

--- End quote ---

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).


[0] Message Index

[*] Previous page

Go to full version