Save And Launch Tab Group Scripts (Updating Bookmarks)

The Problem

Do you ever have this issue?

 I have a bunch of tabs that I don't need right now but I want the next time I'm working on programming.

I have a bunch of tabs that I don't need right now but I want the next time I'm working on programming.

Often when I am done working for the day I have a bunch of tabs that I need tomorrow but aren’t currently relevant. There are a few ways to save them but non really accomplish what you want. I have written 2 scripts to solve this problem.

The Solution

When you are done working, you launch the “Save Tabs” script. Which does the following:

  • Looks at all the visible windows. (Any Safari window not minimized.)
  • Saves the URL’s of every tab in those windows to a text file.
  • Closes the Safari Windows.

When you start working, you launch the “Open Tabs” script. Which does the following:

  • Opens all of the tabs in Safari.

It’s easy to use and you can even have multiple versions for different tasks.

Download The Scripts

Save Safari Tabs

Open Safari Tabs

Update: I made a version for the Chrome Browser as well.

Save Chrome Tabs

Open Chrome Tabs

How To Set Them Up

Unfortunately this isn’t something that will automatically work. You need to do a couple things to get everything working.

  1. Create a text file and save it somewhere. (I recommend a plain text .txt file.)
  2. Open both of the scripts in the ‘Script Editor’ app. (This is installed on all Macs. If you can’t find it launch Spotlight and search ‘Script Editor’.)

Save Tabs Script

  1. Drag the text file you created from Finder to the bottom of your Save Tabs script. It will show something like this: /Users/iankohlert/Dropbox/Files/programmingtabs.txt
  2. Replace the ‘/‘ with ‘:’

  3. Near the bottom of the script you will see this:

open “Paste your path here. Remember to replace the ‘/‘ with ‘:’“

Take the your path and paste it between the quotation marks. It should look like this:

open "Users:iankohlert:Dropbox:Files:programmingtabs.txt"

That's it. You can run it via the play button at the top of Script Editor. To check that it is working, open your text file and see that the URL’s from your visible Safari windows are there.

Note: You may want to “comment out” a line or two while testing this. For example you may not want to close the Safari windows until you are sure the URL’s are being saved properly. In that case you should add 2 dashes (-) before this line:

--close (windows whose visible is true)

Simply remove the two dashes to close the windows when the script is run.

Opening Tabs

  1. Drag the text file you created from Finder to the Open Tabs script.
  2. On the line ‘set theFile to (“Put the file path you dragged in from Finder here”)’ Erase everything within the “” marks and paste the text that showed up when you dragged the file in from Finder. It should look something like this:

set theFile to ("/Users/iankohlert/Dropbox/Files/programmingtabs.txt")

Note: You don’t have to change the slashes (/) to colons (:) here.

That is all you need to do to get the Open Tabs script working. If you have already saved some tabs, run the script and they should all open back up.

Launching These Scripts

While you can launch these scripts via the Finder, you probably want an easier way to do it. Personally, I use Alfred to launch them. There are also apps like FastScripts that will do the same thing. Here are the scripts as Alfred workflows:

Save Tabs Alfred

Open Tabs Alfred

Note: These only work with Safari. If there is interest I'll make ones that work with Chrome.

You still need to make the changes outlined above. Go to the workflows and double click on “Run NSApplescript”.

This allows you to launch Alfred and type either savetabs, or opentabs to run the scripts. Super easy and if you want you can even change it so they are launched with a keyboard shortcut.

Using This Script To Launch/Quit Apps

I use these scripts to open and close my “workspaces”. My workspaces are all the files/apps/websites needed for a specific task. You will notice that the examples I showed have the file ‘programmingtabs.txt’ in them. That is because I use these scripts as part of my programming workspace. You can launch/quit apps by adding this to the bottom of the script:

To Launch An App

launch application “AppName”

Do that for as many apps as you need.

To Quit An App

quit application “AppName”

Just replace AppName with what ever app you want to open or close. (Keep the quotation marks)

Having Multiple Scripts For Multiple Tasks

You can even make duplicates of these scripts for multiple tasks. For example: I program, write and study math. So I could have 3 text files and 3 versions of the scripts for each topic.

If You Have Problems

You can comment below or send me an email at I