Skip to content

Commit

Permalink
Merge pull request #4 from amitjslearn/patch-1
Browse files Browse the repository at this point in the history
added a littile description
  • Loading branch information
KalleHallden authored Aug 27, 2019
2 parents f5d8fb3 + ae949a9 commit 4cfdd90
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Tracking the desktop applications in real time and time spent on each application.

Check out this for more https://youtu.be/ZBLYcvPl1MA

Dependencies:

- selenium
- selenium
71 changes: 71 additions & 0 deletions linux.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
'''
This file gives the linux support for this repo
'''
import sys
import os
import subprocess
import re


def get_active_window_raw():
'''
returns the details about the window not just the title
'''
root = subprocess.Popen(
['xprop', '-root', '_NET_ACTIVE_WINDOW'], stdout=subprocess.PIPE)
stdout, stderr = root.communicate()

m = re.search(b'^_NET_ACTIVE_WINDOW.* ([\w]+)$', stdout)
if m != None:
window_id = m.group(1)
window = subprocess.Popen(
['xprop', '-id', window_id, 'WM_NAME'], stdout=subprocess.PIPE)
stdout, stderr = window.communicate()
else:
return None

match = re.match(b"WM_NAME\(\w+\) = (?P<name>.+)$", stdout)
if match != None:
ret = match.group("name").strip(b'"')
#print(type(ret))
'''
ret is str for python2
ret is bytes for python3 (- gives error while calling in other file)
be careful
'''
return ret
return None

'''
this file alone can be run without importing other files
uncomment the below lines for linux - works - but activities won't be dumped in json file
(may be it works for other OS also, not sure)
'''
# def run():
# new_window = None
# current_window = get_active_window_title()
# while(True):
# if new_window != current_window:
# print(current_window)
# print(type(current_window))
# current_window = new_window
# new_window = get_active_window_title()


# run()
def get_chrome_url_x():
'''
instead of url the name of the website and the title of the page is returned seperated by '/'
'''
detail_full = get_active_window_raw()
detail_list = detail_full.split(' - ')
detail_list.pop()
detail_list = detail_list[::-1]
_active_window_name = 'Google Chrome -> ' + " / ".join(detail_list)
return _active_window_name

def get_active_window_x():
full_detail = get_active_window_raw()
detail_list = None if None else full_detail.split(" - ")
new_window_name = detail_list[-1]
return new_window_name

0 comments on commit 4cfdd90

Please sign in to comment.