Amazing script from Matt Reed, to prompt me to log my time.
Last active
December 26, 2015 21:58
-
-
Save simonwheatley/7219258 to your computer and use it in GitHub Desktop.
Amazing script from Matt Reed, to prompt me to log my time.
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
Simon Log.app |
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
on run | |
end run | |
on idle | |
activate | |
update_file() | |
return 1800 | |
end idle | |
on update_file() | |
display dialog "What have you been doing?" default answer "" | |
set this_data to text returned of result & space & "[" & (year of (current date)) & (month of (current date) as integer) & (day of (current date)) & space & getTimeInHoursAndMinutes() & "]" & return | |
set this_file to (((path to home folder) as string) & "Dropbox:simon-log.txt") | |
my write_to_file(this_data, this_file, true) | |
end update_file | |
on write_to_file(this_data, target_file, append_data) | |
try | |
set the target_file to the target_file as string | |
set the open_target_file to open for access file target_file with write permission | |
if append_data is false then set eof of the open_target_file to 0 | |
write this_data to the open_target_file starting at eof | |
close access the open_target_file | |
return true | |
on error | |
try | |
close access file target_file | |
end try | |
return false | |
end try | |
end write_to_file | |
on getTimeInHoursAndMinutes() | |
-- Get the "hour" | |
set timeStr to time string of (current date) | |
set Pos to offset of ":" in timeStr | |
set theHour to characters 1 thru (Pos - 1) of timeStr as string | |
set timeStr to characters (Pos + 1) through end of timeStr as string | |
-- Get the "minute" | |
set Pos to offset of ":" in timeStr | |
set theMin to characters 1 thru (Pos - 1) of timeStr as string | |
set timeStr to characters (Pos + 1) through end of timeStr as string | |
--Get "AM or PM" | |
set Pos to offset of " " in timeStr | |
set theSfx to characters (Pos + 1) through end of timeStr as string | |
return (theHour & ":" & theMin & " " & theSfx) as string | |
end getTimeInHoursAndMinutes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment