Skip to content

Instantly share code, notes, and snippets.

@dusekdan
Last active February 17, 2020 05:03
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save dusekdan/d6247be7a3f961138367332cde77fd23 to your computer and use it in GitHub Desktop.
Resume Browser Work from File

Why and What?

When I am working on something that I know I will get back to in a while and have to switch context (sometimes even a machine and an environment), I want to save all the relevant opened tabs from my browser to reopen them later. Ideally, I would like to avoid saving them to my bookmarks and rather save them together with a project (context) I was working on.

Before I wrote this small utility, I used to store the links in markdown format as a list with description of what I can find under given links. That was rather impractical and took a long time to initially write down, and also open later on.

With the utility, I can now save the links into the sources.txt file, one link per line. Then I just check-in the file together with the project into the VCS. When the time comes to start where I left of, I just run python resume.work.from.file path/to/directory/with/sources.txt/file and it opens all the tabs in my default browser.

import os, sys, webbrowser
DEFAULT_FILE_NAME = "sources.txt"
try:
path = sys.argv[1]
if not path.endswith(DEFAULT_FILE_NAME):
path = os.path.join(path, DEFAULT_FILE_NAME)
try:
with open(path, 'r') as f:
links = f.readlines()
except:
print(f"Failed to open {path}. Sorry, you're on your own.")
exit(2)
for link in links:
webbrowser.open_new_tab(link)
except:
print("Nothing to do here.")
exit(1)
https://google.com
https://danieldusek.com
https://example.com/this-is-just-an-example-file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment