A. 使えます
% cat ~/.slate.js
S.on('appActivated', function (event, app) {
S.log('appActivated:' + app.name());
});
/var/log/system.log にアプリ切り替えログが出る
Jan 21 23:23:41 songmu-mac Slate[14580]: appActivated:Slack
% sudo sysctl -w karabiner.debug=1
/var/log/system.log にキーダウンのログが出る
Jan 21 23:26:41 songmu-mac kernel[0]: org.pqrs.Karabiner --Debug-- KeyboardEventCallback [ caught]: eventType 10...
#!/usr/bin/env perl
use 5.020;
use warnings;
$| = 1;
while (my $line = <>) {
state $current_app = 'Terminal';
if (my ($app) = $line =~ /Slate\[.*appActivated:(.*)/) {
if ($app =~ /ターミナル/) {
$app = 'Terminal';
}
$current_app = $app; next;
}
my $press_key = quotemeta 'org.pqrs.Karabiner --Debug-- KeyboardEventCallback [ caught]: eventType 10';
if ($line =~ /$press_key/) {
printf qq[{"app": "%s"}\n], $current_app if $current_app;
}
}
#!/bin/sh
tail -F /var/log/system.log | ./keylogger.pl | fluent-cat keylogger
<source>
type forward
port 24224
</source>
<match keylogger>
type datacounter
count_interval 1m
count_key app
tag keycounter
aggregate all
pattern1 Terminal ^Terminal$
pattern2 MacVim ^MacVim$
pattern3 LimeChat ^LimeChat$
pattern4 Slack ^Slack$
pattern5 GoogleChrome ^Google\s*Chrome$
</match>
<match keycounter>
type mackerel
service songmu
api_key [YOU API KEY]
metrics_name keylogger.${out_key}
out_keys Terminal_count,MacVim_count,LimeChat_count,Slack_count,GoogleChrome_count
</match>