Selecting default browser

Greetings! I’ve been posed with a rather tricky project. I’m working on a project to allow a user to select a folder with a group of web pages (.htm and .html), be able to open each web page in a browser, and have the browser print each page. This is to allow batch printing of large web sites. I’m trying to keep it flexible so I’m using a ‘choose folder’ call to allow the user to select which folder he/she wants to process. The script extracts all the files with extensions of .htm. Up to this point the script works fine, however, I’m running to a few rather difficult problems that I can’t find solutions for in Apple’s, rather inadequate, documentation.
One (1): I’m using a ‘choose file’ command to have the user select their web browser. It’s ugly and confusing and I’m wondering if there’s a way to access the default browser from within Applescript.
Two (2): When I open the browser (using the technique above), I get unpredictable results. If I select Navigator (4.7) as the browser, NN opens and displays the page, but I can’t get it to print anything. If I choose IE (5.0), it opens, NN opens then collapses, then IE just displays a blank page. Sometimes, the browsers open the source code for the web page in SimpleText, then nothing happens after that.
Are there fixes to these problems? presuming that I can only use the Apple ScriptEditor?
Below I’m copying the code I’m using for this project so the more savvy scripters can see if I’m making any grotesque errors.
Thank you,
Jon Lester
Software Developer
Woller, Cook, and Misamore
--------------------- Begin Applescript Code Block ------------

tell application “finder”
set playFiles to choose folder
set moreFiles to (every file whose name contains “.htm”) in playFiles
set browser to choose file with prompt (“Which browser…”)
set max to count moreFiles
set i to 0
repeat
if i = max then
exit repeat
end if
set temp to file i of moreFiles
tell browser
print temp
end tell
set i to i + 1
end repeat
end tell

---------------- End Applescript Code Block --------------------

: Greetings! I’ve been posed with a rather tricky project.
: I’m working on a project to allow a user to select a
: folder with a group of web pages (.htm and .html), be
: able to open each web page in a browser, and have the
: browser print each page.
Here is a cleaned up version of your code with some additions. While it may or may not work it will give you some ideas, I hope. I am working on a better way to choose the browser.
-------- set playFiles to choose folder tell application “Finder”
set moreFiles to (every file whose name ends with (“.htm” or “.html”)) in playFiles end tell set browser to choose file with prompt (“Which browser…”) set max to count of moreFiles set i to 0 repeat while i <= max
tell application browser
open file i of moreFiles
print file i of moreFiles
close frontmost
end tell
set i to i + 1 end repeat -------

"Two (2): When I open the browser (using the technique above), I get unpredictable results. If I select Navigator (4.7) as the browser, NN opens and displays the page, but I can’t get it to print anything. If I choose IE (5.0), it opens, NN opens then collapses, then IE just displays a blank page. Sometimes, the browsers open the source code for the web page in SimpleText, then nothing happens after that. "
Instead of asking users a browser with which to view or print a file, consider writing a script for each browser which can be double-clicked.
Is drag ‘n’ drop on an applet unacceptable? The applet could be tailored to a browser, or the user could drag ‘n’ drop the browser (store this in a property), then the files to view or print.
Have you tried setting the creator type of the chosen files to the creator code of the appropriate browser (and restoring it, if necessary) – once this is done, the chosen files can be printed using the Finder’s print command (the creator code will cause the proper application to respond; e.g. print every item of [folder]; print [file]). I can’t say I 've used this, so it may not work as I expect.
How well does the “open [file] using [application]” command work for you?
As to why Netscape wouldn’t print anything, I am clueless.
“If I choose IE (5.0), it opens, NN opens then collapses, then IE just displays a blank page.”
My guess: Netscape is the default browser. Your script tells IE to open, but the default browser also attempts to handle file, which forstalls its appearance in IE. Plus it’s not as if browsers are stable software.
mg

: Greetings! I’ve been posed with a rather tricky project.
: I’m working on a project to allow a user to select a
: folder with a group of web pages (.htm and .html), be
: able to open each web page in a browser, and have the
: browser print each page. This is to allow batch
: printing of large web sites. I’m trying to keep it
: flexible so I’m using a ‘choose folder’ call to allow
: the user to select which folder he/she wants to
: process. The script extracts all the files with
: extensions of .htm. Up to this point the script works
: fine, however, I’m running to a few rather difficult
: problems that I can’t find solutions for in Apple’s,
: rather inadequate, documentation. One (1)
: I’m using
: a ‘choose file’ command to have the user select their
: web browser. It’s ugly and confusing and I’m wondering
: if there’s a way to access the default browser from
: within Applescript. Two (2)
: When I open the browser
: (using the technique above), I get unpredictable
: results. If I select Navigator (4.7) as the browser,
: NN opens and displays the page, but I can’t get it to
: print anything. If I choose IE (5.0), it opens, NN
: opens then collapses, then IE just displays a blank
: page. Sometimes, the browsers open the source code for
: the web page in SimpleText, then nothing happens after
: that.
: Are there fixes to these problems? presuming that I can
: only use the Apple ScriptEditor?

I agree with macguy about the probable cause of Navigator being launched when IE tries to open a file. I’m also clueless about how to get it to print anything.As for identifying the default browser, there was a script application called ‘Browse the Internet’ installed with Mac OS 8.0 (I think) that launched the default browser by means of a command in «event» format. To borrow from that:

set playFiles to choose folder
tell application "Finder"
	activate
	set moreFiles to (every file whose name contains ".htm") in playFiles
	try«event GURLBROW» with «class errr» 
		-- activate the default browser 
	on error msg 
		display dialog msg with icon note 
		return 
	end try 
	set theBrowser to ""
	repeat until theBrowser is not ""
		-- wait until the browser appears in the processes
		try
			set theBrowser to the file of the first process whose frontmost is true
		on error
			-- the Finder, not a process, is still frontmost
			delay 1
		end try
	end repeat
	set browserName to the name of theBrowser
end tell
repeat with thisFile in moreFiles
	tell application "Finder" to open thisFile using theBrowser
	tell application browserName
		-- Somehow print, using commands from the Standard/Required Suites
	end tell
end repeat

NG