Open local file in browser

Howdy,

I have a script that needs to open a HTML file that resides on the local desktop. I would use the Finder but, if someone has their HTML files set to open in BBEdit or something other than a browser, it won’t work. What’s a generic way to do this? Can I use ‘open location’ from Standard Additions? If so, how do I construct the URL using a regular file path?

Thanks. :slight_smile:

Thanks! With your help and a bit of experimentation, I seem to have something that works. :slight_smile:

hi, rob…
This is a little tricky, but you can get the default browser of the user by reading a file called “com.apple.LaunchServices.plist”, located at preferences folder.

You must look for “U:http” and read some extra characters to get this text:

		<key>U:http</key>
		<array>
			<dict>
				<key>LSBundleIdentifier</key>
				<string>com.microsoft.explorer</string>
				<key>LSBundleLocator</key>
				<data>
				AAAAAAC2AAMAAQAAug6DKAAASCsAAAAAAAAB2gAAQVAA
				ALloB3UAAAAAASD//gAAAAAAAAAA/////wABAAQAAAHa
				AA4ALAAVAEkAbgB0AGUAcgBuAGUAdAAgAEUAeABwAGwA
				bwByAGUAcgAuAGEAcABwAA8AEAAHAGoAdQBsAGkAZgBv
				AHMAEgAiQXBwbGljYXRpb25zL0ludGVybmV0IEV4cGxv
				cmVyLmFwcAATAAEvAP//AAA=
				</data>
				<key>LSBundleRoleMask</key>
				<integer>-1</integer>
				<key>LSBundleSignature</key>
				<string>MSIE</string>
				<key>LSBundleVersion</key>
				<integer>336639</integer>
			</dict>
		</array>

(note that all carriage returns here are not carriage returns, but line feeds (ascii char 10)
A little exercice of read/parse text will give you not the name, but the creator of the default browser, which is cool for “tell app finder to open x using app file id y”…
:wink:

Thanks JJ. Maybe I’ll play with this and Late Night Software’s XML Tools. I’ll need to learn this XML/plist stuff sooner or later, so now is a good time to do it. :slight_smile:

off topic slighty but does someone have a link to a good xml editor seeing as pepper has gone the way of the dodo…

I like both bbedit & dreamweaver…

Never tried “FrameMaker”
Some people like OxYgen (http://www.oxygenxml.com/)
Also, some links to check:
http://www.entropy.ch/software/macosx/#testxslt (applescriptable)
Jeebox

Howdy Rob,

I’m just throwing this out there, but what about Peter Bunns stuff? He spent a long time refining that, and it appears to work very well. Even if you didn’t use it altogether, perhaps some of the code might shed some light on what your trying to accomplish.

Just a thot. :wink:

I agree that Peter has done an excellent job with Missing Link but I alread found what I needed. Thanks anyway! :slight_smile: