l i v e c o d e

Opening a Folder on the Desktop
Mac OS 9 Mac OS X Windows

The following is a way to open a folder window on the desktop in both Mac and Windows. The Windows way is a bit “sneaky” because it takes advantage of file aliases, but it works just the same:
on mouseUp
  answer folder "Get a folder:"
  if it <> "" then
    OpenFolder it
  end if
end mouseUp

on OpenFolder pPath
  switch (the platform)
  case "Win32"
    set the hideConsoleWindows to true
    if the shellCommand is "cmd.exe" then
      create alias "C:/Temp.lnk" to file pPath
      get shell("C:\Temp.lnk")
      delete file "C:/Temp.lnk"
    else
      get shell("start" && quote & pPath & quote)
    end if
    break
  case "MacOS"
    if the systemVersion >= 10 then
      get shell("open " & pPath)
	else
      put "tell application " & quote & "Finder" & quote & cr & \
        "activate" & cr & \
        "open folder " & quote & ConvertPath(pPath) & quote & cr & \
        "end tell" into tScript
      do tScript as AppleScript
    end if
    break
  end switch
end OpenFolder

function ConvertPath pPath
  if char 1 to 9 of pPath = "/Volumes/" then
    delete char 1 to 9 of pPath
  else
    put line 1 of the drives before pPath
  end if
  replace "/" with ":" in pPath
  return pPath
end ConvertPath
Enjoy!

Posted 10/23/2002 by Ken Ray
Revised 10/24/2002 by Ken Ray


Close this window Print this window