clock_window 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/README.md +8 -2
- data/lib/clock_window/version.rb +1 -1
- data/lib/clock_window.rb +30 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1eeb75045c84292f96dc765b06173d5c43afe5e0
|
4
|
+
data.tar.gz: 908fd15c3d7c4beba0dfb4bf497e19147aa99612
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7bd7995f99f8d5aee5d81b5fb58fa8f1b0e129c53d1d4840a3f6638a3d13fbb777884765d45c55a1eef106c8bcff0001928dc28d30df258b7f94ef4f5e119fca
|
7
|
+
data.tar.gz: fbcdecdde1147191822d8c0d6ee9c40bd46e12c7cea0e03a70cf3707d66bc8e2eeae3f32626afee406739867b3c497a86690827f024c83a2ee720623f413e172
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
-
|
1
|
+
[](http://www.codetriage.com/danielpclark/clock_window)
|
2
|
+
|
3
|
+
# Clock Window
|
2
4
|
A minimalist script to keep track of how long each window is active. Measured in quarter minutes. Hash builds until you kill the script with CTRL-C at which point it writes out the log file. This script <del>adds no extra CPU load</del> will not raise the CPUs temperature indicating minimal CPU usage.
|
3
5
|
|
4
6
|
The output will look quite nice in any text editor aligned by the colon separator.
|
5
7
|
|
6
|
-
**Linux** compatible.
|
8
|
+
**Linux** & **Mac** compatible.
|
7
9
|
|
8
10
|
Output looks like:
|
9
11
|
```
|
@@ -24,6 +26,10 @@ gem install clock_window
|
|
24
26
|
|
25
27
|
To execute just run `clock_window` . If you put this script in your executable path then the **timelog.json** file should appear in whatever folder you run it from.
|
26
28
|
|
29
|
+
# Contributing
|
30
|
+
|
31
|
+
Feel free to contribute! We're looking for additional OS support by people who use different operating systems.
|
32
|
+
|
27
33
|
## The MIT License (MIT)
|
28
34
|
Copyright (c) 2016 Daniel P. Clark
|
29
35
|
|
data/lib/clock_window/version.rb
CHANGED
data/lib/clock_window.rb
CHANGED
@@ -17,7 +17,8 @@ module ClockWindow
|
|
17
17
|
# As this will get more sophisticated this class is the Back End
|
18
18
|
def initialize
|
19
19
|
# Detect operating system
|
20
|
-
@os =
|
20
|
+
@os = RbConfig::CONFIG['host_os']
|
21
|
+
@window_title_length = 0..60
|
21
22
|
end
|
22
23
|
|
23
24
|
# output will be a two parameter array
|
@@ -26,12 +27,37 @@ module ClockWindow
|
|
26
27
|
def active_window
|
27
28
|
# Choose script to execute and format output to just window name
|
28
29
|
case @os
|
29
|
-
when
|
30
|
+
when /linux/i
|
30
31
|
exe = "xprop -id $(xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2) _NET_WM_NAME"
|
31
|
-
format = ->str{ str.match(/.*\"(.*)\"\n\z/)[1][
|
32
|
+
format = ->str{ str.match(/.*\"(.*)\"\n\z/)[1][@window_title_length] }
|
33
|
+
[exe, format]
|
34
|
+
when /darwin/i
|
35
|
+
exe = <<-SCRIPT
|
36
|
+
osascript -e '
|
37
|
+
global frontApp, frontAppName, windowTitle
|
38
|
+
|
39
|
+
set windowTitle to ""
|
40
|
+
tell application "System Events"
|
41
|
+
set frontApp to first application process whose frontmost is true
|
42
|
+
set frontAppName to name of frontApp
|
43
|
+
tell process frontAppName
|
44
|
+
tell (1st window whose value of attribute "AXMain" is true)
|
45
|
+
set windowTitle to value of attribute "AXTitle"
|
46
|
+
end tell
|
47
|
+
end tell
|
48
|
+
end tell
|
49
|
+
|
50
|
+
return {frontAppName, windowTitle}
|
51
|
+
'
|
52
|
+
SCRIPT
|
53
|
+
|
54
|
+
format = ->str {
|
55
|
+
app, window = str.split(',')
|
56
|
+
"#{window.strip} - #{app.strip}"[@window_title_length]
|
57
|
+
}
|
32
58
|
[exe, format]
|
33
59
|
else
|
34
|
-
raise "Not implemented"
|
60
|
+
raise "Not implemented for #{@os}"
|
35
61
|
end
|
36
62
|
end
|
37
63
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clock_window
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel P. Clark
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: neatjson
|