Hi Ed,
there are a couple of problems. First, if you want to work with a file using TextWranger, you can use an open specifier command (specifier usually being an alias), work on that file and close it with close saving yes In my script it looks like tell application "TextWrangler" open theFile opening in new_window tell window 1 # do something end tell close saving yes end tell
If you just want to get the text from a file, you can use the StandardAdditions command "read", but if you enclose it within a "tell …" command, you will get an error. You can get around this by usingtell me to read <file>
If you want to read only a line, you have to check what kind of line separator is used within the text and do something like read myFile until "\n" if it is Unix-style. If the separator isn't found in the file it will read until the end of the file without giving an error (on my machine at least, Mac OS X 10.6.8).
Using read myFile as Unicode text will expect the text to be using 2byte characters (looks chinese) and is most likely not what you want, UTF-8 isn't handled that way. With read you get the "raw" byte equivalent which is fine if you treat it that way, you can paste the result into a text opened by TextWrangler, if you opened that accordingly: open myFile reading as "Western (Mac OS Roman)" with LF translation
You can save it as such and then open it as UTF-8.
I hope this helps a little.
Best Thomas
Am 28.01.2013 um 23:41 schrieb Ed Rush: I'm trying to open an existing text file, add some HTML code, and write the result to replace a pre-existing second file, but I keep getting an end-of-file error right off the bat:
tell application "TextWrangler" activate
set sourceFile to (choose file with prompt "Choose the ... text file:") set targetFile to (choose file with prompt "Choose the ... HTML file:")
set introText to "<!DOCTYPE html PUBLIC ...(lots of header code)"
--read the books list set booksList to read sourceFile as Unicode text using delimiter return close access sourceFile
... <loop to do the deed, etc.> end tell --"TextWrangler"
I'm trying to open an existing text file, add some HTML code, and write the result to replace a pre-existing second file. I've tried it with the surrounding "tell" set to TextEdit, TextWrangler, Finder, and nothing. Regardless, I get this:
read alias "Goalie:Users:edr:Documents:BUUF:BUUF Library:BUUF library in OO.txt" as Unicode text using delimiter " " --> error number -10004 end tell tell current application read alias "Goalie:Users:edr:Documents:BUUF:BUUF Library:BUUF library in OO.txt" as Unicode text using delimiter " " Result: error "TextWrangler got an error: End of file error." number -39 from file "Goalie:Users:edr:Documents:BUUF:BUUF Library:BUUF library in OO.txt"
I found that error -10004 is a permissions error, so I made sure that the files and their folders are all "Read & Write," but the problem persists. Error 39 is the EOF, presumably resulting from inability to open the file.
-*"*-.,,.-*"*-.,,.-*"*-.,,.-*"*-.,,.-*"*-.,,.-*"*-.,,.-*"*—
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden
|