Skip to content

Instantly share code, notes, and snippets.

View auroracramer's full-sized avatar

Aurora Cramer auroracramer

View GitHub Profile
@auroracramer
auroracramer / disable-keyboard
Last active September 6, 2022 13:32
Script for temporarily disabling keyboard from command line on Ubuntu 22.04
#!/usr/bin/env bash
if [[ -n "$1" ]]; then
TKB_TIMEOUT=$1
else
TKB_TIMEOUT=600 # 10 minutes
fi
# Prevent sudo from timing out
# https://serverfault.com/a/266463
@auroracramer
auroracramer / mute-on-headphone-unplug
Last active July 11, 2022 21:06
Startup script muting audio when you plug/unplug headphones so you don't blow out your eardrums
#!/bin/bash
acpi_listen | while IFS= read -r line; do
if [ "$line" = "jack/headphone HEADPHONE plug" ]
then
pactl -- set-sink-volume 0 20%
amixer -D pulse set Master mute
elif [ "$line" = "jack/headphone HEADPHONE unplug" ]
then
@auroracramer
auroracramer / pause-on-idle
Last active September 8, 2022 14:02
Startup script to pause audio if you're idle
#!/bin/bash
# Courtesy of https://superuser.com/a/638487
IDLE_TIME_MIN=15
IDLE_TIME_SEC=$((IDLE_TIME_MIN*60))
IDLE_TIME_MS=$((IDLE_TIME_SEC*1000))
sleep_time_ms=$IDLE_TIME_MS
triggered=false
@auroracramer
auroracramer / unstuck-keyboard
Created July 11, 2022 21:00
Companion cron job for https://gist.github.com/auroracramer/64fa76aa82da717a520a28ec25304a66 to re-enable keyboard when screen is locked so you don't have to restart your computer
#!/usr/bin/env bash
# Add to crontab via:
# (crontab -u $USER -l; echo "*/1 * * * * $HOME/.local/bin/unstuck-keyboard" ) | crontab -u $USER -
# Set up env vars so that gnome-screensaver-command works with cron. If these
# are not
@auroracramer
auroracramer / toggle-keyboard
Last active August 31, 2022 19:00
Utility for toggling keyboard. Created so I can write on my laptop keyboard when it's open. I'm using it as a GNOME launcher application for Ubuntu 18.04 that can be access with the mouse. UPDATE: Doesn't work on Ubuntu 22.04 since it uses the Wayland window manager :(
#!/usr/bin/env bash
KEYBOARD_INFO=$(xinput list | sed -e 's/ */ /g' | grep "AT Translated Set 2 keyboard")
EXTRAKEY_INFO=$(xinput list | sed -e 's/ */ /g' | grep "ThinkPad Extra Buttons")
KEYBOARD_ID=$(echo $KEYBOARD_INFO | grep -o -P 'id=\K\d*')
EXTRAKEY_ID=$(echo $EXTRAKEY_INFO | grep -o -P 'id=\K\d*')
MASTER_ID=$(xinput list | sed -e 's/ */ /g' | grep -o -P 'slave keyboard \(\K\d*' | head -n 1)
IS_ATTACHED=$([ -z "$(echo $KEYBOARD_INFO | grep -o -P 'floating slave')" ])
if [ -z "$(echo $KEYBOARD_INFO | grep -o -P 'floating slave')" ]; then
xinput float $KEYBOARD_ID
@auroracramer
auroracramer / check-audio-playing
Last active August 31, 2022 13:03
Simple crontab script for making sure you're using your headphones and listening to music while working. Developed for Ubuntu 18.04 and 22.04, but should work for any Linux distro that uses GNOME
#!/usr/bin/env bash
# Add to crontab via:
# (crontab -u $USER -l; echo "*/1 * * * 1-5 $HOME/.local/bin/check-sound-playing" ) | crontab -u $USER -
# Set up env vars so that gnome-screensaver-command works with cron. If these
# are not set, the scree