Writing Files in StandAlone on Mac

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 in StandAlone on Mac

Post by Ron Zellner » Fri Jan 02, 2009 6:53 pm

I have an application that opens a text file and later rewrites it- The standalone seems to work on the PC but not the Mac version. I am developing on a Mac and it works fine in Revolution, just not in the StandAlone.

Code: Select all

      set the itemDelimiter to numToChar(47)
      put the filename of this stack into P  --get current location    
      Delete the last item of P
      Put empty into field "Transcription" 
      answer file "Choose a file:"     -- select an audio file to open  
      set the filename of Player "MovieScreen" to it     
      put the last item of it into field "MovieTitle"      
      Put P & "/DataFiles/" &  field "MovieTitle" & ".txt" into TheFileName
             -- creates a text file name with the same name as the audio file
      open file TheFileName
      open file TheFileName for read
      read from file TheFileName at 1 until EOF
      put it into field "Transcription"  
      close file TheFileName 
Instead of putting the contents of the text file that was read into the field "Transcription", it puts the path to the audio file (the previous value of 'it') so the read statement must not be working.
There are no error statements produced.
Does anyone see what is going on here? Thanks.

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Post by Janschenkel » Fri Jan 02, 2009 7:56 pm

Note that for Revolution, regardless of the platform, the path delimiter is slash,which is a constant, so you can easily use that in your script - no need for numToChar(47).
Back to your problem, you should probably check the path to the file, as well as if it exists or not.

Code: Select all

Put P & "/DataFiles/" &  field "MovieTitle" & ".txt" into TheFileName 
             -- creates a text file name with the same name as the audio file
answer TheFileName & return & "Exists:" && (there is a file TheFileName)
If that shows the correct file path and the file exists, then you should probably check 'the result' after opening the file.

Code: Select all

open file TheFileName for read
answer "The result of open:" && the result
This should help us figure out the problem.

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

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

Post by Ron Zellner » Fri Jan 02, 2009 9:41 pm

OK, I see the nature of the problem- the path changes in the StandAlone version as the location is actually embedded inside the app- so, I have to compensate for the .app/Contents/MacOS/ part of the path that is added in order to get up to the level where my folder/files are actually located.
I think that means deleting the last 4 items in the file path- basically the same solution that Klaus had to a similar problem last month.

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

Post by Klaus » Fri Jan 02, 2009 10:31 pm

Hi Ron,

another important hint is to put IT into another variable IMMEDIATLEY!
Since IT will change whenever you least exspect it :-)

Like:

Code: Select all

answer file "Choose a file:"     -- select an audio file to open  
put it into tNewFileName ## !!!
set the filename of Player "MovieScreen" to tNewFileName
Best

Klaus

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

Post by Ron Zellner » Fri Jan 02, 2009 10:48 pm

Good point- actually has other benefits as I can use that variable in other scripts in the stack and don't have to reassess It again.

and so- combining Klaus' suggestion from last month and an old trick I learned a while back, I think this solution handles all situations:

Code: Select all

      put the filename of this stack into P
      if (the openStacks contains "revTools") then           -- it's in the development environment
         Delete the last item of P
      else                                                   -- It's in a StandAlone mode.
         if the platform = "MacOS" then
            Delete  item -4 to -1 of P
         else
            Delete the last item of P
         end if
      end if
I think that takes care of it, but I haven't tested it on a PC yet.

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Post by Janschenkel » Sat Jan 03, 2009 7:46 am

Actually, to test if you're in a standalone or inside the Rev IDE, it's best to check the content of the 'environment' property - that would survive a future where the stack "revTools" is renamed.

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

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

Post by Ron Zellner » Sat Jan 03, 2009 4:14 pm

Oh, that's pretty simple.:shock: Hadn't noticed it before. I guess the old trick is too old.

Post Reply