Recent

Author Topic: Mac application bundle and ExtractFilePath(Application.ExeName)  (Read 5968 times)

ozznixon

  • Jr. Member
  • **
  • Posts: 88
    • http://www.modernpascal.com/
Re: Mac application bundle and ExtractFilePath(Application.ExeName)
« Reply #15 on: June 02, 2018, 05:59:21 pm »
It's simple:

ExtractFilePath(Paramstr(0))

That returns the folder where your progname binary is. e.g. /path to the progname.app/Contents/MacOS/
---
Want to kick the tires to a Free Pascal like script engine? http://www.ModernPascal.com/

Gilles

  • New Member
  • *
  • Posts: 37
Re: Mac application bundle and ExtractFilePath(Application.ExeName)
« Reply #16 on: June 20, 2018, 07:01:44 am »
I used to do that (I know, it is deprecated) :

Code: Pascal  [Select][+][-]
  1.  
  2.     function f_GetAppDir (var L_dir: SInt32; var x_vrn: SInt16): t_OSErr;
  3.         var
  4.             L_psn: ProcessSerialNumber;
  5.             xx_cat: FSCatalogInfo;
  6.             xx_ref: FSRef;
  7.             L_oss: OSStatus;
  8.             xErr: OSErr;
  9.             L_err: t_OSErr;
  10.     begin
  11.         L_err := 1;
  12.                
  13.     { - }
  14.                
  15.         L_oss := GetProcessBundleLocation(L_psn, xx_ref);
  16.        
  17.         if L_oss = noErr then
  18.         begin
  19.             xErr := FSGetCatalogInfo(xx_ref, kFSCatInfoVolume + kFSCatInfoParentDirID,
  20.                                                     @xx_cat,
  21.                                                     nil, nil, nil);
  22.                        
  23.             if xErr = noErr then
  24.             begin
  25.                 L_dir := xx_cat.parentDirID;
  26.                 x_vrn := xx_cat.volume;
  27.     { - }
  28.                 L_err := k_noErr
  29.             end
  30.             else
  31.                 L_err := xErr
  32.         end
  33.         else
  34.  
  35.     { - }
  36.  
  37.         f_GetAppDir = L_err
  38.     end;
  39.  

DEPRECATED, but it works on Mac OS 64 bits
« Last Edit: June 20, 2018, 08:28:37 am by Gilles »
TurboPascal -> ThinkPascal -> CodeWarrior -> XCode with FPC -> (Well-deserved) Retirement (but not yet, not yet…)

RayoGlauco

  • Full Member
  • ***
  • Posts: 108
  • Beers: 1567
Re: Mac application bundle and ExtractFilePath(Application.ExeName)
« Reply #17 on: June 20, 2018, 09:07:55 am »
Maybe I am saying something everybody knows, but there is a function called ProgramDirectory: http://lazarus-ccr.sourceforge.net/docs/lcl/fileutil/programdirectory.html  :)
To err is human, but to really mess things up, you need a computer.

 

TinyPortal © 2005-2018