Skip to content

Instantly share code, notes, and snippets.

@czottmann
Created July 15, 2009 06:55
Show Gist options
  • Save czottmann/147548 to your computer and use it in GitHub Desktop.
Save czottmann/147548 to your computer and use it in GitHub Desktop.
-- http://bbs.applescript.net/viewtopic.php?id=22890
on formatDate(theFormat, theDate)
-- Example for `theDate`: "2007-10-23T17:54:23"
try
do shell script "/usr/local/bin/ruby -e 'require \"parsedate\"; puts Time.local(*ParseDate.parsedate(ARGV[1])).strftime(ARGV[0])' " & ¬
quoted form of theFormat & " " & quoted form of theDate
on error
-- The date could not be parsed
return false
end try
end formatDate
display dialog "Log minutes to RescueTime" default answer ¬
"5" buttons {"Reading", "Phone", "Cancel"} ¬
default button 1
copy the result as list to {text_returned, button_pressed}
if (button_pressed is not "Cancel") then
set text_returned to text_returned as number
set hostname to (do shell script "hostname | cut -d '.' -f1")
set whoami to (do shell script "whoami")
set os_username to (hostname & "\\" & whoami) as Unicode text
set app_name to ("MANUAL_" & button_pressed) as Unicode text
set window_title to button_pressed as Unicode text
set time_start to formatDate("%Y-%m-%d %H:%M:%S", ¬
((current date) - text_returned * 60) as «class isot» as string) as Unicode text
set time_end to formatDate("%Y-%m-%d %H:%M:%S", ¬
(current date) as «class isot» as string) as Unicode text
set theFilename to ("~/Library/RescueTime/Logs/Pending/rt_" & ¬
formatDate("%Y%m%d-%H%M%S", (time_end) as string) & ¬
".yml") as Unicode text
do shell script "echo \"--- \" >" & theFilename
do shell script "echo \"- os_username: " & os_username & "\" >>" & theFilename
do shell script "echo \" app_name: " & app_name & "\" >>" & theFilename
do shell script "echo \" window_title: '" & window_title & "'\" >>" & theFilename
do shell script "echo \" start_time: " & time_start & "\" >>" & theFilename
do shell script "echo \" end_time: " & time_end & "\" >>" & theFilename
end if
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment