2015-03-10 23:22:53 +01:00
|
|
|
Writing qutebrowser userscripts
|
|
|
|
===============================
|
|
|
|
The Compiler <mail@qutebrowser.org>
|
|
|
|
|
|
|
|
qutebrowser is extensible by writing userscripts which can be called via the
|
2015-03-31 20:49:29 +02:00
|
|
|
`:spawn --userscript` command, or via a key binding.
|
2015-03-10 23:22:53 +01:00
|
|
|
|
2015-10-25 20:12:10 +01:00
|
|
|
You can also call a userscript via hints so they get the selected hint URL by
|
|
|
|
calling `:hint links userscript ...`.
|
|
|
|
|
2015-06-29 17:45:56 +02:00
|
|
|
These userscripts are similar to the (non-javascript) dwb userscripts. They can
|
|
|
|
be written in any language which can read environment variables and write to a
|
|
|
|
FIFO. Note they are *not* related to Greasemonkey userscripts.
|
2015-03-10 23:22:53 +01:00
|
|
|
|
|
|
|
Note for simple things such as opening the current page with another browser or
|
2015-03-31 20:49:29 +02:00
|
|
|
mpv, a simple key binding to something like `:spawn mpv {url}` should suffice.
|
2015-03-10 23:22:53 +01:00
|
|
|
|
|
|
|
Also note userscripts need to have the executable bit set (`chmod +x`) for
|
|
|
|
qutebrowser to run them.
|
|
|
|
|
2015-10-07 23:53:21 +02:00
|
|
|
To call a userscript, it needs to be stored in your data directory under
|
|
|
|
`userscripts` (for example: `~/.local/share/qutebrowser/userscripts/myscript`),
|
|
|
|
or just use an absolute path.
|
|
|
|
|
2015-03-10 23:22:53 +01:00
|
|
|
Getting information
|
|
|
|
-------------------
|
|
|
|
|
2015-06-29 17:48:30 +02:00
|
|
|
The following environment variables will be set when a userscript is launched:
|
2015-03-10 23:22:53 +01:00
|
|
|
|
|
|
|
- `QUTE_MODE`: Either `hints` (started via hints) or `command` (started via
|
2015-03-31 20:49:29 +02:00
|
|
|
command or key binding).
|
2015-03-10 23:22:53 +01:00
|
|
|
- `QUTE_USER_AGENT`: The currently set user agent.
|
|
|
|
- `QUTE_FIFO`: The FIFO or file to write commands to.
|
2015-04-20 07:50:47 +02:00
|
|
|
- `QUTE_HTML`: Path of a file containing the HTML source of the current page.
|
|
|
|
- `QUTE_TEXT`: Path of a file containing the plaintext of the current page.
|
2016-06-29 13:39:18 +02:00
|
|
|
- `QUTE_CONFIG_DIR`: Path of the directory containing qutebrowser's configuration.
|
2016-07-02 13:20:11 +02:00
|
|
|
- `QUTE_DATA_DIR`: Path of the directory containing qutebrowser's data.
|
|
|
|
- `QUTE_DOWNLOAD_DIR`: Path of the downloads directory.
|
2015-03-10 23:22:53 +01:00
|
|
|
|
|
|
|
In `command` mode:
|
|
|
|
|
|
|
|
- `QUTE_URL`: The current URL.
|
|
|
|
- `QUTE_TITLE`: The title of the current page.
|
|
|
|
- `QUTE_SELECTED_TEXT`: The text currently selected on the page.
|
2016-09-01 22:45:14 +02:00
|
|
|
- `QUTE_SELECTED_HTML` The HTML currently selected on the page (not supported
|
|
|
|
with QtWebEngine).
|
2015-03-10 23:22:53 +01:00
|
|
|
|
|
|
|
In `hints` mode:
|
|
|
|
|
|
|
|
- `QUTE_URL`: The URL selected via hints.
|
|
|
|
- `QUTE_SELECTED_TEXT`: The plain text of the element selected via hints.
|
|
|
|
- `QUTE_SELECTED_HTML` The HTML of the element selected via hints.
|
|
|
|
|
|
|
|
Sending commands
|
|
|
|
----------------
|
|
|
|
|
|
|
|
Normal qutebrowser commands can be written to `$QUTE_FIFO` and will be
|
|
|
|
executed.
|
|
|
|
|
|
|
|
On Unix/OS X, this is a named pipe and commands written to it will get executed
|
|
|
|
immediately.
|
|
|
|
|
|
|
|
On Windows, this is a regular file, and the commands in it will be executed as
|
|
|
|
soon as your userscript terminates. This means when writing multiple commands,
|
|
|
|
you should append to the file (`>>` in bash) rather than overwrite it (`>`).
|
|
|
|
|
|
|
|
Examples
|
|
|
|
--------
|
|
|
|
|
|
|
|
Opening the currently selected word on http://www.dict.cc/[dict.cc]:
|
|
|
|
|
|
|
|
[source,bash]
|
|
|
|
----
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
echo "open -t http://www.dict.cc/?s=$QUTE_SELECTED_TEXT" >> "$QUTE_FIFO"
|
|
|
|
----
|