Skip to content

Commit

Permalink
Dim when not working plus misc other
Browse files Browse the repository at this point in the history
  • Loading branch information
robotdana committed Nov 16, 2023
1 parent 4ac80ac commit 27ef476
Show file tree
Hide file tree
Showing 10 changed files with 209 additions and 16 deletions.
23 changes: 23 additions & 0 deletions LaunchAgents/sh.dana.dim_when_not_working.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>$PATH</string>
</dict>
<key>Label</key>
<string>sh.dana.dim_when_not_working</string>
<key>ProgramArguments</key>
<array><string>$HOME/.dotfiles/scripts/dim_when_not_working.applescript</string></array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardErrorPath</key>
<string>/tmp/sh.dana.dim_when_not_working.err</string>
<key>StandardOutPath</key>
<string>/tmp/sh.dana.dim_when_not_working.out</string>
</dict>
</plist>
23 changes: 23 additions & 0 deletions LaunchAgents/sh.dana.dont_sit_in_silence.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>$PATH</string>
</dict>
<key>Label</key>
<string>sh.dana.dont_sit_in_silence</string>
<key>ProgramArguments</key>
<array><string>$HOME/.dotfiles/scripts/dont_sit_in_silence.sh</string></array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardErrorPath</key>
<string>/tmp/sh.dana.dont_sit_in_silence.err</string>
<key>StandardOutPath</key>
<string>/tmp/sh.dana.dont_sit_in_silence.out</string>
</dict>
</plist>
3 changes: 2 additions & 1 deletion bash_profile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ set +H

export PYENV_SHELL=bash
export PATH="$HOME/.cargo/bin:/Users/dana/.pyenv/shims:/usr/local/heroku/bin:/usr/local/bin:/usr/local/sbin:/usr/local/lib/node:$PATH"
export EDITOR='/usr/local/bin/code --wait'
export EDITOR='code --wait'
export GUI_EDITOR=$EDITOR
export THOR_MERGE=$EDITOR' -d $1 $2'
export GPG_TTY=$(tty)
export BASH_SILENCE_DEPRECATION_WARNING=1
if [[ -f /opt/homebrew/bin/brew ]]; then
Expand Down
1 change: 1 addition & 0 deletions bundle_config
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ BUNDLE_BUILD__MYSQL2: "--with-opt-dir=/usr/local/opt/[email protected]"
BUNDLE_GEM__CI: "github"
BUNDLE_GEM__CHANGELOG: "true"
BUNDLE_GEM__LINTER: "rubocop"
BUNDLE_BUILD__PUMA: "--with-pkg-config=/opt/homebrew/opt/[email protected]/lib/pkgconfig"
13 changes: 6 additions & 7 deletions gitconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
excludesfile = ~/.gitignore
mergeoptions = --no-edit
hooksPath = ~/.dotfiles/hooks
editor = mate --wait
[help]
autocorrect = -1
[push]
Expand Down Expand Up @@ -57,12 +56,12 @@
diff = diffr | less

[core]
editor = code --wait
editor = code --wait
[diff]
tool = vscode
[difftool "vscode"]
cmd = code --wait --diff $LOCAL $REMOTE
tool = vscode
[merge]
tool = vscode
tool = vscode
[mergetool "vscode"]
cmd = code --wait $MERGED
cmd = code --wait --merge $REMOTE $LOCAL $BASE $MERGED
[difftool "vscode"]
cmd = code --wait --diff $LOCAL $REMOTE
108 changes: 108 additions & 0 deletions scripts/dim_when_not_working.applescript
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#!/usr/bin/osascript

-- reading calendar is from:
-- https://www.macscripter.net/t/faster-way-to-find-a-calendar-event/69257/5
-- Setting greyscale is from:
-- https://stackoverflow.com/questions/75152094/applescript-ventura-toggle-accessibility-grayscale-on-off

use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "EventKit"

set listOfCalNames to {} -- list of one or more calendar names

--gain access to Event Kit.
set theEKEventStore to create_event_store_access()

--if no access is allowed to Event Kit, then exit script
if theEKEventStore is false then return

-- get calendars that can store events
set theCalendars to theEKEventStore's calendarsForEntityType:0

repeat
checkGreyscale(listOfCalNames, theCalendars, theEKEventStore)
delay 1
end repeat

on checkGreyscale(listOfCalNames, theCalendars, theEKEventStore)
-- prepare times
set nowDate to current application's NSDate's |date|()

-- filter the find to events in the calendar named "Home"
set theNSPredicate to current application's NSPredicate's predicateWithFormat_("title IN %@", listOfCalNames)
set calsToSearch to theCalendars's filteredArrayUsingPredicate:theNSPredicate

