I'm trying to run activitywatch on Ubuntu. I'm getting the folowing error:
code
┌─(~/Downloads/activitywatch-v0.13.2-linux-x86_64/activitywatch)──────────────────────────────────────────────────────────────────────────────────────────────(mbp@mbp-latitude:pts/0)─┐
└─(10:58:24)──> 2025-04-14 10:58:24 [ERROR]: Exception thrown while trying to get active window (aw_watcher_window.main:133) 130 ↵ ──(Mon,Apr14)─┘
Traceback (most recent call last):
File "aw_watcher_window/main.py", line 115, in heartbeat_loop
File "aw_watcher_window/lib.py", line 64, in get_current_window
File "aw_watcher_window/lib.py", line 8, in get_current_window_linux
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "PyInstaller/loader/pyimod02_importers.py", line 419, in exec_module
File "aw_watcher_window/xlib.py", line 13, in <module>
File "Xlib/display.py", line 89, in __init__
File "Xlib/display.py", line 71, in __init__
File "Xlib/protocol/display.py", line 166, in __init__
Xlib.error.DisplayConnectionError: Can't connect to display ":0": b'Authorization required, but no authorization protocol specified\n'
┌─(~/Downloads/activitywatch-v0.13.2-linux-x86_64/activitywatch)──────────────────────────────────────────────────────────────────────────────────────────────(mbp@mbp-latitude:pts/0)─┐
└─(10:58:25)──> 2025-04-14 10:58:25 [ERROR]: Exception thrown while trying to get active window (aw_watcher_window.main:133) 130 ↵ ──(Mon,Apr14)─┘
Traceback (most recent call last):
File "aw_watcher_window/main.py", line 115, in heartbeat_loop
File "aw_watcher_window/lib.py", line 64, in get_current_window
File "aw_watcher_window/lib.py", line 8, in get_current_window_linux
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "PyInstaller/loader/pyimod02_importers.py", line 419, in exec_module
File "aw_watcher_window/xlib.py", line 13, in <module>
File "Xlib/display.py", line 89, in __init__
File "Xlib/display.py", line 71, in __init__
File "Xlib/protocol/display.py", line 166, in __init__
Xlib.error.DisplayConnectionError: Can't connect to display ":0": b'Authorization required, but no authorization protocol specified\n'
┌─(~/Downloads/activitywatch-v0.13.2-linux-x86_64/activitywatch)──────────────────────────────────────────────────────────────────────────────────────────────(mbp@mbp-latitude:pts/0)─┐
└─(10:58:26)──> 2025-04-14 10:58:26 [ERROR]: Exception thrown while trying to get active window (aw_watcher_window.main:133) 130 ↵ ──(Mon,Apr14)─┘
Traceback (most recent call last):
File "aw_watcher_window/main.py", line 115, in heartbeat_loop
File "aw_watcher_window/lib.py", line 64, in get_current_window
File "aw_watcher_window/lib.py", line 8, in get_current_window_linux
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "PyInstaller/loader/pyimod02_importers.py", line 419, in exec_module
File "aw_watcher_window/xlib.py", line 13, in <module>
File "Xlib/display.py", line 89, in __init__
File "Xlib/display.py", line 71, in __init__
File "Xlib/protocol/display.py", line 166, in __init__
Xlib.error.DisplayConnectionError: Can't connect to display ":0": b'Authorization required, but no authorization protocol specified\n'
2025-04-14 10:58:27 [ERROR]: Exception thrown while trying to get active window (aw_watcher_window.main:133)
Traceback (most recent call last):
File "aw_watcher_window/main.py", line 115, in heartbeat_loop
File "aw_watcher_window/lib.py", line 64, in get_current_window
File "aw_watcher_window/lib.py", line 8, in get_current_window_linux
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "PyInstaller/loader/pyimod02_importers.py", line 419, in exec_module
File "aw_watcher_window/xlib.py", line 13, in <module>
File "Xlib/display.py", line 89, in __init__
File "Xlib/display.py", line 71, in __init__
File "Xlib/protocol/display.py", line 166, in __init__
Xlib.error.DisplayConnectionError: Can't connect to display ":0": b'Authorization required, but no authorization protocol specified\n'
I wonder whether it should be run in some kind of isolated environment like pipx
Assistant
Fixing ActivityWatch X11 Authorization Error on Ubuntu
The error you're encountering is related to X11 authorization permissions. ActivityWatch's window watcher component needs permission to access your display to track which windows are active.
Solution to the Authorization Error
The error "Authorization required, but no authorization protocol specified" indicates that the application doesn't have permission to connect to your X server. To fix this issue, run the following command in your terminal:
bash
xhost +si:localuser:$USER
This command grants your user account permission to connect to the X display server, which ActivityWatch needs to monitor active windows. For a temporary, less secure but quick solution, you could use xhost +, but the above command is more secure as it only allows your user to access the display.
Understanding ActivityWatch
ActivityWatch is an open-source application that automatically tracks how you spend time on your devices. It can:
Monitor your activity to analyze screen time
Provide a summary of daily activity with applications/programs
Offer different timeline visualizations
Track browser usage with browser extensions
Track time spent away from keyboard (AFK time)
Track coding time in editors
Store activity history for productivity analysis
Allow classification of time spent for detailed analysis
One important feature is that all data is stored locally on your device, respecting your privacy.
Proper Installation of ActivityWatch on Ubuntu
While pipx could be an option, ActivityWatch is typically installed and run as follows:
Download the ZIP file from the official ActivityWatch website
Extract the compressed file to a suitable location
Run the binary by double-clicking the aw-qt application or via terminal
For a more permanent setup, you can:
Move the downloaded files to /opt directory
Create a link to the aw-qt executable in the /usr/share/bin directory
Add it to your startup applications for automatic launch at login
To access the ActivityWatch interface, you can either:
Use the icon in the system tray
Access it through your web browser using the URL localhost:5600
Setting Up ActivityWatch for Regular Use
If you plan to use ActivityWatch regularly, add it to your startup applications:
Go to "Startup Applications" in your system settings
Add the path to the aw-qt executable
Make sure to run the xhost +si:localuser:$USER command before starting ActivityWatch or add it to your startup script
If you continue having issues with the window watcher, you might need to address specific X11 configuration issues that can occur on some Linux desktop environments.
ActivityWatch is available for Linux, Windows, macOS, and Android, with browser extensions for Chrome and Firefox. It's a powerful tool for tracking your computer usage while maintaining your privacy.