Launching a Local HTML File
Mac Only  Mac Only (Mac Only)

Launching a local HTML file on the Mac is not as easy as it sounds; at least not under OS X. However, to provide a good cross-Mac solution, here's how to do it. The trick is that in OS X, the type/creator code of the file causes it to have problems in being launched in the default browser, so we need to stip this info away before we launch it.

Here we go:

on mouseUp
  answer file "Pick a file to launch:"
  if it <> "" then
    launchHTML it
  end if
end mouseUp

on launchHTML pPath
  if the systemVersion >= 10 then
    StripTC pPath
  end if
  if char 1 of pPath = "/" then delete char 1 of pPath  -- For OS 9
  send "file:///" & pPath to program "Finder" with "GURLGURL"
end launchHTML

on StripTC pPath
  put pPath into tDestPath
  set the itemDel to "/"
  put last item of pPath into tOrigName
  
  -- First, copy the target file to a dummy file; this removes the T/C
  put "temp.html" into last item of tDestPath
  get shell("cp" && q(pPath) && q(tDestPath))
  if it <> "" then
    answer "Error:" & it
    exit to top
  end if
  
  -- Then, copy it back over the original
  put tOrigName into last item of pPath
  get shell("mv" && q(tDestPath) && q(pPath))
  if it <> "" then
    answer "Error:" & it
    exit to top
  end if
end StripTC

function q pWhat
  return quote & pWhat & quote
end q

(Note that the above code is a bit more refined than was posted to the MetaCard List. - Editor.)

Posted 8/9/2003 by Ken Ray to the MetaCard List   (See the complete post/thread)