Writing files outside the Mac App

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Ron Zellner
Posts: 106
Joined: Wed May 31, 2006 9:56 pm
Contact:

Writing files outside the Mac App

Post by Ron Zellner » Thu Dec 11, 2008 4:31 pm

I have a stack that writes files to store the contents of fields:

Code: Select all

put the filename of this stack into P
Delete the last item of P
Open file P & "/" & "TimeSeq" & field "Subject" for write
etc.
works fine but when I create a standalone for Mac the files are created inside the App. I can access the contents with a right click, but that isn't too convenient. I've added a folder to the file structure and modified the path to include that folder to put the file at a different level:

Code: Select all

Open file P & "/DataFiles/" & "TimeSeq" & field "Subject" for write
Works fine in development, but that doesn't work in the App.

Similarly, I'm creating png files from images with:

Code: Select all

put (item 1 to -2 of the effective filename of this stack) & "/activity1-snapshots" & field "Subject" into tSnapshotPath
create folder tSnapshotPath
and then elsewhere:

Code: Select all

then export image "ImageDrawing"   of card "Activity1" to URL ("binfile:"&tSnapshotPath&"/" & the seconds & ".png") as PNG
but they also are created inside the App.
Is there a way to alter the file paths to produce files outside the App? They also need to work in the PC standalone. Separate folders would be good there too for convenient access.

(Which of these two ways of creating the file path is preferred? they seem to work equally well; the second one is more efficient.)

Klaus
Posts: 14208
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Post by Klaus » Thu Dec 11, 2008 6:36 pm

Hi Ron,

remember that OS X applications are in fact folders with a certain structure!
Maybe this "anatomy" of an OS X Application bundle may help:

.../Folder with your standalone inside/Standalone.app/Contents/MacOS/Standalone
Where "Standalone" is the Main stack that you compiled a standalone from.

So you will have to:

Code: Select all

...
put the filename of this stack into we_are_here
set itemdel to "/"
if the platform = "MacOS" then
   delete item -4 to -1 of we_are_here

## Win:
## ../Folder with your standalone inside/Standalone.exe
else
   delete item -1 of we_are_here
end if
...
Now "we_are_here" contains the path of your "Folder with your standalone inside".

Hope that helps.


Best

Klaus

Post Reply