Echo and special characters in log

This code dont save special characters correctly to log:

set testing to "ü"
do shell script "echo " & testing & " >> " & quoted form of logname

Result:
ü

it does, these log files are utf8 encoded

set testing to "ü"
do shell script "echo " & testing & " >> " & quoted form of logname
set l to POSIX file logname
set c to read file l as «class utf8»
display dialog c
--> "ü"

I was reading it using TextEdit and it dont show correctly in it. Txs

launch TextEdit and load the file pressing cmd-O and choosing Unicode UTF-8 from the Plain Text Encoding pop up menu

If i try to search strings with “ü” then Spotlight don’t find that log file at all.

I could use “write” command, but that requires multiple lines of code and opening/closing file. I would prefer single line of code just like “echo” does.

Are there any way to write “ü” to .txt file Spotlight friendly way with just one row of code?

Thanks

If you want to save text in the MacRoman encoding (or pretty much any other encoding) in a do shell script environment, you will probably want to use iconv. I am not sure how “Spotlight friendly” it will be though. I suspect that there may be some way to signal to Spotlight (and other programs) that an text file has a specific , non-MacRoman encoding. I found an xattr under the name “com.apple.TextEncoding” in the Xcode project source of hdapm, but I have never bothered to check how to set this xattr manually or whether anything else (e.g. Spotlight or TextEdit) supports the xattr and the values that Xcode uses.

property n : 0
set s to "ü"
do shell script "cd ~/Desktop;echo " & quoted form of (s & n) & "|iconv -f UTF-8 -t MACROMAN >> log.txt"
set n to n + 1

But why worry about lines of code? Just use a handler to abstract away the open for access, write, and close access. Also, write can be used without open for access and close access, but (at least on my machine) you still need a bit of special handling for the case where the file does not already exist.

Model: iBook G4 933
AppleScript: 1.10.7
Browser: Safari 4.0.3 (4531.9)
Operating System: Mac OS X (10.4)

Thanks.

If i use your code, then ü shows correctly in TextEdit, but not in Spotlight and Quick Look.

But if i use this code, then ü shows correctly in Quick Look, but not in Spotlight and TextEdit:

do shell script "echo " & "ü" & " >> " & (quoted form of POSIX path of (path to desktop) & "log.txt")

For some reason i can’t get write to work right now.

How i can make all 3, Spotlight, Quick Look and TextEdit work using echo or write or …?

Thanks