Page 1 of 1

Writing Files in StandAlone on Mac

Posted: Fri Jan 02, 2009 6:53 pm
by Ron Zellner
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.

Posted: Fri Jan 02, 2009 7:56 pm
by Janschenkel
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.

Posted: Fri Jan 02, 2009 9:41 pm
by Ron Zellner
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.

Posted: Fri Jan 02, 2009 10:31 pm
by Klaus
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

Posted: Fri Jan 02, 2009 10:48 pm
by Ron Zellner
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.

Posted: Sat Jan 03, 2009 7:46 am
by Janschenkel
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.

Posted: Sat Jan 03, 2009 4:14 pm
by Ron Zellner
Oh, that's pretty simple.:shock: Hadn't noticed it before. I guess the old trick is too old.