i made a script which creates html files, the problem is that they are set to open with textedit, i want them to open with the users default browser. i can change them to open with safari easily enough, but i want it to change to whatever browser the user set as default. is there any way to get info about the default browser? same with default image viewing app (for jpeg’s)
Model: iBook G4
Browser: Safari 2.0 (412)
Operating System: Mac OS X (10.4)
Change the creator type with Finder. I think “???” was default. Something like this:
set t to "
home
hi
"
set desk_path to (path to desktop) as string
set file_spec to (desk_path & “MyPage.html”) as file specification
set ref_num to (open for access file_spec with write permission)
try
write t to ref_num
close access ref_num
on error
close access ref_num
beep 2
return
end try
tell application “Finder”
set creator type of file_spec to “???”
end tell
I think “???” is the representation for four-nulls (ASCII 0).
Allways I need map files to their default apps, I first create the file using a shell, which will ensure that NO creator info is printed to the file, as in AS’s “write” command. Eg:
set theFile to (path to desktop as text) & "file.html"
do shell script "touch " & quoted form of POSIX path of theFile
--> now use AS' read/write commands
(this is a pure speculation), I still think the propper creator type would be ASCII 0 + ASCII 0 + ASCII 0 + ASCII 0, as you can read if you open the file with Resorcerer (or any res-editor). In my system, it also works if you set the creator type to “xxxx” or “qqqq”. It associates to the default browser, since the system doesn’t know an app with a signature like “xxxx” or “qqqq”. Or perhaps the 4-nulls are equivalent to 4-?, at all!
Anyway, I think it’s faster the “do shell script” call than involving the Finder… In fact, I allways fly away from the Finder when I can do it since OS X was born… It’s buggy, slow, and very workaround-able thanks to the *nix stuff (but that’s my opinion)…
I agree with you that faster is better, but setting properties with Finder is not that slow. The part that I don’t understand is how it didn’t work. No matter how I write using the standard additions write, it always opens in the default browser after changing the creator as long as I use the .html extension. There’s probably something else going on.
I understand what you’re saying about the other stuff. I think I read somewhere that “???” was the creator type for using the default app, but couldn’t find where I read that.
kel,
i just tried your script again in a separate script and it worked just fine, there was probably something buggy in my script preventing it from working. anyways, i already got it to work, but its good to know, thanks.