Skip to content

Instantly share code, notes, and snippets.

@sbz
Created February 4, 2015 21:57
Show Gist options
  • Save sbz/d9cc018bd248aab6312c to your computer and use it in GitHub Desktop.
Save sbz/d9cc018bd248aab6312c to your computer and use it in GitHub Desktop.
mz-tab-urls: Get Mozilla Firefox tabs URLs on stdout
#!/usr/bin/env python
import ConfigParser
import json
import os
"""
Dirty script to get Mozilla Firefox tabs URLs on stdout
source: https://raymii.org/s/snippets/Get_the_current_or_all_Firefox_tab_urls_in_Bash.html
"""
mz_user = os.environ['USER']
mz_profile_path = \
"/home/{0}/.mozilla/firefox/profiles.ini".format(mz_user)
def LoadProfile(profile_path):
cp = ConfigParser.ConfigParser()
cp.read(profile_path)
return cp.get('Profile0', 'Path')
def GetProfilePath(path):
return LoadProfile(path)
def GetMozillaProfilePath():
return GetProfilePath(mz_profile_path)
def GetJson(path):
json_store = ""
with open(path, "r") as f:
json_store = json.loads(f.read())
return json_store
mz_store_path = \
"/home/{0}/.mozilla/firefox/{1}/sessionstore.bak".format(mz_user, GetMozillaProfilePath())
def GetMozillaSessionStore():
return GetJson(mz_store_path)
if __name__ == '__main__':
json_data = GetMozillaSessionStore()
for w in json_data.get('windows'):
for t in w.get('tabs'):
i = t.get('index') - 1
print t.get('entries')[i].get('url')
@sbz
Copy link
Author

sbz commented Feb 4, 2015

  • I can now open Firefox URLs in chromium like that:
% python mz-tab-urls.py | while read u; do chrome --remote "$u"; done;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment