Skip to content

Instantly share code, notes, and snippets.

@philsnow
philsnow / _summary.md
Last active June 18, 2024 02:46
simple app-agnostic window switcher in hammerspoon

What

This is just a simple switcher that lets you cycle through recently-used windows on the current workspace, regardless of what app they are from.

It uses Hammerspoon. It's set to bind to option-tab so that I can still use the native/default cmd-tab switcher.

@philsnow
philsnow / _summary.md
Created June 1, 2024 06:41
MacOS plist oddity

Disclaimer/preface: I don't know all that much about MacOS.

Why are my MacOS backups so large?

I was investigating why my Time Machine (and later, borgbackup'ed tmutil localsnapshots) incremental backups were larger than I expected -- around 1-7 GB worth of changes per day.

I found this out after I had set up Time Machine backups to a TrueNAS CORE machine and had set up regular snapshots of the Time Machine ZFS dataset:

# zfs list -t snapshot -o space -r /mnt/vault/delorean/philsnow | head
@philsnow
philsnow / _readme.md
Created March 15, 2023 18:13
Switching spaces in Hammerspoon, without showing the Mission Control UI

Wherein I continue to try to recreate my long-loved but long-lost Linux window manager UX.

Switching spaces in Hammerspoon, without showing the Mission Control UI

The bits of MacOS that handle space naming and switching (Mission Control? Dock.app?) aren't publicly consumable / there isn't a public API for them. That sucks because it leads to workarounds, some of them harmful, like the (otherwise-fantasic) yabai needing SIP to be disabled for full functionality (it's in the very name, "yabai" means dangerous).

In Hammerspoon it works differently. For several of its operations, hs.spaces brings up the Mission Control UI and then scrapes its accessibility axuielements, then interacts with those. This works and I appreciate that I don't have to disable SIP... but it's slow and causes distracting stuff to briefly appear on the screen.

I miss how instantaneous switching workspaces is in XMonad, ion3, pretty much

@philsnow
philsnow / walkthrough.md
Last active June 27, 2024 19:18
Another way to manually add another site to Firefox Multi-Account Containers

Another way to manually add another site to Firefox Multi-Account Containers

Multi-Account Containers and Temporary Containers are great extensions for a great browser. I get really frustrated when I can't make them work together the way I want, though.

The most common problem I have is when some site redirects through a bunch of subdomains (usually during login). Because of Temporary Containers, each redirect opens in a new tab+container which doesn't bring cookies from the other container, and the login flow breaks.

If the resulting page leaves you on the subdomain that broke the flow, you can use the menu to add another "always open in container" rule, but if it didn't (because on error the site redirects you to the first subdomain or somewhere else), you can't use that menu. Some people have found workarounds that work for them (like [changing `networ

@philsnow
philsnow / _readme.md
Created February 8, 2023 10:32
simple_switcher.lua: simple mac window switcher with hammerspoon

simple_switcher.lua

I've been using numbered Spaces a lot more lately, and it's helpful for me to only see the apps/windows that I'm currently focused on, instead of all 30 apps I happen to have open. I wanted something similar to hs.window.switcher, but I don't care about window thumbnails and I wanted to be able to see more than just a few characters of the window title.

I cribbed heavily from the window_switcher.lua source but removed a lot of configurability, logging, backwards compatibility, and other good ideas.

Screencast/demo: (I have this new switcher bound to option+tab, and can still use the regular macos cmd-tab switcher)

@philsnow
philsnow / .DisableSlackAnimationsOnBattery.md
Last active June 30, 2022 07:24
disable slack animations on battery power

What is this?

Slack animations take a ton of CPU and thus battery. Wouldn't it be great if unplugging your laptop from its power source would automatically turn them off?

This is a bit of code for Hammerspoon that makes that happen.

AnimateSlack is just an Automator app that pulls my user token out of a keychain with security and curls a POST to api.slack.com, but if I were to do this again I'd just have Hammerspoon do it.

@philsnow
philsnow / _description.md
Created June 30, 2022 07:15
disable slack animations when on battery power

What is this?

Slack animations take a ton of CPU and thus battery. Wouldn't it be great if unplugging your laptop from its power source would automatically turn them off?

This is a bit of code for Hammerspoon that makes that happen.

AnimateSlack is just an Automator app that pulls my user token out of a keychain with security and curls a POST to some Slack API URL I forget the details of

@philsnow
philsnow / chrome_tabs.sh
Created January 28, 2021 19:14
some ways of getting tabs out of chrome/firefox because I don't trust their session restore 100%
# source this from your shell
chrome_tabs () {
for win in $(seq 1 $(osascript -e 'tell application "Chrome" to get count every window'))
do
for tab in $(seq 1 $(osascript -e "tell application \"Chrome\" to get count every tab of window ${win}"))
do
echo -n "win $win tab $tab: "
osascript -e "tell application \"Chrome\" to get URL of tab $tab of window $win"
done
done
@philsnow
philsnow / firefox_tabs_to_emacs.sh
Last active December 11, 2022 06:02
getting tabs out of firefox
#!/bin/bash
# brew install lz4 && \
# mkdir -p ~/dev && \
# cd ~/dev && \
# git clone https://github.com/lilydjwg/mozlz4-tool && \
# cd mozlz4-tool && \
# LIBRARY_PATH=/opt/homebrew/lib cargo build --release
~/dev/mozlz4-tool/target/release/mozlz4-tool "$(find ~/Library/Application\ Support/Firefox/Profiles/ -name recovery.jsonlz4 | head -1)" | jq '["* \(.windows | length) Firefox windows as of '$(date +%Y-%m-%dT%H:%M:%S)'", (.windows | . as $windows | length as $num_windows | keys | .[] | $windows[.] as $window | [" - window \(. + 1) out of \($num_windows), \($window.tabs | length) tabs", ($window.tabs[] | .entries[-1] as $last | " - [[\($last.url)][\($last.title)]]")])] | flatten | .[]' -r
@philsnow
philsnow / init.lua
Last active June 20, 2020 09:34
hammerspoon snippet that allows me to paste where I want
-- other stuff in hammerspoon init.lua
require("pasteboardtype")