Default folder question for OSX
Richard Gaskin
ambassador at fourthworld.com
Wed May 5 01:57:57 EDT 2004
Barry Levine wrote:
> I'm developing an app that will read the contents of a specific file
> upon openStack assuming that the file is present. Lets call this the
> "defaultFile". I am not setting the defaultFolder so my stack (as I am
> developing/testing) does, indeed, find the file and read its contents as
> scripted. According to the electronic docs, the folder that holds the
> ".app" bundle will be the default folder when I build my app. This
> indicates that I shouldn't have to change the defaultFolder from
> "stock". I'm developing and will build in v2.2. Will there be any
> unexpected behavior in this version relative to this issue?
>
> This also brings up a second question: If I want to place that
> "defaultFile" inside the package so it can't be lost, how would I have
> to set my defaultFolder. Let's assume the path to the app bundle is:
>
> MyDisk/myFolder/myApp
>
> Any suggestions would be appreciated.
There are two views on this, and the differences between then are
largely subjective and I believe both have merit, so I'll provide some
background on these issues, briefly outline both groups of solutions,
and offer my personal favorite for handling these things.
At the heart of the issue is that the defaultFolder and relative paths
like those in the stackFiles property and in the fileName properties of
images and players behave differently in OS X than on all other
platforms, and there is a difference in the defaultFolder on all
platforms depending on whether a stack is running in development mode or
as a standalone.
defaultFolder
-------------
The defaultFolder is initialized to the folder containing the
application. In development this is the folder containing the Rev
application, and for a standalone this is the folder containing your
standalone application. This is true in all OSes, including OS X where
the application folder is the one containing the *.app bundle.
So as you can guess things can get tricky looking for files based on the
defaultFolder, since it is initialized differently depending on whether
you're stack is running in the Rev IDE or as a standalone.
Also, note that the defaultFolder can be changed in script, as would be
necessary to obtain a list of files in another folder for example.
While it's considered good practice to save and restore the value of the
defaultFolder for such operations, if you use code from other libraries
you may not have complete assurance such save-and-restore is being done.
relativePaths
-------------
This issue is compounded by the different way relative paths are handled
in the fileName property of image and player objects. In such cases a
path is relative to the location of the stack file containing the
reference, so this is consistent regardless of whether it is a
standalone or a stackfile -- except on OS X.
On OS X such paths are relative to the actual executable file buried
with in *.app bundle, not the *.app bundle itself as with the
defaultFolder (look inside an OS X bundle and see the path
*.app/Contents/MacOS/executableFile).
Options for resolving these issues
----------------------------------
Some feel that bundles are a wonderful invention from Apple, in that it
allows you to hide components within the bundle so the user never has to
deal with them.
Others feel that having folders that appear to be executable files (the
bundle) is potentially confusing, and makes things like having a Plugins
folder complex for those apps that use such things.
For myself, I tend to document what gets installed with my apps and
prefer not to write two different sets of docs, one for OS X only and
another for Classic and all other supported OSes. Also, an increasing
number of the apps I produce have some form of user-extensible
components (plugins), so I prefer to keep the folder structure
consistent across platforms to simplify working with and documenting
such options.
I generally prefer solutions which minimize differences between runtime
and development, and have gotten into the habit of using this handy
function for obtaining the path to my stackFile regardless of whether
it's a standalone or in the IDE, and regardless of whether as a
standalone it's running on OS X or any other OS:
function AppPath
local tPath
--
put the filename of this stack into tPath
set the itemdel to "/"
If (IsOSX()) then
get offset(".app/Contents/MacOS/", tPath)
if it > 0 then -- engine v2.4.3 or later
delete char it to len(tPath) of tPath
end if
end if
delete last item of tPath
return tPath &"/"
end AppPath
function IsOSX
set the itemdel to "."
if (the platform is "MacOS") \
AND (item 1 of the systemVersion >= 10) then return true
else return false
end IsOSX
I use this to build paths I need for other files, such as to a Plugins
folder:
put AppPath()&"Plugins/" into tPluginsPath
But like I said, there's more than one way to skin this cat. Hopefully
some of those with other solutions will chime in here with their favorites.
--
Richard Gaskin
Fourth World Media Corporation
___________________________________________________
Rev tools and more: http://www.fourthworld.com/rev
More information about the use-livecode
mailing list