Standalones and the defaultFolder
mark at livecode.com
Mon Dec 16 12:15:03 EST 2019
On 2019-12-16 16:54, J. Landman Gay via use-livecode wrote:
> On launch, the defaultfolder is set to the folder containing the
> executable. On desktop this is the folder containing livecode. In a
> standalone it's the folder containing the app (which on Mac is inside
> the bundle.) But any time you change the defaultfolder it stays there,
> it doesn't set itself back automatically.
The latter part is true, the former isn't necessarily so :)
I think the 'problem' here is that there is an expectation that the
defaultFolder is something you can rely on to be known when your app is
run but it isn't (nor has it ever been) - the engine doesn't touch the
defaultFolder on startup, it is what the OS/environment decides it is.
For example if you launch a LiveCode app from Terminal (or platform
equivalent) the default folder will be that which was in place in
Terminal when you launched it (i.e. what your user - not you - decided
it to be).
Launching from Finder (or Explorer or wherever) might make it appear
like it should be a standard place - but that will depend on what OS you
are running and even which version (I'm almost sure Finder changed from
being the MacOS folder inside an app bundle to the folder containing the
bundle at some point - or vice-versa - but don't quote me on that).
If the engine did fettle with the defaultFolder at all, then writing any
sort of shell command (or app launchable from the command-line) which
allowed relative paths in arguments would be impossible.
Upshot - never use the defaultFolder to find stackfiles - unless they
are passed in by the user as arguments in a command-line context.
There's 'specialFolderPath's for various places these days (most
noticeable resources and engine); but you can also just grok the
filename property of your mainstack too. (The stackFiles property can be
useful here too - this allows mapping arbitrary stack names to
filepaths, which if relative are relative to the stack on which the
stackFiles property is set).
Mark Waddingham ~ mark at livecode.com ~ http://www.livecode.com/
LiveCode: Everyone can create apps
More information about the use-livecode