by Robert Howe and Laura Lunetta
Laura and I described an AppleScript (see the July-August 1998 MacToday) that helps Netscape Navigator crash less often. Because of space limitations, we couldn't explain everything in as much detail as we would have liked. We even had to forgo explanations in spots where we had a good idea some readers might have problems...a pox upon our editor!. Ah, but that's where the Web saves the day! Here you will find what we had to leave out of our "Crash-Less-Often Netscape Navigator" column. Where the column was unclear, incorrect, or incomplete, this web page will clarify, correct, and complete.
What follows is our original column with our clarifing, correcting, and completing annotations set off by "***" and in "bold".
Another note: This character ƒ should appear as an ...not all browsers will support this special character. If your browser doesn't support it, there's not much we can do to help. The actual character used by Netscape to signify a folder is that Latin small f with a hook. Sorry!
Finally, several readers wrote to say they have been getting errors when trying the script with Netscape Navigator 2.x and 3.x. I thought I had updated this page to include the fix; I was wrong. Thanks to Vincent Malmgren for first bringing this to my attention, and to John Readout for bringing it to my attention again. This time I really, really have included the fix.
Raise your hand if you use Netscape Navigator. Ohhh, a lot. Now keep your hand up if Navigator's crashed on you. Ah-ha, we thought so. Want to know a secret? We've found that tossing Netscape's cache into the trash makes Netscape not crash--at least not as often. So guess what? Our column is about creating an AppleScript to throw away Netscape's cache then start up Netscape. You'll see the AppleScript Script Editor record your actions for playback, and you'll modify the recording for efficiency and safety.
Space limitations (i.e. "Scott and Jim, MacToday publishers, want a few pages for other writers ") prevent us from explaining every last detail in this column. You'll find these missing elaborations at <http://homepage.mac.com/rhowehmd/Inreach/MacToday>.
*** Elaboration Actually, that link is to our "Elaborations" index. But you knew that. ***
And while we've tested this script, we cannot guarantee it won't perform unwanted actions. You accept all risk of damages, because we can't. Neither will Scott nor Jim (see the prior paragraph). You could try Richard the Editor; although he won't accept responsibility either, he might send you an amusing note. Thus, if a script we helped you create starts sending e-mail to Scott and Jim saying how you want more and longer columns from Robert and Laura, well, the customer is always right.
With those two warnings in mind, let's create our script.
* Find and open the Apple Script Script Editor. If you are having problems finding it, try reinstalling AppleScript from your System 7.5 (or later) system disks. Or go to our elaborations page.
***
ELABORATION:
Apple included both AppleScript and the AppleScript Script Editor beginning with at least System 7.5. If you can't find your installation disk(s), or if you have an earlier version of System 7, you can get AppleScript and the Script Editor from Apple's web site <http://applescript.apple.com/>
If you don't have at least System 7.0, then we're terribly sorry...AppleScript won't work. Instead, you could try the old MacroMaker that was bundled with System 6.x. But neither of us remember how to use it, so you're on your own.
If reinstalling Applescript didn't help, you are having bigger problems than we can handle here. Email Robert or Laura and we'll try to help, but no promises!
***
* Find the Netscape "Cache ƒ". Keep it in its parent folder, but position it so you can easily drag it to the trash. If you don't know where the cache is, try looking in the system folder's preferences folder; you should find a Netscape folder. Look in there. (If you still can't find it, go to our elaborations page.)
***
ELABORATION:
Netscape's Cache could be in several places, and the version of Netscape you are using makes a difference too. Here's some suggestions (based on the versions we have available to test)
Netscape version 2.x and 3.x:
The default "Cache ƒ" is in the Preferences folder, in a folder called "Netscape". See Extra Figure 1. Be aware that Netscape has the exact location as a user-setable preference. Set it in the Options menu, in "Network Preferences...". The "Network Preferences" dialog that appears has a tab for the Cache; the path to the cache folder is shown there. If the path name is too long, it'll be abbreviated. (Well, the middle will be hacked out. But that's where you'll find the Cache folder.) Extra Figure 2 shows the Network Preferences dialog from Netscape 3.x (the dialog from 2.x is similar). Note the location of the cache directory.
Netscape Version 4.x:
The default Cache folder is in the Preferences folder, but not in a folder called "Netscape." Netscape 4.x saves the Cache in a private folder within the Preferences:Netscape folder. Odds are the folder you use has your name on it. (That's how you set up Netscape 4.x the first time you ran it.) In Extra Figure 3, you'll see the Cache folder in my folder.
***
Click the Script Editor's "Record" button, drag the "Cache ƒ" in to the trash, then click the script editor's "stop" button. You should have something that looks like Figure 1, with a script similar to:
tell application "finder" activate select folder "Cache ƒ" of folder "Netscape ƒ" of folder "Preferences" of folder "System Folder" of startup disk delete selection end tell
Pretty neat, eh? Too bad there's two BIG problems with this script.
***
ELABORATION
Actually, there's three problems. Four if you count a minor catch with having to start up PPP. Five, thanks to Vincent Malmgren and John Readout for bringing the problem with Netscape 2.x and 3.x to my attention. We'll discuss the third in just a bit, and the fourth and fifth just after that.
***
Click on the "run" button. You'll get the message that Apple Script couldn't find "Cache ƒ". Well, duh! It's not where it was anymore; it's in the trash!
Fix 1: To stop AppleScript from complaining when it can't find the "Cache ƒ", make the following changes to the script so far. (You'll have to type 'em in. Sorry):
tell application "finder" activate try select folder "Cache ƒ" of folder "Netscape ƒ" of folder "Preferences" of folder "System Folder" of startup disk delete selection on error beep end try end tell
The "Try....on error..end try..." lets you control AppleScript when something not normally expected happens. Here we just have it beep, but our elaborations page offers other suggestions.
***
ELABORATION
There's two things going on here: selecting the folder, and deleting the selection. You can trap for errors on one or both of these. What else could you do instead of have AppleScript beep? Maybe put up a message. Maybe ask if you want to find and delete the file(s) yourself. But heck, you don't have to have AppleScript do anything.
***
See that "Delete selection" line? That's dangerous. Picture this sequence of events:
* You start this Apple Script * You switch to the Finder to open your "Fergus, Dog Hero" novel. * Apple Script selects "Cache ƒ" * You find your novel, and have just finished the first click of the double-click to open it. * The AppleScript deletes the selection, which is now your document. Yikes!
Fix 2: Instead of the select-then-delete process that Apple Script records, we'll tell it to delete the "Cache ƒ" directly. To do this, change "select" to "delete", then get rid of the "delete selection" line in the script, as shown in Figure 2.
Next, we need to have our script launch Netscape. Just type in the following line after the "end tell":
open application "Netscape"
(Also shown in Figure 2, except you don't need to type in "Navigator 3.04".)
When we try running the script, our Script Editor will ask us to locate our copy of Netscape then automatically substitute the exact name (for example "Netscape Navigator 3.04") for whatever name we used (in this case, "Netscape").
Ready? Run the script. The first time you do, the Script Editor will ask where Netscape is. If you don't have a "Cache ƒ", you'll hear a beep; otherwise, the "Cache ƒ" will be tossed. Then the Script Editor starts up Netscape. Horay!
***
ELABORATION
Now for the third problem, the one we hadn't noticed at the time we submitted this article:
Moving the Cache to the trash is not good enough for version 3.x of Netscape (and maybe version 2.x as well; I haven't gotten to my old machine yet to try). It'll keep using the cache even though you've moved it! To get around this problem, rename the cache folder...you can rename it either before or after you put it in the trash. I suggest renaming it after it's in the trash because the typing is easier.
So what do you have to do? Add a line that says...:
set name of folder "Cache ƒ" of trash to "Old Cache"
...right after the line beginning with "delete"
***
***
ELABORATION
The fourth potential problem: If PPP isn't running when you start this script, Netscape might attempt to start up PPP. If your Internet Service Provider is booked solid at times, the AppleScript might time out before the script finishes. If this happens to you, you'll see an error like that in Extra Figure 4:
This really doesn't hurt anything, since the script's work is pretty much done by the time Netscape starts up. But to prevent getting this error, we must add another (sigh) two lines to our script to change AppleScript's 2-minute default timeout wait. Depending on how long it takes your PPP to start up, you might try changing AppleScript's timeout to 4 minutes. (AppleScript measures timeouts in seconds, so you have to do some calculations here...sorry.)
So what do you have to do? Add two lines, one before and one after the "Open Netscape" line:
with timeout of 240 seconds open application "Netscape Navigator 3.04" end timeout
ELABORATION
The fifth potential problem: AppleScript and Netscape's earlier versions (2.x and 3.x) have trouble getting along. After Netscape opens, AppleScript reports the error "can't make some data into the expected type."
We can work around that. Where we have the line
open application "Netscape Navigator 3.04"
...replace it with the following:
try open application "Netscape Navigator 3.04" on error number thisErrorNumber if thisErrorNumber = -1700 then -- ignore it; it's the 'can't change data' problem we know about else beep -- we got some other error end if end try
----- THE FINAL SCRIPT! -----
tell application "Finder" activate try delete folder "Cache ƒ" of folder "Netscape ƒ" of folder "Preferences" of folder "System Folder" of startup disk on error beep end try end tell with timeout of 240 seconds try open application "Netscape Navigator 3.04" on error number thisErrorNumber if thisErrorNumber = -1700 then -- ignore it; it's the 'can't change data' problem we know about else beep -- we got some other error end if end try end timeout
***
You won't want to run the script editor every time you want to launch Netscape; luckily, you don't have to. By saving the script as an application, you'll create a super-alias to Netscape. Here's how:
Choose "Save As" from the File menu. From the save dialog, choose 'as application', with 'never show dialog' marked and 'stay open' not marked. (See Figure 3.) As a finishing touch, replace the resulting application's icon with Netscape's icon (Don't know how? See the elaborations page).
***
Elaboration:
You need to know how to change an icon? Oh, that's not too difficult. First you need an icon to copy; for this, we'll use Netscape's icon. Find your copy of Netscape, and single-click it. Then press command-I to bring up the "Info" window. (See Extra Figure 5).
Click on the icon in the Info window; you'll see a box drawn around the icon (see Extra Figure 6).
Now press command-C to copy the icon. Close the Info window, then repeat the process on the AppleScript Application you just created, except instead of pressing command-C to copy the icon, press command-V to paste the icon. Close the Info window, and you're done!
***
You're done! You've created an AppleScript to throw away Netscape's cache then start up Netscape. You saw the AppleScript Script Editor record your actions for playback, and you modified the recording for efficiency and safety. Netscape now crashes less often. Goals accomplished!
Other things you can do (as an exercise; answers are on our elaborations page)
- add comments to the script (a topic for a future article)
***
ELABORATION
Here's a taste of what's to come:
Comments in AppleScript are simple. Just add a double-dash where you want the comment to begin. A new line ends the comments. Here's some examples:
tell application Navigator -- Comment: Navigator is a browser. -- here's another comment. Navigator is made by Netscape. register protocol "MMan" for protocol "mailto:" -- use E-mailer -- instead of Netscape's mail package to send mail. "MMan" is Emailer's -- creator code. Every time a 'mailto' link is clicked, Emailer will -- set up a blank reply. end tell
***
- toss the global history file (in case you don't like people seeing where you've been)
***
ELABORATION
Well, the global history file is right next to the Cache folder in versions 2.x and 3.x. To delete it, add a line similar to this:
delete file "Global History" of folder "Netscape ƒ" of folder "Preferences" of folder "System Folder" of startup disk
...right after the earlier delete.
In Netscape 4.x, the Global History file is IN the cache folder. You don't have to do anything!
***
- set your favorite e-mail package as the default mail application (so when you click on links that send mail, you won't get Netscape's mail)
***
ELABORATION:
Hey! We already did that in the 'comment' example above. Geeze!"
***
- send e-mail to Scott and Jim saying how much more you like browsing the web with Robert's and Laura's crash-less-often Netscape!
***
ELABORATION:
This would not be fair to the other MacToday writers, so you'll have to send email to Scott and Jim the old way. That is, you'll have to write it. Sorry!
***
***** the end *****
Last updated: 11/17/1998