print string on a browser, shell script

227 Views Asked by At

I can't find a command to print on a browser a string in a shell script. For example here on stackoverflow. I'd like to create a script that writes a string in the searchbar and search

xdotool mousemove x y # position of the searchbar
xdotool mouseclick 1 # leftclick
[[command that writes a string on the searchbar]]
xdotool key KP_Enter # press enter

It should be easy but I can't find it

2

There are 2 best solutions below

1
grundic On

Would answer in this question be useful? Just replace url with apropriate search string https://stackoverflow.com/search?q=foobar

0
Jamil Said On

There might be an approximate way to do what you want (tested in Linux Debian 8). You could -- as a normal user, not root (see this for the reason) -- run the following command (on a terminal):

firefox "http://stackoverflow.com/search?q=my_search_term"

That would open firefox on a Stack Overflow's page that would display the search results for the term my_search_term.

If you need this code to be run on a script that runs as root, it would still be possible to (safely) run this command if you run it as a "normal" user instead of root, such as:

su - myuser -c 'firefox "http://stackoverflow.com/search?q=my_search_term"'

To find out who is the user who should be used to run the command above, one of the best options would be to use the logname command, such as:

myuser="$(logname 2>/dev/null)"

Note: This workaround of sorts would also works on many other web sites, such as Google, just substitute with the right url address, such as:

firefox "http://www.google.com/search?q=my_search_term"