Figured out how to merge duplicate buckets (Mac)

I’ve been having an issue where AW keeps making new hostnames. I wanted to merge the buckets all into one, but the available documentation out there was unhelpful. I figured out a process that worked for me to merge buckets and fix my hostname, but it took me forever to piece it together because I’m an utter noob, so here’s a step by step. I do not know if it will work for you, I just hope that this saves someone at least some time.

The Problem
I had AW already installed and working. However, I kept seeing new hostnames in the upper left of the UI. I don’t know why this happens, apparently it’s a known bug.
hostnames
I wanted to merge these into one because it was really annoying having to open three different buckets to see what I was doing.

Changing Hostname
This will (I think) permanently set the hostname so it stops making new hostnames.

  1. Open a Terminal window.
  2. sudo scutil --set HostName {YOUR HOSTNAME}
    1. This changes your computer’s hostname (replace {YOUR HOSTNAME} with whatever hostname you want). I just changed it to [my name’s]-Macbook-Air. This caused some issues down the line because I had to merge all of the other buckets into that hostname. If you don’t change it to one of the pre-existing bucket titles, I recommend restarting AW or your computer, because it looks like AW doesn’t initialize all of the buckets unless it’s restarted. Maybe. I could be wrong.
  3. Go change the hostnames of other watchers to your desired hostname.
    1. For me, this meant opening the AW extension for Firefox and changing the name. (I then had to restart AW to see the bucket show up in the web UI.) I don’t know how to change other watchers’ hostnames, sorry.

Merging Buckets
This uses a pre-existing script in AW to merge the existing buckets. I’m assuming you have python, pip, and git installed.

  1. Go to http://localhost:5600/#/buckets.
  2. Scroll to the bottom and click “Export all buckets as JSON” in the bottom right.
    1. This makes a backup of your current buckets in case something goes wrong.
  3. Open a Terminal window.
    1. Optional: Make a folder somewhere in Finder to hold the AW installation. I just made a folder called “AW” in Documents. If you do this, the first command you enter into the shell is cd {PATH TO YOUR FOLDER}. An easy way to find the path to the folder is to go to its parent (in my case Documents), right click on the folder, and press and hold Option. Then click on the “Copy ‘AW’ as Pathname” (the ‘AW’ will be whatever you named your folder). You can then type in cd and press Cmd+V to paste in the pathname you just copied.
    2. I know that this might be duplicative of ActivityWatch.app in Applications, it’s just that none of the below commands worked when I tried to use that folder.
  4. git clone https://github.com/ActivityWatch/activitywatch.git
    1. This clones the ActivityWatch code into your folder.
  5. git submodule update --init --recursive
    1. When you clone the code, all of the subfolders are empty. This clones all the code of the subfolders.
  6. python3 -m venv venv
    1. AW needs to run in a virtual environment. This creates that virtual environment.
  7. source venv/bin/activate
    1. This activates the virtual environment.
  8. pip install ./aw-client
    1. This installs aw-client, which is a dependency for the python script we’re using later on.
  9. cd ./aw-client/examples
    1. Changes directory into the folder with the python script.
  10. Open the activitywatch/aw-client/examples folder in Finder and open merge_buckets.py in a text editor. Look for this line: aw = aw_client.ActivityWatchClient(testing=True). Change that line so it says this, and then save the change:
  11. aw = aw_client.ActivityWatchClient(testing=True, host="127.0.0.1", port=5600)
    1. I don’t know why this works, but when I tried to run the code as-is it kept giving me “connection refused” errors.
  12. Go back to Terminal. Run this:
  13. python3 merge_buckets.py
    1. For me, I had to use python3. Using just python threw a ModuleNotFound error. I think my Python is misconfigured, but whatever.
  14. It’ll show your buckets and ask for the source bucket ID and the destination bucket ID. The source is the bucket that you’re copying from, and the destination is the bucket you’re copying to. I am pretty sure you’re supposed to only merge buckets of the same type with each other (like don’t merge an aw-watcher-afk and an aw-watcher-window).
  15. Run python3 merge_buckets.py as many times as you need to merge all of your buckets together. You can press the up arrow on your keyboard to repeat the same command you just did.

Again, I don’t know what I’m doing, so I’m sorry if this does something unexpected. It’s just what worked for me. If something disastrous happens, go back to the Raw Data page on the web UI, scroll to the bottom, and import your backup file you downloaded earlier.

1 Like

Thanks for sharing. So many people will find this helpful.