question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Creating a new watcher

See original GitHub issue

I would like to watch one integer variable from my window-manager (XY context : the virtual desktop I am in, as they are a good classification of the activities I do on the computer + makes it trivial to label current activity, by just moving to the corresponding space).

What would be a bare-bones watcher ?

Only has to run on linux. I can have the watched-thing run a shell command (messaging the watcher) every time its value changes, so it doesn’t even have to continuously listen (though if it must listen, it can watch the /tmp/current-value file, easy).

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:25 (23 by maintainers)

github_iconTop GitHub Comments

3reactions
nikanarcommented, Sep 12, 2018

@rhabbachi Not that I can remember. I think it boils down to the following

will@ker:~$ cat .../AW/aw-wmtag.py

#!/usr/bin/python3

import subprocess
import time, datetime
from aw_client import ActivityWatchClient
from aw_core.models import Event

def main():
    client = ActivityWatchClient("aw-wmtag")
    bucket_id = "{}_{}".format(client.name, client.hostname)  # Give your bucket a unique id.
    event_type = "activedesktop"  # Used to annotate what kind of data the events in a given bucket will contain.
    client.create_bucket(bucket_id, event_type)

    poll_time = 5  # Send an event every 5 seconds
    with client:
        while True:
            data = {"desktop": get_the_watched_thing()}
            now = datetime.datetime.now(datetime.timezone.utc)
            awesome_event = Event(timestamp=now, data=data)
            client.heartbeat(bucket_id, awesome_event, pulsetime=poll_time+1, queued=True)
            time.sleep(poll_time)
        
def get_the_watched_thing():
    filename = "/path/to/awesome-logging.log"
    f = subprocess.Popen(['tail','-c','2',filename],
                         stdout=subprocess.PIPE,stderr=subprocess.PIPE)
    value = int(f.stdout.read(1))
    # print("Looking at {} says desktop is currently {}".format(filename, value))
    return value
    
if __name__ == "__main__":
    main()

… given that the window manager (awesome-wm) writes in /path/to/awesome-logging.log, with the following (excerpt from ~/.config/awesome/rc.lua):

local function log_current_tag()
   local i = awful.screen.focused().selected_tag.index
   file = io.open("/path/to/awesome-logging.log", "a")
   file:write(string.format("%s Switching to awesome tag %i\n", os.date("%Y/%m/%d %X"), i))
   file:close()
end

and then calling that function whenever I change tags (by whatever keybinding or clicking sequence) = user input changes the observed value - e.g.

   awful.key({modkey},	"Tab", function () awful.tag.viewnext() log_current_tag() end),

There, now it’s done 😂

1reaction
ErikBjarecommented, Nov 24, 2017

@nikanar Awesome! Great to see you got it working 😄

Huge thanks for helping us make the process a bit less cumbersome for people in the future. I updated the doc to mention the PIP_USER trick as you suggested.

Closing this for now, but don’t hesitate to let us know how things turn out 🚀

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting started with Watcher | Elasticsearch Guide [8.5] | Elastic
Getting started with Watcheredit · Schedule the watch and define an input. · Add a condition that checks to see if an alert...
Read more >
How to add Watchers or Request Participants during issue ...
First, you'll need a custom field for the process to work properly. You can follow our documentation on creating a new custom field...
Read more >
Create a File Watcher: /Documentation - LabKey Support
File Watchers let administrators set up the monitoring of directories on the file system and perform specific actions when desired files appear. This...
Read more >
Create an Azure Network Watcher instance - Microsoft Learn
Create a Network Watcher in the portal · Log into the Azure portal with an account that has the necessary permissions. · Select...
Read more >
Automatically add Watchers to Newly Created Issues
I can use this script to automatically add that user as a watcher on all new issues created. Good to Know This script...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found