Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > AppleScript: Write To File Help...

AppleScript: Write To File Help...
Thread Tools
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status: Offline
Reply With Quote
May 27, 2001, 07:03 PM
 
I am trying to write a return to a file so when I open the file in simpel text, it won't all be one long line.. doing it like this...

open for access X
write "text" & Return & "more text" to X at (get eof X)
clsoe access X

This does not work. Also tried putting a real return in between quotation marks in the code, that also does not work. Also tried (ASCII Character 13). To no Avail. If anyone has a clue, let me know please.

------------------
Make Money With Your Macintosh!
     
Junior Member
Join Date: Apr 2001
Status: Offline
Reply With Quote
May 28, 2001, 01:13 AM
 
maybe try something like this:

set file_Data to open for access alias "MyDisk:MyFolder:MyFile" with write permission
write return & "text" & return & "more text" to file_Data starting at eof
close access file_Data

it seems the file "read" and "write" commands like to work with a reference to the file data returned by "open for access", which you'd set with file_Data.
also, it prefers the file specification in the form of an alias filepath... and be sure to enable write permission. not sure exactly what was causing the error, but the above routine should work.
regards, acur
     
l008com  (op)
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status: Offline
Reply With Quote
May 28, 2001, 01:18 AM
 
I guess I wasn't clear, the writing to the file works jsut fine, the problem i have is writing a -return- character into the file. I get the data but i don't get a return, so when I open the file, it's all one long line.

------------------
Make Money With Your Macintosh!
     
Junior Member
Join Date: Apr 2001
Status: Offline
Reply With Quote
May 28, 2001, 02:33 AM
 
how are you transferring the data... in strings generated in the script, or directly from another file's data?
if you're using strings, then the & return & should work fine... otherwise, you might try using text delimiters in the data read from the original file.
something like:

set file_Data to open for access alias "MyDisk:MyFolder:MyFile" without write permission
set old_text to read file_Data using delimiter {", "} as text
close access file_Data
set Applescript's text item delimiters to {return}
set new_Text to open for access alias "MyDisk:MyOtherFolder:MyOtherFile" with write permission
write return & old_text to new_Text starting at eof
close access new_Text
set Applescript's text item delimiters to {""}

should work if you have some way (like commas, tabs, etc.) of delimiting the text in the original file.
acur

[This message has been edited by acur128 (edited 05-28-2001).]
     
l008com  (op)
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status: Offline
Reply With Quote
May 28, 2001, 02:35 AM
 
I am getting a string, and trying to add my own return into it (as depicted in my original post) so I can open the file in a text editor and it will be easier to read.

------------------
Make Money With Your Macintosh!
     
Junior Member
Join Date: Apr 2001
Status: Offline
Reply With Quote
May 28, 2001, 02:44 AM
 
hmmm... what kind of error(s) are you getting? and how many (and what type) of strings? The first example should work for text or any type of strings, but not lists or records...
acur
     
l008com  (op)
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status: Offline
Reply With Quote
May 28, 2001, 02:48 AM
 
I'm not getting any error, it simply doesn't write the return.

------------------
Make Money With Your Macintosh!
     
Junior Member
Join Date: Apr 2001
Status: Offline
Reply With Quote
May 28, 2001, 02:53 AM
 
indeed, was just about to edit that last post... getting a little late it is...
i guess i don't know... but maybe try pasting the fragment in my first post to script editor, changing the path "MyDisk:MyFolder:MyFile" to the path to your file, and see if it works...?
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 11:03 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2