Created
February 27, 2011 17:24
-
-
Save jplattel/846348 to your computer and use it in GitHub Desktop.
MacLogger script to print pretty signals without time to a file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess, os, sys | |
from varints import uvarintRead, uvarintsDecode | |
def main(): | |
signalName = sys.argv[1] | |
signal_repr = { | |
'mouse-pos': mouse_pos, | |
'input-idle': input_idle, | |
'front-window': front_window, | |
}[signalName] | |
signalDir = os.path.expanduser('~/Library/Application Support/MacLogger/signals/%s' % signalName) | |
path = '%s/%s' % (signalDir, list(sorted(os.listdir(signalDir)))[-1]) | |
#p = subprocess.Popen(['tail', '-n', '0', '-f', path], stdout=subprocess.PIPE) | |
#f = p.stdout | |
try: | |
f = open(path, 'rb') | |
print path | |
while True: | |
msDelta = uvarintRead(f) | |
dataLength = uvarintRead(f) | |
data = f.read(dataLength) | |
print '[t += %.4d]: %s' % (msDelta, signal_repr(data)) | |
msDeltaTime = '%.4d' % msDelta | |
try: | |
# This tries to open an existing file but creates a new file if necessary. | |
logfile = open("log2.txt", "a") | |
logfile.write(signal_repr(data) + '\n') | |
logfile.close() | |
except: | |
pass | |
except: | |
pass | |
def mouse_pos(data): | |
(x, y) = uvarintsDecode(data) | |
return '%d,%d' % (x, y) | |
def input_idle(data): | |
(value,) = uvarintsDecode(data) | |
return '%d' % value | |
def front_window(data): | |
return data | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment