Force-launch IE instead of default browser

Is there a way via Applescript to use load a locally-stored .htm file with Internet Explorer, even if the user has a different browser set as their default browser? Would it be something like “launch loadme.htm with appname of apptype ” (something along those lines?)


This might work:

set theHTMfile to alias "path:to:htm"

tell application "Finder"
	set {ieName, ieContainer} to {name, container} of application file id "MSIE"
	set pathToIE to ((ieContainer as alias) as text) & ieName
	open theHTMfile using alias pathToIE
end tell

Perfect! Thank you so much - - this is just what I needed. One last question - - - - I’m trying to think of a nice temporary place to stash the .htm file on the user’s hard-drive, where I then alias to it, launch from it, and then delete it afterwards. I’m having a very tough time getting all these pathname options straight in Applescript. Let’s say for instance that I want to create an alias to a file called “launchregistration.htm” in the user’s active Mac OS X “Temporary Items” folder. Is there an easy way to alias right to that folder automatically in Applescript?

I’m a bit worried that not everyone will have a “Temporary Items” folder - - - perhaps there’s a safer place - - - all I need is a place to stash 1 file temporary. In any case, I could use some advice on aliasing to such a folder.

Bummer, I spoke too soon - - - - actually there is one issue with that code - - - if IE is up and running already, it works great - - - - however if IE is not up and running, when I run the code with the proper filepath, IE popup up an error message saying “File not found”. If I then run the script a 2nd time after IE is up, it works fine. Any idea why IE would do that? Is there a way to launch IE to “blank:”, and then run the script?

This should open IE first, but it may use IE’s preferences to determine what type of window, if any, is opened. Ideally, the script would ‘launch’ IE, which should result in no windows, but I couldn’t figure out how to make it happen.

tell application "Finder"
	set {ieName, ieContainer} to {name, container} of application file id "MSIE"
	set pathToIE to ((ieContainer as alias) as text) & ieName
	open alias pathToIE
	open theHTMfile using alias pathToIE
end tell

I’d be willing to bet that everyone has a temp folder by default. This should get you started:

set tempFol to path to "temp"
set pathToTempFile to ((tempFol as text) & "launchregistration.htm")
-- do something to alias pathToTempFile

Sooo close - - - the last browser code sample works, except that in my case the user won’t be able to get to their default homepage, as I’m launching the user’s browser when they are in the middle of configuring a DSL router, so they won’t have access to a live internet connection (which is why I need to point IE to a locally-stored filed).

I seem to be between a rock and a hard place - - - either IE launches to the local .htm file, and IE gives a “File not Found” error when it first launches, or we launch IE first, THEN load the local .htm file (which doesn’t work for me since IE won’t be able to get to the default homepage, so it’ll still give an error).

It almost sounds like I need to somehow set their default homepage in Internet Connect to “blank” or something so that IE will not attempt to load anything when it launches for the first time. That might work, but is there a better way?

I don’t understand why IE is giving a “file not found” error. Is the same script placing the htm file? If so, it might be that the script is outrunning the Finder. If this is the case, it might help to use Finder’s ‘update’ command on the htm file.

tell application "Finder"
	set {ieName, ieContainer} to {name, container} of application file id "MSIE"
	set pathToIE to ((ieContainer as alias) as text) & ieName
	update theHTMfile
	open theHTMfile using alias pathToIE
end tell

Nope - - the file was written and closed out long ago. I really don’t get it either, but I’m curious if it does the same thing on your Mac.

If you run this Applescript:


set theHTMfile to alias "Macintosh HD:notoolbar.htm"

tell application "Finder"
	set {ieName, ieContainer} to {name, container} of application file id "MSIE"
	set pathToIE to ((ieContainer as alias) as text) & ieName
	open theHTMfile using alias pathToIE
end tell

(replacing “Macintosh HD” with the name of your drive)

and set your html code in “notoolbar.htm” to this:


<html>
<head>
<script>
function hidebars(){
window.open("http://www.apple.com","","toolbars=no");
window.close();
}
</script>
</head>
<body onload="hidebars()">
</body>
</html>

I hope you’ll see what I see - - - if IE is already open, it works great. But if IE isn’t already open, it gives a Cannot find file" error, and subsequently works on the 2nd try.

I REALLY appreciate all your advice - - - once this last bug is figured out, I’m done and can finally move on to my next project :slight_smile:

Well, I hate to be the bearer of good news but it worked perfectly. For the record, IE was not running when I ran the script and I ran it from Script Debugger and as an application. I’m running OS X 10.2.6 and IE 5.2.2. :shock:

Ok, I lied! I had the file on my desktop and the script worked fine. When I moved the file to “My HD:notoolbar.htm”, the script failed with a “File not found” error! I suspect that it must be a permissions issue caused by the file being located outside of the user domain. I apologize for the false good news.

It didn’t work for you too! That’s great news!

Mac OS X has really confused my life - - - I love it, but paths, permissions and domains will be the death of me. I thought that the root of the hard-drive was in my “domain” when logged in as administrator.

Since the file could go anywhere, would I do best to put it at “~” (home)? I assume that’d be in the domain. I don’t know, however, how to tell Applescript to look at home for the .htm file. Is it defined in Applescript as ~, or did they by chance make a HOME reserved word?

What I really don’t understand is why it would work the 2nd time, but not the first time.

Hmm, good point. I don’t know why it works on attempt #2. The following will provide an alias to the root level of the user’s directory:

set home to path to "cusr"

Hmmmm - - - still doing the same thing, even when the file is in the user’s HOME directory. I’m not sure what to make of this - - - - it works, but only on the second try. Where exactly was the .htm file when it worked for you on the first try? Desktop?


set home to path to "cusr"
set theHTMfile to home & "notoolbar.htm"

tell application "Finder"
	set {ieName, ieContainer} to {name, container} of application file id "MSIE"
	set pathToIE to ((ieContainer as alias) as text) & ieName
	open theHTMfile using alias pathToIE
end tell

It works on the desktop or anywhere within my user folder. I made a slight change to the script. I hope it works. :slight_smile:

set home to path to "cusr"
set theHTMfile to (home as text) & "notoolbar.htm"

tell application "Finder"
	set {ieName, ieContainer} to {name, container} of application file id "MSIE"
	set pathToIE to (ieContainer as text) & ieName
	open alias theHTMfile using alias pathToIE
end tell

Excellent - - - that seems to have done the trick! Thanks so much for your help. That was a nasty problem to figure out, and I know I couldn’t have done by myself in that amount of time. The alias referencing an alias technique seems to work, from within the user domain.

Sorry to reply when the problem has go out :oops:
I think the best one-line solution to open a page using IE could be:

tell application "Internet Explorer" to open aliasToFile

--> or...

tell app "Finder" to open aliasToFile using application file id "MSIE"

Also, I don’t think the “user domain” has to do with this stuff… This works for me:

set theHTMfile to "/notoolbar.html" as POSIX file --> eg, file "Macintosh HD:notoolbar.html"
tell application "Internet Explorer" to open theHTMfile

Maybe your “file not found” was cause by “open alias pathToIE”, which usually will open a default document, pointing to user’s default page. The cycle would be:
:> open default home page in document 1 → file not found!
:> open your html file in document 1
Instead of (based on my own code)
:> open your html file in document 1

I posted this because I was interested in the “user domain” part, and I would like to know if this code (html file in the startup disk) works or not for you… :?:

Hmmm - - - not sure why, but when I try your method, nothing happens - - - IE opens up, but just opens to the default homepage and does not open the locally stored .htm file on the root of my hard-drive.

Why force the user to see the file open in IE? I often find it annoying that a readme file opens itself in a browser I didn’t have open. It sounds like this probably won’t be a problem for your case, but if the page is simple, why not just open the file? :slight_smile: