Articles Archive
Articles Search
Director Wiki
 

Creating Internet Shortcuts

May 29, 2001
by Will Turnage

Dear Multimedia Handyman,

I'm working on a dual platform Director-based app and I need to create a desktop shortcut a user can interact with that fires up a URL with updates etc. I've got a handle on obtaining the correct cd path for both platforms, and I can figure out how to identify different platform types, but I haven't figured out how to interact with different OS's in a neat way. I would appreciate any help.

Regards

Justin

Justin,

If you want to create aliases or shortcuts on a user's desktop, then first of all, you're going to need to use two Xtras. The first Xtra should be a system information Xtra like FileXtra3, the BuddyAPI Xtra, or the DirectOS Xtra. The second Xtra you'll need to use is the FileIO Xtra which comes free with Director.

The first step is to find the path to the user's desktop. This step is very important because the path to a desktop can be different on every machine. In this code example, I'll use FileXtra3 because it's fairly straightforward and better yet, it's free, but you should have no problem using any other system information Xtra to do the same thing.

gFileObj = new (xtra "filextra3")
if the platform contains "Windows" then
    desktopPath = gFileObj.fx_FolderGetSpecialPath ("CSIDL_DESKTOPDIRECTORY")
else
    desktopPath = gFileObj.fx_FolderGetSpecialPath ("kDesktopFolderType")
end if
gFileObj = 0

The first thing this code does is create a new instance of FileXtra3. Next it checks to see whether it is running on a Windows machine or a Macintosh. If it's running on Windows, Windows-specific code determines the path to the desktop, otherwise it uses Mac-specific code to determine the path to the desktop. Finally, the code deletes the instance of the Xtra by setting it to zero.

Now that you have the path to the desktop, you need to make an Internet shortcut. Unfortunately, none of the system information Xtras I mentioned earlier have the capability to make quick aliases and shortcuts to URLs. They can make shortcuts to other files and folders on your hard drives, but URLs are a bit trickier. The solution for this problem is that instead of using FileXtra3 to create a shortcut, you'll create an HTML page that redirects the user to the web site of your choice.

HTMLString = "<html><head><title>Visit Director Online</title> <META http-equiv=refresh content=0;URL=> </head><body bgcolor=#ffffff> <center> Click <a href=http://www.director-online.com>here</a> to visit Director Online. </center> </body></html>"
DesktopFileName = "VisitDOUG.htm"

In this code, you've take the entire text of an HTML document and put in a variable called HTMLString. This string contains a document title, destination URL, number of seconds until the page refreshes (in this case, zero), and it also a simple text link for browsers that don't support redirects. Finally, you create another variable that contains the name of the file that will appear on the user's desktop. It's very wise to end this file name with am .htm extension so that your computer will automatically open the file in a web browser in Windows.

The final step is to create the HTML page on the desktop.

fileObj = new (xtra "fileIO")
fileObj.createFile (desktopPath & DesktopFileName)
fileObj.openFile (desktopPath & DesktopFileName, 0)
fileObj.writeString (HTMLString)
fileObj.closeFile ()
fileObj = 0

This code creates a new instance of the FileIO Xtra. Next it creates a new, blank file on your desktop using the desktop path and file name you declared earlier. Then it opens the new file and writes your HTML into the file. And when that's finished, the Xtra closes the file and deletes itself.

The Mac needs a couple of extra steps. Just naming the file doesn't associate it with an application on the Mac, and on most systems, SimpleText would be the default application. Turning back to FileXtra3, though, you can set the file type and creator attributes of the file, to associate it with Internet Explorer or Navigator:

gFileObj = new (xtra "filextra3")
if the platform contains "Windows" then
    nothing
else
    gFileObj.fx_FileSetType (desktopPath & DesktopFileName, "TEXTMOSS")
end if
gFileObj = 0

The file type becomes TEXT. The four-character creator code for Navigator is MOSS. To associate the file with Internet Explorer, you use the string "TEXTMSIE" instead.

And that's it. The final result is a file on the desktop that will redirect the user to any web site that you want.

Will Turnage is a multimedia programmer based in New York City. In addition to his weekly role as Director Online's Multimedia Handyman, he is also the Technology Director for Sony Music's Client Side Technologies Group. You can read more about his work at http://will.turnage.com/.

Copyright 1997-2024, Director Online. Article content copyright by respective authors.