Plain Text Save As on Internet Explorer

Newby with first post! Have scripted Internet Connect to connect and then Launch Internet Explorer to go to particular URL. Then the page is Saved-As in Plain Text format with a new file name. Then the Browser quits and the connection is disconnected. My problem is that when I select the Plain Text Format, it still saves it in Web Page format. This is true even though I can see that the popup menu has changed to Plain Text. Do I have to do something else to make IE “accept” the input? I am using System Events for all of these actions. Any musings on this topic would be gratefully appreciated…Ken

You probably won’t be able to get any browser to save only the displayed text to a file. Using the text-only save feature of IE will just write the HTML code to file in plain text, not what’s displayed in the window. You’ll need to use GUI scripting to do that, as you’ll have to script a manual select all, copy, and then write the file yourself.

tell application "Internet Explorer"
	Activate
end tell

tell application "System Events"
	tell application process "Internet Explorer"
		tell window 1
			keystroke "a" using command down
			keystroke "c" using command down
		end tell
	end tell
end tell

delay 1 --> Seems to help

(* Define the file contents and write the file *)
tell me
	activate
	set theFileContents to the clipboard
end tell

set theTargetFile to (((path to desktop) as string) & "test.txt") as file specification
try
	open for access theTargetFile with write permission
	set eof of theTargetFile to 0
	write (theFileContents) to theTargetFile starting at eof
	close access theTargetFile
	
on error
	try
		close access theTargetFile
	end try
end try

This writes a file named ‘test.txt’ to the desktop with the text-only contents of the topmost window in IE. I did notice one quirk…if the window has javascript elements that steal focus from the window (like an auto-focusing text field) or if you’ve focused a text field youself, it will try to act on the text field and not the window and the procedure will fail. There may be some scripting way around this, but I’m not too familiar with gui scripting.

Good luck,
j

Hi,

Also, Safari does well getting the text of a web page. You probably need to convert line feeds to carriage returns.

gl,

Thanks for the tips. I tried the Select All and then Copy and Paste Special as Text. It worked like a charm. I will leave Save-As Plain Text for another day…Ken