Skip to content

Instantly share code, notes, and snippets.

@jacaetevha
Forked from ammojamo/track.sh
Last active March 3, 2016 01:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jacaetevha/6bf3f03fbc8df8cd37b2 to your computer and use it in GitHub Desktop.
Save jacaetevha/6bf3f03fbc8df8cd37b2 to your computer and use it in GitHub Desktop.
#!/bin/sh
input=
while true
do
input="$(/usr/bin/osascript 2>/dev/null <<-__HEREDOC__
with timeout of 300 seconds
tell application "System Events"
activate
set notes to display dialog "What ya been up to?" \
with title "Oi!" \
with icon note \
default answer "$input" & return & return & return & return \
buttons {"Cancel", "OK"} \
default button 2 \
giving up after 295
set the_result to the result
set gave_up to gave up of the_result
if gave_up is true then
return "Away"
end if
keystroke "h" using command down
return text returned of notes as string
end tell
end timeout
__HEREDOC__
)"
# replace CR with LF
input=$(echo $input | tr '\r' '\n')
# trim whitespace
input=$(expr "$input" : '[[:space:]]*\(.*[^[:space:]]\)[[:space:]]*$')
echo "$(date "+%Y-%m-%d,%H:%M:%S"),\"$input\"" >> ~/time-log-$(date "+%Y-%m-%d").txt
sleep 1800
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment