Path problem with Standalone

J. Landman Gay jacque at hyperactivesw.com
Fri May 4 16:51:32 EDT 2007


Joe Lewis Wilkins wrote:
> It's definitely not as simple as I had hoped nd expected; but what is? 

Story of my life. :) Actually, it really is simpler than it appears, but 
only if you know the underlying concepts. I think what you're getting 
stuck on are some concepts that HyperCard didn't have, so it's normal to 
be a little baffled.

The main thing here is the concept of a "defaultfolder". This is the 
directory where Rev (or your standalone) will start looking for files. 
When the engine starts up, the default folder is always the one that 
contains the application. In the IDE, this is the "Revolution" folder. 
In your standalone, it's the folder containing your standalone bundle 
(or on Windows, the folder with the executable.)

You can change the defaultFolder in a script. If you do that, the engine 
will use the newly specified folder to look for files if the file 
reference doesn't contain a full file path. If a player or a file 
reference does use a complete file path, then Rev will use that path 
without consulting the defaultFolder.

When you "add files" to a standalone, the SB will place the files (on OS 
X) inside the application bundle, next to the engine file, in:

   My Standalone/Contents/MacOS/

Since the default folder on launch will be the folder containing the 
standalone, a relative file path that will work in your players (on Mac 
OS X only) would be the above, with the file name appended:

  My Standalone/Contents/MacOS/myAudioFile.aif

During development though, you'll want to play your files for testing. 
If your players are set up with relative paths then the above will fail 
because those folders don't exist outside of standalones. You'll need to 
reproduce the relative folder structure inside your test folder (which 
in your case is the Rev folder, though I think that's not a great idea. 
But anyway.)

So for testing, you'd want to create these folders inside the Rev folder:

   My Standalone/Contents/MacOS/

and put your audio files in there. That matches the paths your 
standalone will use. But hardly anyone does it this way. It's too fussy. 
There's a better way.

Many of us use a little custom function to determine the path to the 
stack, which returns the right path regardless of whether you are are in 
the IDE or running a standalone (careful of text wrap):

function appPath theStackName -- return the path of the application
   if theStackName = "" then put the short name of this stack into 
theStackName
   put the effective filename of stack theStackName into thePath
   set the itemdel to "/"
   If (IsOSX()) then
     get offset(".app/Contents/MacOS/", thePath)
     if it > 0 then
       delete char it to len(thePath) of thePath
     end if
   end if
   delete last item of thePath
   return thePath &"/"
end appPath

function isOSX
   set the itemDelimiter to "."
   return (the platform = "MacOS" and item 1 of the systemVersion >= 10)
end isOSX


This pair of functions will always return the path to the stack, whether 
it is in stack form (during development) or inside the bundle in a 
standalone (which is where the SB will copy your audio files.) When you 
want to play back an audio file, just set the defaultFolder before any 
of the players load:

   set the defaultFolder to appPath()

To work, your players should use relative file paths. In this case, 
since we're using appPath(), you don't need any folder reference. Your 
relative file path will just be the name of the audio file. Dump all 
your audio files into the same folder as your stack for testing. Now the 
engine will look inside the bundle for the audio files, and if your 
player paths are relative ("myAudioFile.aif" without any folders) then 
it will find the file and play it. If you are running in the IDE, it 
will look in the stack's folder for the files because appPath() will 
return that path.

That's just one way, there are other things you can do instead of 
setting the defaultFolder. I more often use appPath() to construct a 
filepath dynamically in scripts. For example, when the standalone starts 
up you could set all your players to absolute paths right at the start:

  put appPath() & "myAudioFile.aif" into tPath
  set the filename of player 1 to tPath

Now you don't have to worry about the default folder, because you've 
just set the file name to an absolute path. The above will work in both 
development and standalones, provided your audio files are in the same 
folder as your stack.

Finally, having a lot of loose files like that is sort of messy, so I 
usually put them into a containing folder. Say you've got a folder 
called "Audio" and all your audio files are in there. The same rules 
apply as above, but instead of using just the filename with appPath() 
you'd add the containing folder as well:

   put appPath() & "Audio/myAudioFile.aif" into tPath

I can't recall whether the SB will move the files into the standalone 
inside a folder (I usually just do it manually) but if it doesn't, it's 
a pretty easy step to open the standalone bundle and add the folder 
yourself. Maybe someone else remembers.

Re-reading this, I'm not sure if I've made things clearer or murkier. 
Maybe just reading the docs on defaultFolder would be a better start. ;)

-- 
Jacqueline Landman Gay         |     jacque at hyperactivesw.com
HyperActive Software           |     http://www.hyperactivesw.com



More information about the use-livecode mailing list