Skip to content

Instantly share code, notes, and snippets.

View nriley's full-sized avatar

Nicholas Riley nriley

View GitHub Profile
@nriley
nriley / init.lua
Last active March 6, 2024 17:02
Hammerspoon script for ensuring Sidecar is active when iPad is plugged in (macOS 10.15; see comments for versions up to macOS 13)
hs.loadSpoon('SpoonInstall')
spoon.SpoonInstall.use_syncinstall = true
Install = spoon.SpoonInstall
log = hs.logger.new('init', 5)
-- function debugUI(msg, table)
-- log:d(msg)
-- log:d(hs.inspect(table))
-- end
@nriley
nriley / Fix broken Finder windows.applescript
Created January 26, 2020 19:55
Fix Catalina Finder windows that sprout unwanted toolbars
-- Fix Catalina Finder windows that sprout unwanted toolbars
-- Takes advantage of the property that these windows cannot have their toolbars hidden through AppleScript
-- Nicholas Riley <[email protected]>
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
tell application "Finder"
set _windows to Finder windows
repeat with _window in _windows
@nriley
nriley / get_lutron_cert.sh
Created October 14, 2017 15:55 — forked from mhofman/get_lutron_cert.sh
Generate a signed certificate valid to connect locally to a Lutron Caseta Smart Bridge
#!/bin/bash
# Usage: get_lutron_cert.sh [bridge_ip] | tee cert.pem
function error() {
echo "Error: $1" >&2
exit 1
}
login_server="device-login.lutron.com"
@nriley
nriley / README.md
Last active April 1, 2017 14:55
Fake switching with homebridge-websocket

Update

The below continues to work, but homebridge-http-webhooks is much easier to set up and use as it only requires a HTTP request. With this package, you configure individual switches from config.json.

    "platforms": [
[...]
        {
            "platform": "HttpWebHooks",
 "webhook_port": 4051,
@nriley
nriley / archive-application.sh
Last active March 3, 2018 16:28
Script to archive a macOS application.
#!/bin/zsh -ef
set -x
app="$1"
# https://stackoverflow.com/a/1665662/6372
space_version=$(/usr/local/bin/launch -f "$1" |
sed -e 's/^ version: \(.*\) \[.*/ \1/; t' \
-e 's/^ version: \(.*\)/ \1/; t' \
@nriley
nriley / Move to Top.applescript
Created April 25, 2016 12:25
Move tasks to the top of their containing task or project in OmniFocus
tell application "OmniFocus"
tell default document's first document window's content
set _tasks to (selected trees where its value's class is task)'s value
set _tasks to _tasks's reverse
repeat with _task in _tasks
tell _task's parent task
move _task to beginning of tasks
end tell
end repeat
end tell
@nriley
nriley / ts.zsh
Created February 6, 2016 17:11
Timestamp your command output with zsh
ts() {
local tspty=tspty.$(/usr/bin/uuidgen)
zmodload zsh/zpty
zpty $tspty $@
setopt localtraps
TRAPINT() { zpty -d $tspty }
while zpty -r $tspty line; do
print -Pn '%B%D{%m/%d %H:%M:%S}%b '
print -n -- $line
done
local _outlinePath, _htmlPath, _htmlFolder, _outlineName, _itemsToCommit
tell application "OmniOutliner Professional"
tell front document
save
set _outlineName to name
set _outlinePath to path
end tell
set _htmlPath to ((characters 1 thru ((count characters of _outlinePath) - 4) of _outlinePath) as string) & ".html"
set _htmlFolder to (_htmlPath as POSIX file)
@nriley
nriley / better-buff-menu.el
Created August 22, 2015 16:48
better buffer switching - a bit like electric-buffer-list, but with fit-to-buffer and window management that makes more sense to me
(global-set-key (kbd "C-x C-b")
(lambda ()
(interactive)
(let ((buffer-list-window (list-buffers)))
(fit-window-to-buffer buffer-list-window)
(select-window buffer-list-window)
(setq tabulated-list-sort-key '("File"))
(tabulated-list-init-header)
; don't try to preserve selection, because...
(tabulated-list-print nil)
@nriley
nriley / Save to Date.scpt
Last active August 29, 2015 13:56
Save to Date
on replace_chars(this_text, search_string, replacement_string)
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
return this_text
end replace_chars
on dlog(foo)