SpecialFolder and CurrentWorkingDirectory

When looking at Opening Files on Different Operating Systems I realised there is no path that I can discern for mac osx that results in where the application is being executed from.

ie, the application as run doesn’t appear to know (from the exposed properties/methods) where the application is loaded.

My gut told me that CurrentWorkingDirectory would suffice, but explicitly, not for OSX (emphasis mine):


  • Windows:
    – When run from Xojo, it is the path to Xojo.
    – In a built app, it is the path to the built app.
  • OSX: Usually “/”.
  • Linux: Current working directory at the time the application was launched (uses getcwd).


The only way I could find to determine where the application is installed/run from was to use Resource and work backwards, but that’s too hacky (what if it doesn’t exist):

SpecialFolder.Resources.Parent.Parent.NativePath or
SpecialFolder.Resources.Parent.Parent.Parent.NativePath to return the built.app executable.

Is there a better way?

Dave’s suggestion:

currentWorkingDirectory = App.ExecutableFile.parent

Excellent. Missed that. Thanks.

I find:

here = new FolderItem ("", FolderItem.PathModes.Native)
path = here.NativePath + “/”

to be quite useful.

there is no path that I can discern for mac osx that results in where the application is being executed from.

I worry when I see that being asked.
If this is because you want to read or write files that are ‘in the same folder as the app’, then you are doing things wrong.
Often, Windows and OSX won’t even let you access them.

On first use, create a folder for your app in Specialfolder.applicationsupport

Put your external files there.
Then, it doesnt matter where your app is actually located, or whether it is debug or release.
Your external files are always there, and they are always writable.

In my case, it used to be that the app expected the user’s data flles to be next to it. That allowed the user to easily transport his files to another machine. Then I added the notion that, if the app is within /Applications, the user’s files would be expected to be in ~/Documents (or the Windows equivalent in both cases).

So an early thing the app does is to check where it is located, so it can look for the user’s files in the right place. These are not application support files, all of which are within the app.