Last active
September 20, 2021 10:56
-
-
Save stuart-warren/48769b7fc934002116e41833e27f4bf2 to your computer and use it in GitHub Desktop.
log pomodoro task and turn on do-not-disturb (mac os)
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
#!/bin/bash | |
# xbar script https://github.com/matryer/xbar | |
# put in "${HOME}/Library/Application Support/xbar/plugins" | |
${HOME}/bin/start-pomodoro --countdown |
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
#!/bin/bash | |
# put in "${HOME}/bin" | |
# macos: brew install coreutils | |
export PATH="${PATH}:/usr/local/bin" | |
POMODORO_MINS="25" | |
TASKDIR="${HOME}/.pomodoro" | |
TASKSLOG="${TASKDIR}/tasks" | |
mkdir -p "${TASKDIR}" | |
notify() { | |
local title="$1" | |
local body="$2" | |
osascript -e "display notification \"${body}\" with title \"${title}\"" | |
} | |
endofpomodoro() { | |
local task="${@}" | |
setDoNotDisturb false | |
notify "end of pomodoro" "${task}\ntake a 5m break!" | |
} | |
log() { | |
local task="${@}" | |
echo "ts=\"$(gdate -u --rfc-3339=seconds)\" task=\"${task}\"" >>${TASKSLOG} | |
} | |
setDoNotDisturb() { | |
local bool="${@}" | |
defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturbDate -date "$(gdate -u +'%Y-%m-%dT%H:%M:%SZ')" | |
defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturb -boolean ${bool} | |
killall NotificationCenter | |
} | |
closeApp() { | |
local app="${1}" | |
osascript -e "tell application \"${app}\" to close every window" || true | |
} | |
closeTab() { | |
local url="${1}" | |
osascript -e "tell application \"Google Chrome\" | |
set windowList to every tab of every window whose URL starts with \"${url}\" | |
repeat with tabList in windowList | |
set tabList to tabList as any | |
repeat with tabItr in tabList | |
set tabItr to tabItr as any | |
delete tabItr | |
end repeat | |
end repeat | |
end tell" | true | |
} | |
countdown() { | |
task="$(head -n1 ${TASKDIR}/enddate)" | |
secs="$(($(tail -n1 ${TASKDIR}/enddate)-$(gdate -u +%s)))" | |
if [[ ${secs:0:1} == "-" ]]; then # check for negative | |
secs="0" | |
fi | |
mins="$(((${secs}%3600)/60))" | |
secs="$((${secs}%60))" | |
printf " %s - %02dm %02ds\n" "$task" "$mins" "$secs" | |
} | |
start() { | |
if [[ "$1" == "--countdown" ]]; then | |
countdown | |
exit 0 | |
fi | |
local task="${@}" | |
log "$task" | |
closeApp Slack | |
closeTab https://mail.google.com | |
setDoNotDisturb true | |
{ | |
echo "$task" >${TASKDIR}/enddate | |
gdate -d "+${POMODORO_MINS} minutes" -u +%s >>${TASKDIR}/enddate | |
sleep ${POMODORO_MINS}m && endofpomodoro "$task" | |
}& | |
} | |
start "${@}" |
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
# "run applescript" automator quick action | |
set task_details to text returned of (display dialog "What are you doing?" default answer "") | |
do shell script ("~/bin/start-pomodoro " & task_details) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment