简体   繁体   中英

“Write” in Applescript adds things to text

I am relatively new to applescript, so I apologize if this is a silly question. When I write (text & return) to file the randomFile starting at eof it adds "listutxtplaceholderutxtº" to the beginning and "utxt!utxt" to the end, making it so that these things show up when I read the file. Why is it doing this? Is there a workaround?

Any help is appreciated!

That happens when the content in your variable is a list .

Make sure it's not a list or handle it as a list ( you already know how ).

But when that list only has one item you can use as text , like that:

set myList to {"Hi"} -- this is a list with one item
write ((myList as text) & return) to file the randomFile starting at eof


From the Apple Script Language Guide :

List
A list defines an ordered collection of values, known as items, of any class. As depicted in a script, a list consists of a series of expressions contained within braces and separated by commas, such as the following:

{1, 7, "Beethoven", 4.5}

A list can contain other lists. An empty list (containing no items) is represented by a pair of empty braces: {} .

AppleScript provides the list class for working with lists.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM