How to get the url from current tab of firefox, without need to install additional software?
5
votes
3
answers
2574
views
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
Asked by Alfred.37
(137 rep)
Jan 16, 2021, 03:12 PM
Last activity: Apr 7, 2023, 10:53 PM
Last activity: Apr 7, 2023, 10:53 PM