writing to text file quirk

Hi, I’m sure this is really obvious but a quick glance at previous threads and I can’t find an answer.

I’m outputting data from a script (its actually a photoshop script logging some numbers). It stores the stuff in an array and then writes to a text file. Why is it that at the front and end of every line I get gibberish like

“fromnulldle2obj Ñformenumnamewanttypecobjseldutxt”

which makes processing the file afterwards annoying? Any help appreciated.

I’m using the write_to_file code on the applescript website, heres the kind of thing:

		set output_line to ""
		set output_line to (item pic of pic_file_list) & tab
		repeat with n from 1 to length of jumbled_list
			set output_line to output_line & item n of data_list & tab
		end repeat
		set output_line to output_line & "
		my write_to_file(output_line, (((path to desktop folder) as text) & "output_file"), true) 

When you say “stores it in an array” I assume you mean a list. In Applescript, lists aren’t “text” although they can contain text.

What you’re likely seeing is the result of not converting the list to text before you write it. And if you want space between the items, you need to

set saveDelimiters to applescript's text item delimiters
set applescript's text delimiters to space
set output_list to output_list as text
<<do your file write>>
set applescript's text delimiters to saveDelimiters

Thanks for the reply Kevin.

yes I meant list not array. The delimiters are not a problem and I can do that. I’ve tried converting to text but I still get the same problem. ie. I try

set output_list to output_list as text

before doing my write. However, every line written starts with the fromnulldle2obj Ñformenumnamewanttypecobjseldutxt and ends with kstystylfromnull. Can anyone shed light on what that means and tell me how to write a list containing text items to a text file without that gibberish?!



Hi, tom_fo.

It looks as if some kind of record is being written to the file and read back as text. What are the contents of ‘pic_file_list’ and ‘data_list’ and how are they derived? It might also help if you post the handler you’re using to write to the file.


I’m no expert… However, this is how I write lists and then read them back.


-- Your List
set myList to {2312, "Chia Pets", 12.32, {"Hungry", "Hippo", 23}}

-- Write The List As List
set userHome to path to (home folder) as text
set dataPath to userHome & "Desktop:savedData.txt" as string
set openAccess to open for access file dataPath with write permission
write myList to openAccess as list
close access openAccess

-- Read The List As List
set openAccess to open for access file dataPath
set myRead to read openAccess as list
close access openAccess

-- What Was Read
return myRead