Trouble with file types....

I have a program that dynamically generates an .html file. At present, however, this “file.html” is actually considered to be a text document by the finder. I’ve tried everything I can think of to make it open with the default web browser, but it just opens in text edit every time.

  1. Is there a way that I can open the file for writing as an .html file rather than text?

  2. Can I change the file type once its written so that the finder knows to open it in a browser?

  3. Is there some line of code that will force it to open in a browser anyway, just as is?

THANKS!

Hi,

For you to be able to edit the html file as you see it in a browser, you need a what you see is what you get (wyswyg) html editting app. There are many of these apps, but a good freeware wyswyg editor is Netscape Composer. You don’t edit the html code.

The file type for html is TEXT. So if you want to open the file in a browser, then you need the change/set the creator type. Here’s some creator types:

MSIE - Internet Explorer
MOSS - Netscape
sfri - Safari

You can easily get creator types with:

set the_app to choose file
file creator of (info for the_app)

It’s wierd but if you choose Netscape, you might get MOZZ when it should be MOSS. You can also have the file open in your default browser by setting the creator type to ???.

You can open a file in the default web browser with:

open location “file///Users/etc./”

but I think the file can’t have a creator type. This uses a local file address. You can open a file in any browser with an AppleScript tell statement:

set the_file to choose file
tell app “Internet Explorer”
open the_file
end tell

for example. Here, if you’re have classic, you need to make it not open with the classic browser if one exists. You can also open the file using the Finder.

If I think of anything else, I’ll try to write back.

Editted: in the last simple script with the tell statement, if you open a file this way, look in the address bar of the browser. You’ll see the local file address of the file. You can use this local url with the ‘open location’ command.

gl,

I tried the “???” method you mentioned. Interestingly, if I change the creator type to “???” and then open the file through applescript, everything works fine and the file takes the Safari logo. However, if I simply set the creator type and let the user double click it, then it still has the same old logo and opens with simpletext like it used to.

I could set it to “sfri” or “msie”, but I’d rather not assume what browser they have.

Also, I did try using the open location thing…and it still opened with simpletext.

I suppose I can have nested code with try … “SFRI”
… on error … try “MSIE” … etc. but if they haven’t selected the preference which automatically opens the file, how do I find the default browser?

Thanks again for all your help! oh, and is there a list of these creator types anywhere, or do I have to just use /Developer/Tools/GetFileInfo ? THANKS.

Hi Esqwuared,

I’m in a rush now, but creator types are case sensative. Will read your post again and reply back after work unless somebody else answers.

gl,
ps. you can set creator types through applescript also.

set the_file to choose file
tell app “Finder”
set creator type of the_file to “MSIE”
end tell

Note that I tried all this in OSX. Opening with the Finder is another option to look into… I don’t know what would happen if you’re making applescript studio app.

Hi,

With the ‘open location’ command for opening files in the default browser, you might need to change the creator code to an anonymous one first as I posted before. Here’s a simple script that opens a file.html created in SimpleText:

set the_file to choose file – choose file.html
tell application “Finder”
set creator type of the_file to “???”
end tell
open location “file:///Users/kel/Desktop/Test%20Site/file.html”

Here, my SimpleText file is in a folder “Test Site” on my desktop. After you change creator types, it may take the system a while to change the file’s icon but the script should work I hope. Here, I hard coded the local file url in the open location url but you can make your script build the url from the file reference.

gl,

Hi Esqwuared,

I like a good mystery, but could not figure out what app you used to generate this file.html and get the behaviors you are experiencing. At first, I thought you might be writing your html code in TextEdit in rtf. So after numerous tries I could not save the rtf with the extension html. I just came up with an idea. Maybe you’re getting your html file from a windows machine. Ok so I’ll use MS Word to make web page. Maybe that’s how your generating your html files.

Later,