Last active
August 5, 2021 13:35
-
-
Save j4mie/382e490b31c4a39a4cba3b66341fb954 to your computer and use it in GitHub Desktop.
Plugin for xbarapp.com to display total time spent using your computer today
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
#!/usr/bin/env bash | |
# This query adds up the lengths of all the /app/usage events in ZOBJECT. | |
# This gives an approximation of how long the machine has been used for today, assuming | |
# the display goes to sleep fairly quickly when the machine is not used (eg 1 minute). | |
# You'll need to give xbar "Full Disk Access" | |
# (System Preferences -> Security and Privacy -> Privacy) for this to work. | |
DBPATH=~/Library/Application\ Support/Knowledge/knowledgeC.db | |
SQL=$(cat <<EOF | |
select | |
sum(ZENDDATE - ZSTARTDATE) as total | |
from | |
ZOBJECT | |
where | |
ZSTREAMNAME = '/app/usage' | |
and date( | |
ZCREATIONDATE + 978307200, | |
'UNIXEPOCH' | |
) = date() | |
EOF | |
) | |
seconds=$(echo ${SQL} | sqlite3 "${DBPATH}") | |
printf '%dh%dm\n' $((seconds/3600)) $((seconds%3600/60)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment