Last active
August 31, 2016 19:20
-
-
Save juniorbird/368240a5493ebd22b0c1b5319d49f3b3 to your computer and use it in GitHub Desktop.
Simple applescript day planner
This file contains 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
############## | |
# Time-related tasks | |
set plannerMonth to (month of (current date) as text) | |
set plannerDay to (day of (current date) as text) | |
set plannerYear to (year of (current date) as text) | |
################ | |
# Set up our file paths | |
# Base paths | |
set home to get POSIX path of (get path to current user folder) as string | |
set plannerPath to POSIX path of (home & "planner/") | |
# Question lists | |
set plannerQuestionsAM to open for access (home & ".planner-am") without write permission | |
set plannerQuestionsPM to open for access (home & ".planner-pm") without write permission | |
# Output file | |
set plannerDir to POSIX path of (plannerPath & plannerYear & "/" & plannerMonth & "/") | |
set plannerFile to POSIX path of (plannerDir & plannerDay & ".txt") | |
#################### | |
# Build our template | |
set theDate to plannerMonth & " " & ¬ | |
plannerDay & ", " & ¬ | |
plannerYear & linefeed | |
set lenDate to length of theDate | |
repeat lenDate times | |
set theDate to theDate & "=" -- underline the day at the top | |
end repeat | |
########################### | |
# Which questions? | |
# If the file already exists, we're doing wrap-up | |
# Else, we're starting fresh | |
try | |
# does it exist? | |
do shell script "cat " & (quoted form of plannerFile) -- will fail if the file does not exist | |
# It does! | |
set plannerQuestions to plannerQuestionsPM | |
set plannerTitle to "Daily Wrap-Up" | |
try | |
do shell script "open " & plannerFile -- display the file for thinkin' about | |
end try | |
set plannerFileHandle to open for access plannerFile with write permission | |
set plannerWriteOffset to (get eof of plannerFileHandle) -- we plan to write the wrap-up to the end of the file | |
set plannerOutput to linefeed & linefeed | |
on error errMsg | |
# It does not! (Bug-ish: assumes you're doing AM and PM on the same machine) | |
set plannerQuestions to plannerQuestionsAM | |
set plannerTitle to "Daily Planning" | |
try | |
do shell script "cd ~ && git clone https://github.com/juniorbird/my-daily-plans.git planner" -- automatically restore backed up if exists | |
on error | |
do shell script "cd ~/planner && git pull" | |
end try | |
do shell script "mkdir -p " & (quoted form of plannerDir) -- we have to create the place to save the file, -p will create whatever needed parts of the path | |
set plannerFileHandle to open for access plannerFile with write permission | |
set plannerWriteOffset to 0 -- write starting at the beginning | |
set plannerOutput to theDate | |
end try | |
#################### | |
# Now read our file and ask questions | |
set plannerQuestions to read plannerQuestions using delimiter linefeed | |
repeat with planner in plannerQuestions | |
if length of planner is greater than 0 then | |
set thisPlanner to linefeed & linefeed & linefeed & planner & linefeed | |
repeat length of planner times | |
set thisPlanner to thisPlanner & "-" -- underline the question | |
end repeat | |
display dialog ¬ | |
planner with title ¬ | |
plannerTitle default answer linefeed & linefeed & linefeed & linefeed | |
set thisResult to text returned of result as text | |
set thisPlanner to thisPlanner & linefeed & thisResult | |
set plannerOutput to plannerOutput & thisPlanner | |
end if | |
end repeat | |
# We've done it! Write the file! | |
write plannerOutput to plannerFileHandle starting at plannerWriteOffset | |
close access plannerFileHandle | |
# Git is our file storage and backup | |
do shell script "cd ~/planner && git add . && git commit -am '" & theDate & "' && git push" | |
# Be nice and show the user their work | |
try | |
tell application "TextEdit" | |
close (every window whose name is (plannerDay & ".txt")) | |
delay 1 | |
do shell script "open " & plannerFile | |
end tell | |
end try |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment