How to get url from most active tab from firefox which is in focus, by bash or python ?
The follow partly solution, show how to do it if only one Firefox window are opened. ( This partly solution are not able to do this if more than one FF windows are open. This partly solution, check only the most active tab from only one running FF window or if more than one ff window are open, the most active tab, from first started FF window.).
Partly Python solution: import json, lz4.block, glob, subprocess
wins = subprocess.run('wmctrl -l', shell=True, stdout=subprocess.PIPE) title = next(ln for ln in wins.stdout.decode('utf-8').splitlines() if 'Mozilla Firefox' in ln) for f in glob.glob('.mozilla/firefox/*default*/sessionstore-backups/recovery.jsonlz4'): j = json.loads(lz4.block.decompress(open(f, 'rb').read()[8:])) for win in j['windows']: for tab in win['tabs']: for entry in tab['entries']: if entry['title'] in title: print(entry['url']) exit()
Remark:
A solution in bash or Python is sought, but not one that requires the installation of a browser addon, based on Javascript, Selenium or Brotab and without to use the not treadsafe buggy xdotool.