| |||
| How To Add Time Machine To Safari |
|
|
|
| Written by Webmaster | |
| Friday, 01 August 2008 | |
![]() Apple What I needed was something like Time Machine for Safari. A way to go back in history and reload the windows I had inadvertently closed. Fortunately, the solution was pretty easy, it just required getting my hands dirty. Click "Read More..." to find out the details. Difficulty: Moderate to Hard Requires: Terminal Poking around in the Safari directory in ~/Library/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 ~/Library/Safari with the following contents: #!/bin/bash mkdir -p ~/Library/Safari/LastSessionTimeMachine cp ~/Library/Safari/LastSession.plist \ ~/Library/Safari/LastSessionTimeMachine/LastSession`date "+-%Y-%m-%d-%H-%M-%S"`.plist 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. Make sure it is executable with the following: Writing a script to copy the file was easy, but what I needed was something that would RUN the script. Agent's 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: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Disabled</key> <false/> <key>Label</key> <string>com.cannasoftware.com.lastsessiontimemachine</string> <key>ProgramArguments</key> <array> <string>/Users/USERNAME/Library/Safari/com.cannasoftware.lastsessiontimemachine.sh</string> </array> <key>WatchPaths</key> <array> <string>/Users/USERNAME/Library/Safari/LastSession.plist</string> </array> </dict> </plist> 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 ~/Library/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. |
|
| Last Updated ( Friday, 08 August 2008 ) |
| Next > |
|---|



