Skip to content

Instantly share code, notes, and snippets.

@Songmu
Last active December 14, 2015 15:39
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Songmu/5109279 to your computer and use it in GitHub Desktop.
Save Songmu/5109279 to your computer and use it in GitHub Desktop.
S.on('appActivated', function (event, app) {
S.log('appActivated:' + app.name());
});
<source>
type forward
port 24224
</source>
<match keylogger>
type copy
<store>
type datacounter
#unit minute
count_interval 1m
count_key app
tag keycounter
aggregate all
# patternX: X(1-9)
pattern1 Terminal ^Terminal$
pattern2 MacVim ^MacVim$
pattern3 LimeChat ^LimeChat$
pattern4 Slack ^Slack$
pattern5 GoogleChrome ^Google\s*Chrome$
</store>
<store>
type stdout
</store>
</match>
<match keycounter>
type copy
<store>
type growthforecast
gfapi_url http://localhost:5127/api/
service key
section count
tag_for ignore
name_keys Terminal_count,MacVim_count,LimeChat_count,Slack_count,GoogleChrome_count
</store>
<store>
type mackerel
service songmu
api_key xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
metrics_name keylogger.${out_key}
out_keys Terminal_count,MacVim_count,LimeChat_count,Slack_count,GoogleChrome_count
</store>
<store>
type stdout
</store>
</match>
<match **>
type stdout
</match>
#!/usr/bin/env perl
use 5.014;
use warnings;
#use utf8;
use autodie;
$| = 1;
my $current_app = 'Terminal';
while (my $line = <>) {
if (my ($app) = $line =~ /Slate\[.*appActivated:(.*)/) {
if ($app =~ /ターミナル/) {
$app = 'Terminal';
}
else {
$app =~ s/[^a-zA-Z0-9 ]//g;
}
$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;
}
}
1;
#!/bin/sh
tail -F /var/log/system.log | perl $HOME/service/keylogger/keylogger.pl | fluent-cat keylogger
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment