Aug 05, '08 07:30:00AM • Contributed by: feloneouscat
I have been using the following method (posted on my blog) for several months. Basically, the process involves creating a script and a LaunchAgent to run the script. I hope that this helps others as much as it has helped me!
[robg adds: Read the rest of the article for the how-to from the author's blog -- however, this is here primarily as backup, in case the original blog post ever vanishes. Any changes to the original post won't be reflected here, but read on for the write-up as it appeared on the author's blog as of the publication date of this hint. Everything that appears below are the author's original words, not mine. I've only edited for layout and display, not content.]
Fortunately, the solution was pretty easy, it just required getting my hands dirty.
Difficulty: Moderate to Hard
Requires: Terminal
Poking around in the Safari directory, in ~/Libaray/Safari, I noticed that there was a file named LastSession.plist. That took all of 10 seconds!
So what I needed was something that would notice when this file had changed and copy it to a directory. I created a file named com.cannasoftware.lastsessiontimemachine.sh in the directory ~/Libaray/Safari with the following contents: Basically it says "make a directory, if it doesn't exist, named LastSessionTimeMachine and then copy the LastSession.plist to a file into that directory and name that file LastSession-year-month-day-hour-minute-second.plist. That's all.
Writing a script to copy the file was easy, but what I needed was something that would run the script. Agents to the rescue! An agent runs in the background and can do many things, one of which is stare at a file to see if it changes and if it does, to do something. In this case, we tell it to stare at the file LastSession.plist and when it changes, to execute our script.
To do this, I created the file com.cannasoftware.lastsessiontimemachine.plist in the directory ~/Library/LaunchAgents with the following contents: WARNING: Be sure to change USERNAME to the user name of your home directory. If you don't, this agent will not work!
TIME FOR A TEST DRIVE
Assuming everything is running, start up Safari and open multiple windows with multiple tabs. Now shut down Safari. If you examine directory ~/Libaray/Safari you should see a new directory named LastSessionTimeMachine. In that directory will be a file named LastSession-year-month-day-hour-minute-second (for example, LastSession-2008-07-31-7-58-32.plist).
That's it!
WHEN TO USE IT
Start up Safari and Reopen All Windows From Last Session. Everything should be fine. Assuming everything is working, shut down Safari. Start up Safari again, but don't click Reopen All Windows From Last Session. Shut down Safari. Start it up again and Reopen All Windows From Last Session. You should get a single window (or no window). Shut down Safari.
Using the Terminal, go to ~/Library/Safari/LastSessionTimeMachine and pick a time when you had multiple windows. Copy that file with the following (example):
cp LastSession-2008-07-31-7-58-32.plist ../LastSession.plist
Start Safari up and click Reopen All Windows From Last Session. You should be greeted with multiple windows and tabs again.
[robg adds: I haven't tested this one.]
