Forum > Unix

File path to ${HOME}

(1/2) > >>

cryppyrc:
I am new to this forum (and new to pascal) so I hope this question is in the appropriate sub section.

I am trying to compile an app for macOS that was written with a focus on Windows users and I don't understand how I need to adjust the code to make it work on Darwin.

If executed on Linux or Windows from CLI, the app creates two folders (wallet and data) in the app directory. On Darwin this obviously does not work because apps have no permission to write to the app bundle. Therefore I am trying to find a way to adjust the paths of the code snippet below to point to the respective user's home directory ${HOME} in Darwin.

Path definition:

--- 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";}};} ---CONST  WalletDirectory   = 'wallet'+directoryseparator;  // Wallet folder  DataDirectory     = 'data'+directoryseparator;  WalletFileName    = WalletDirectory+'wallet.pkw';  // Wallet keys file 
I would be very happy for any hints.

simone:
I have no experience in developing under Mac OS, but about environment variables, maybe this wiki can help:

https://wiki.freepascal.org/Command_line_parameters_and_environment_variables#Environment_variables

KodeZwerg:

--- 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";}};} ---{$mode objfpc}{$H+}{$modeswitch objectivec1}  ... uses  CocoaAll; // for NSBundle ... function GetBundlePath: string;begin  Result := NSBundle.mainBundle.bundlePath.UTF8String;end;Taken from https://wiki.lazarus.freepascal.org/macOS_Programming_Tips

dbannon:
On the Mac, only files that would be discareded in the even, eg, of an update would be kept in the bundle.  Given we don't see Trev very often these days, here is how I do it ("tomboy-ng" being the name of my app, you will need to set your own !)-


--- 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 TSett.GetDefaultNoteDir : string;begin    {$IFDEF UNIX}    Result := GetEnvironmentVariable('HOME') + '/.local/share/tomboy-ng/';    {$ENDIF}    {$IFDEF DARWIN}    Result := GetEnvironmentVariable('HOME') + '/Library/Application Support/Tomboy-ng/Notes/';    {$ENDIF}    {$IFDEF WINDOWS}    Result := GetEnvironmentVariable('APPDATA') + '\tomboy-ng\notes\';    {$ENDIF}end;
Yes, I know, the UNIX line will be activated in Cocoa too but it will be overwritten by the correct one. There is a historical reason ....

Davo

WayneSherman:

--- Quote from: dbannon ---Yes, I know, the UNIX line will be activated in Cocoa too but it will be overwritten by the correct one.
--- End quote ---

Possibly a better way (?) using newer {$IF} and {$ELSEIF} directives:


--- 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 TSett.GetDefaultNoteDir : string;begin  {$IF DEFINED(DARWIN)}    Result := GetEnvironmentVariable('HOME') + '/Library/Application Support/Tomboy-ng/Notes/';  {$ELSEIF DEFINED(UNIX)}    Result := GetEnvironmentVariable('HOME') + '/.local/share/tomboy-ng/';  {$ELSEIF DEFINED(WINDOWS)}    Result := GetEnvironmentVariable('APPDATA') + '\tomboy-ng\notes\';  {$ENDIF}end;
Reference:
https://wiki.freepascal.org/Conditional_compilation#.24else_and_.24elseif
https://wiki.freepascal.org/$IF

Navigation

[0] Message Index

[#] Next page

Go to full version