It's possible to get the current tab with xdotool:
# set focus to address on browser
xdotool search --onlyvisible --classname Navigator windowactivate --sync key F6
# copy address from browser tab to clipboard
xdotool search --onlyvisible --classname Navigator windowactivate --sync key Ctrl+c
# get off the focus from address from browser tab
xdotool search --onlyvisible --classname Navigator windowactivate --sync key F6
# delivery of clipboard content to variable
clipboard=`xclip -o -selection clipboard`
# clear clipboard
xsel -bc; xsel -c
# echo URL of active tab of active browser
echo $clipboard
Since xdotool is buggy and sometimes fires keys without stopping with the code above, I need another way to do the same, perhaps with wmctrl.
This is what I tried, using wmctrl on bash; it didn't work for me:
id=$(wmctrl -l | grep -oP "(?<=)(0x\w+)(?=.*Firefox)")
# set focus to address on browser
xdotool key --window $id "ctrl+l"
# copy address from browser tab
xdotool key --window $id "ctrl+c"
# delivery of clipboard content to variable
url=`xclip -o -selection clipboard`
# clear clipboard
xsel -bc; xsel -c
# echo URL of active tab of active browser
echo $url