Hi!
I’d like to save a textedit document as “Windows-Latin-1” using Applescript. Here’s what I have:
tell application "TextEdit"
make new document at beginning with properties {name:"test", text:"Hello, World"}
save document 1 as "window-1252" in file "test.txt"
--save document 1 as "utf-8" in file "test.txt"
close document 1 saving no
end tell
Saving the document as “UTF-8” works ok, but as “window-1252” (i.e. Windows-Latin-1 does not. What’s wrong? Thanks!
Luke
This seems to work for me.
tell application “TextEdit”
set myPath to (path to desktop as string) & “junk.txt”
– save document 1 as “window-1252” in file “test.txt”
set fut to “Western (Windows Latin 1)” as Unicode text
save document 1 as fut in file myPath
end tell
Does it work for you? If not, what error are you getting?
It works, thanks a lot! Is there an online reference to stuff like that? I couldn’t find it on Apple’s site http://www.apple.com/applescript/.
Although the Script you wrote works, I still have the original problem. The purpose of saving the document as “Windows Latin 1” was to make it accessible for iCal as a calendar (via subscribe). The text file is created by and exported from Filemaker. If I open and save it using TextEdit (with the mentioned “Windows-Latin-1” encoding), it can be imported in iCal.
If I use “TextEdit” for a manual open and save, the subsequent import to iCal works. If I try your script, it doesn’t import into iCal (can’t be read). If I use the script below with “Tex-Edit Plus”, the import into iCal is ok. Strange, uh?
tell application "Tex-Edit Plus"
open file "calendar.txt"
save document 1 in file "calendar.txt" as string
close window 1 saving no
end tell
So long,
Luke
How did you decide that iCal required a file encoded in Windows Latin 1? Are you sure about that? I’d be surprised if Tex-Edit Plus is saving in that encoding by default.
Just trial and error. iCal import of calendars works after saving the file in Textedit (with Win-Lat-1) or Tex-Edit. Strange, huh?