Solution for saving and restoring pages/tabs in Safari

Posted by Pierre Igot in: Macintosh
September 23rd, 2003 • 4:10 pm

After reading my last “Apple Peel” column, a reader wrote me to mention a possible solution for users who want to quickly save and restore their open pages/tabs in Safari.

The AppleScript-based solution is available on the ever-reliable Mac OS X Hints web site.

Like John Gruber noted a while back, Safari in its current incarnation has no AppleScript dictionary entry for accessing its tab functionality. In other words, its tab browsing architecture is “unscriptable“.

Even in applications where certain controls are not scriptable, however, Apple now has a solution called “GUI Scripting“. This solution makes every control that appears in an application window effectively scriptable, even if the application itself does not have AppleScript support or is only partially scriptable. (This solution reminds me of QuicKeys and other UI-based automation tools.)

In a way, it’s a “hack”, i.e. a non-orthodox way of doing things, but if Apple itself endorses it… It should be noted, however, that the GUI Scripting software provided by Apple is still in beta. So the usual disclaimers apply — although it doesn’t look like the software can do much harm.

In ORDER to be able to use the solution for saving and restoring pages/tabs in Safari mentioned , you need on the Mac OS X Hints web site, you will first need to install the GUI Scripting software. (It doesn’t require a restart.)

You should also install the “Script Menu” menu module provided by Apple in the AppleScript folder inside your main Applications folder.

Finally, you should also download the “Preview Release” of the new Script Editor application.

Once all that is done, you can just SELECT the first script on the Mac OS X Hints page, paste it in a new script window in Script Editor, and save it as a compiled script called “Save Pages and Tabs”.

Then you can SELECT the second script, paste it in a new script window, and save it as a compiled script called “Restore Pages and Tabs”.

Finally, you should put both compiled scripts either in your “Scripts” folder inside your home folder library or in the “Scripts” folder inside your system’s main library folder (depending on whether you want the script to be available to other users as well or not).

Now, whenever you are in Safari and want to save your current environment of loaded pages and tabs, you just need to go to the “Scripts” menu on the right-hand side of your menu bar and SELECT the “Save Pages and Tabs” script inside the “Safari Scripts” folder. The script will run, and will let you know when it’s done.

After that, you can quit Safari and relaunch it and SELECT the “Restore Pages and Tabs” script inside the “Safari Scripts” folder in the “Scripts” menu. That script will restore your saved environment, and let you know when it’s done.

It is not, of course, an ideal solution, in that you still need to invoke the command to save your environment manually — and if you haven’t done so recently when Safari crashes on you, then you won’t be able to restore what you didn’t save.

But it’s much better than nothing, and, in my limited testing, it does work. Thanks to the reader who referred me to the Mac OS X Hints page!


Comments are closed.

Leave a Reply

Comments are closed.