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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 12bf40db265f8aaec9af53df99ab328c8a74511c
4
- data.tar.gz: 852aefabb459b7d483389f62e9580852123dbb90
3
+ metadata.gz: 1eeb75045c84292f96dc765b06173d5c43afe5e0
4
+ data.tar.gz: 908fd15c3d7c4beba0dfb4bf497e19147aa99612
5
5
  SHA512:
6
- metadata.gz: cf742a437542fdb6580cc9598b94f651aeb03f1c33172155b44356009211c23617ea480a18f6b305c574513cae25a27474d299eec55d8efaf3251445d75ea736
7
- data.tar.gz: a244c9686f7d9defabeb18ff02a6aae79fe94afd42e7a57c29f104f49b4aeb4ec0fac1fd961caf7ddd82f76f8a14a675177af92be23b44aba6032f2ecd85b45a
6
+ metadata.gz: 7bd7995f99f8d5aee5d81b5fb58fa8f1b0e129c53d1d4840a3f6638a3d13fbb777884765d45c55a1eef106c8bcff0001928dc28d30df258b7f94ef4f5e119fca
7
+ data.tar.gz: fbcdecdde1147191822d8c0d6ee9c40bd46e12c7cea0e03a70cf3707d66bc8e2eeae3f32626afee406739867b3c497a86690827f024c83a2ee720623f413e172
data/.gitignore CHANGED
@@ -7,3 +7,6 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ *.gem
11
+ **/*.swp
12
+ timelog.json
data/README.md CHANGED
@@ -1,9 +1,11 @@
1
- # Clock Window script
1
+ [![Code Triagers Badge](http://www.codetriage.com/danielpclark/clock_window/badges/users.svg)](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
 
@@ -1,3 +1,3 @@
1
1
  module ClockWindow
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
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 = "Linux"
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 "Linux"
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][0..60] }
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.3
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-06 00:00:00.000000000 Z
11
+ date: 2016-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: neatjson