-- find matching events
set thePred to theEKEventStore's predicateForEventsWithStartDate:nowDate endDate:nowDate calendars:calsToSearch
set theEvents to (theEKEventStore's eventsMatchingPredicate:thePred)

-- sort by date
set theEvents to (theEvents's sortedArrayUsingSelector:("compareStartDateWithEvent:" as list))
-- read isGreyScale
set isGreyScale to do shell script "defaults read com.apple.universalaccess grayscale -bool"
set prohibitedEmoji to ((character id 128683) as Unicode text)
set currentlyProhibited to false
-- log prohibitedString
repeat with index from 1 to length of (theEvents as list)
set theCurrentEvent to item index of (theEvents as list)
-- Process the current event itemexit repeat
set theCurrentEventTitle to (theCurrentEvent's title as Unicode text)
-- log theCurrentEventTitle
if theCurrentEventTitle contains prohibitedEmoji then
-- log "currentlyProhibited"
set currentlyProhibited to true
if isGreyScale is equal to "0" then
toggleGreyscale()
end if
exit repeat
end if
end repeat

if not currentlyProhibited then
if isGreyScale is equal to "1" then
toggleGreyscale()
end if
-- log "Not currently prohibited"
end if
end checkGreyscale

on toggleGreyscale()
-- log "toggling greyscale"
current application's NSWorkspace's sharedWorkspace()'s openURL:(current application's NSURL's URLWithString:"x-apple.systempreferences:com.apple.preference.universalaccess?Seeing_Display")
tell application "System Events" to tell application process "System Settings"
repeat until exists window "Display"
end repeat
set colourFiltersGroup to group 4 of scroll area 1 of group 1 of group 2 of splitter group 1 of group 1 of window "Display"
set filterTypePopup to pop up button 1 of colourFiltersGroup
click filterTypePopup
click menu item 1 of menu 1 of filterTypePopup
click checkbox 1 of colourFiltersGroup
end tell
if application "System Settings" is running then
tell application "System Settings" to quit
end if
end toggleGreyscale

--sub routine to gain access to Event Kit
on create_event_store_access()

-- create event store and get the OK to access Calendars
set theEKEventStore to current application's EKEventStore's alloc()'s init()
theEKEventStore's requestAccessToEntityType:0 completion:(missing value)

-- check if app has access; this will still occur the first time you OK authorization
set authorizationStatus to current application's EKEventStore's authorizationStatusForEntityType:0 -- work around enum bug
if authorizationStatus is not 3 then
display dialog "Access must be given in System Preferences" & linefeed & "-> Security & Privacy first." buttons {"OK"} default button 1
tell application "System Settings"
activate
tell pane id "com.apple.preference.security" to reveal anchor "Privacy"
end tell
error number -128
false
else
theEKEventStore
end if
end create_event_store_access
14 changes: 6 additions & 8 deletions scripts/dont_sit_in_silence.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/env bash
#!/bin/bash

set -e

# whenever you find yourself sitting in silence after a zoom meeting or etc
# it will give a notification you can click to play whatever was last playing in spotify
Expand All @@ -11,19 +13,15 @@ fi
function alert_if_no_audio {
# from https://apple.stackexchange.com/questions/363416/how-to-check-if-any-audio-is-currently-playing-via-terminal
if [[ "$(pmset -g | grep -F ' sleep')" == *"coreaudiod"* ]]; then
echo "Audio is playing"
# alerter -remove ALL -sender com.spotify.client
else
echo "Audio is not playing"

# from: https://github.com/vjeantet/alerter
case "$(alerter -title "Silence Detector" \
-message "You are sitting in silence" \
-sender com.spotify.client \
-activate com.spotify.client \
-actions Play \
-remove "Silence Detector" \
-timeout 5 \
-group "Silence Detector")" in
-group "sh.dana.dont_sit_in_silence")" in
"@TIMEOUT"|"@CLOSED");;
# from: https://stackoverflow.com/questions/8901556/controlling-spotify-with-applescript
"@CONTENTCLICKED"|"@ACTIONCLICKED"|"Play") osascript -e "tell application \"Spotify\"
Expand All @@ -34,7 +32,7 @@ function alert_if_no_audio {


fi
sleep 60
sleep 10
alert_if_no_audio
}

Expand Down
9 changes: 9 additions & 0 deletions scripts/install_launchagents.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

launchagents=(~/.dotfiles/LaunchAgents/*)

for agent in "${launchagents[@]##*/}"; do
cat ~/.dotfiles/LaunchAgents/$agent | sed s^'$HOME'^$HOME^g | sed s^'$PATH'^$PATH^g > ~/Library/LaunchAgents/$agent
echo launchctl unload "~/Library/LaunchAgents/$agent"
echo launchctl load "~/Library/LaunchAgents/$agent"
done
2 changes: 2 additions & 0 deletions scripts/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,6 @@ if [[ -z "$CI" ]]; then
ruby-install ruby 3.0
fi

install_launchagents.sh

resource
29 changes: 29 additions & 0 deletions scripts/watch_prefs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash

set -euo pipefail

domains=($(defaults domains))

before=$(mktemp -d)
for domain in ${domains[@]//,}; do
set +e
defaults read $domain >"$before/$domain" 2>/dev/null
set -e
done

echo "Change preference, then hit enter"

read enter

after=$(mktemp -d)

for domain in ${domains[@]//,}; do
set +e
defaults read $domain >"$after/$domain" 2>/dev/null
set -e
done

echo "The diff between defaults entries is:"

diff -r "$before" "$after"

0 comments on commit 27ef476

Please sign in to comment.