Page 2 of 2
Posted: Tue Jun 24, 2008 9:57 pm
by jamirokwai
Danke, das ist noch besser
Thorsten1867 wrote:I use this for my programs:
Code: Select all
Procedure.s GetProgramDirectory() ; Program Path
Protected ProgDir.s
ProgDir = GetPathPart(ProgramFilename())
If ProgDir = #PB_Compiler_Home+"Compilers" Or ProgDir = GetTemporaryDirectory()
ProgDir = GetCurrentDirectory()
EndIf
ProcedureReturn ProgDir
EndProcedure
-----
Edit:
Hm. After doing some tests, does not work as expected. I use the line coded by Michael51,
which works better for me. I also extended the whole process to determine the
location on compile-time. See
http://www.purebasic.fr/english/viewtopic.php?p=249534
Posted: Thu Jun 26, 2008 11:40 pm
by michel51
jamirokwai wrote:
Thorsten1867 wrote:I use this for my programs:
Code: Select all
Procedure.s GetProgramDirectory() ; Program Path
Protected ProgDir.s
ProgDir = GetPathPart(ProgramFilename())
If ProgDir = #PB_Compiler_Home+"Compilers" Or ProgDir = GetTemporaryDirectory()
ProgDir = GetCurrentDirectory()
EndIf
ProcedureReturn ProgDir
EndProcedure
-----
Edit:
Hm. After doing some tests, does not work as expected. I use the line coded by Michael51,
which works better for me. I also extended the whole process to determine the
location on compile-time.
I don't have tested the code above, but there is a different between the executable on Windows and the application on Mac. If you compile on Mac your code as "Application" (.app), then you will get a "folder". Your (unix-)-executable is saved in 'Contents/MacOS/'.
My code will return the path of the application.
I think, the code of Thosten1867 will return the path of the executable.
But I think, you know the different I told here.

Posted: Fri Jun 27, 2008 3:59 pm
by Thorsten1867
I don't know, which path the Mac use, but you have only to change line 4 (If 'MacPath' ....).
Re: GetCurrentDirectory()
Posted: Thu Dec 04, 2025 7:12 am
by KianV
I know that this is quite a specific case, but it matters when sharing programs.
I have used this code:
Code: Select all
result$ = Left(GetPathPart(ProgramFilename()), FindString(GetPathPart(ProgramFilename()),GetFilePart(ProgramFilename())+".app",1)-1)
to get the directory where the program is stored.
This works fine when the program is compiled and I can run it from any directory.
If I then zip the file and upload it to a server, then download it to replace the original, I get this returned instead of the correct path:
/private/var/folders/90/7gn_ctsx0w5gffqnrypyq_y00000gn/T/AppTranslocation/8294524A-D59F-4FE2-AB7E-C98A971E0D7C/d/
Can anyone enlighten me as to what is going on?
Re: Path to bundle.app
Posted: Thu Dec 04, 2025 3:22 pm
by Piero
jamirokwai wrote: Tue Jun 24, 2008 9:31 amI desperately needed this.
Code: Select all
; Multilevel, Multiplatform Enclosing Folder (can optionally set Current Directory)
Procedure.s UpperDir(path$, level = 1, setcurrdir = #False)
If FileSize(path$) = -1 : ProcedureReturn "" : EndIf
Protected i, OLDcurrdir$ = GetCurrentDirectory()
path$ = GetPathPart(path$) ; in case of file
For i = 1 To level : path$ + ".." + #PS$ : Next
SetCurrentDirectory(path$)
path$ = GetCurrentDirectory()
If Not setcurrdir : SetCurrentDirectory(OLDcurrdir$) : EndIf
ProcedureReturn path$
EndProcedure
Debug UpperDir(ProgramFilename(),2)
Re: GetCurrentDirectory()
Posted: Thu Dec 04, 2025 3:45 pm
by Piero
KianV wrote: Thu Dec 04, 2025 7:12 am
This works fine when the program is compiled and I can run it from any directory.
If I then zip the file and upload it to a server, then download it to replace the original…
Can anyone enlighten me as to what is going on?
Be sure to have an admin account…
Try
but then don't move it… (run it!)
You may also need:
Then in System Preferences > Security & Privacy, under the 'General' tab, you'll need to select 'Allow apps downloaded from: Anywhere'
Re: GetCurrentDirectory()
Posted: Thu Dec 04, 2025 4:59 pm
by kenmo
KianV wrote: Thu Dec 04, 2025 7:12 amCan anyone enlighten me as to what is going on?
Yes, it's a very annoying MacOS feature called "App Translocation" which runs your program from a randomized path, supposedly for security reasons although it's not difficult to get around it... Search "App Translocation" and you'll need some combination of:
- detecting whether you've been "translocated"
- determining the original "untranslocated" path
- changing the current working directory back to there
- removing the quarantine attribute from the executable
- relaunching the unquarantined app might be necessary
I have done this before in PB but I'm not home to grab any code examples.
Here are some links to read...
https://lapcatsoftware.com/articles/app ... ation.html
https://www.synack.com/exploits-explain ... ting-apps/
https://eclecticlight.co/2025/10/16/che ... slocation/
Re: GetCurrentDirectory()
Posted: Thu Dec 04, 2025 5:27 pm
by Piero
Very comprehensive info there kenmo, thanks!
On the contrary, my post may seem like totally insane/insecure, but that helped me solve worst cases, e.g., when opening the app I got "App is damaged, contact the developer"……
