Skip to content

Instantly share code, notes, and snippets.

/*
An OSA script to replace disc numbers in album names with the disc number attribute.
Accepts album names in any of these formats:
LCD Soundsystem (Disc 1)
Mellon Collie and the Infinite Sadness (Disc 1: Dawn to Dusk)
The Wall: Live in Berlin (Disc 2) [Live]
require 'json'
require 'plist'
require 'tempfile'
require 'terminal-table'
class Hash
def without(*keys)
copy = self.dup
keys.each { |key| copy.delete(key) }
@dnicolson
dnicolson / incorrect-sentence-case.js
Last active February 18, 2018 18:48
JXA script to find songs with incorrect sentence case
const lowercaseWords = ['a', 'an', 'and', 'at', 'but', 'by', 'for', 'in', 'nor', 'of', 'on', 'or', 'so', 'the', 'to', 'with']
.map(word => ` ${word.toLowerCase().replace(/(^| )(\w)/g, s => s.toUpperCase())} `).join('|')
const iTunes = Application('iTunes'),
selection = iTunes.selection()
let songsToFix = []
selection.forEach((song) => {
const newName = song.name(),
newAlbum = song.album(),
@dnicolson
dnicolson / phoneview.rb
Last active July 3, 2019 20:17
If the PHONEVIEW_REGISTRATION_LINK environment variable is defined, this can be part of provisioning a new machine by using "brew cask install phoneview.rb"
cask 'phoneview' do
version :latest
sha256 :no_check
url do
customer_center = ENV['PHONEVIEW_REGISTRATION_LINK']
markup = `curl -L '#{customer_center}' 2>&1`
markup.scan(%r{href="([^"]+.dmg)"}).flatten.first
end
name 'PhoneView'
@dnicolson
dnicolson / itunes-add-songs.js
Last active November 10, 2018 17:39
JXA to add songs to a playlist based on an artist and list of songs
const ARTIST = ''
let TRACKS = []
const app = Application('iTunes')
const destinationPlaylist = app.userPlaylists.whose({name: {_equals: ARTIST}})[0]
TRACKS.forEach((name) => {
const matchedNames = app.playlists.whose({name: 'Library'})[0].tracks
.whose({name: {_equals: name}})
@dnicolson
dnicolson / dropbox-git.sh
Created November 4, 2018 16:35
Clone a bare git repo from Dropbox
curl -L https://www.dropbox.com/sh/xxx/yyy > project.git.zip
mkdir project.git
unzip project.git.zip -d project.git
git clone project.git
rm project.git.zip
rm -rf project.git
@dnicolson
dnicolson / pixelsnap.rb
Last active July 3, 2019 20:17
This cask installs PixelSnap from a disk image in the current directory
require 'uri'
cask 'pixelsnap' do
version '1.4.1'
sha256 '13831053af6c1774107619b9419253a3127e2b4eb02e52f8099108e260dcf1d7'
url "file://#{URI.encode(File.expand_path(File.dirname(ARGV[1] || '')))}/PixelSnap-1.4.1.dmg"
name 'PixelSnap'
homepage 'https://getpixelsnap.com/'
@dnicolson
dnicolson / github-commits.js
Created December 18, 2018 21:33
This reads the Link HTTP header and counts the pages of commits (the contributors and search API's do not give accurate commit counts).
const fetch = require('node-fetch');
const parse = require('parse-link-header');
async function githubCommits(owner, repository) {
const response = await fetch(`https://api.github.com/repos/${owner}/${repository}/commits`);
let link;
if (response.headers) {
for (let pair of response.headers.entries()) {
if (pair[0] === 'link') {
@dnicolson
dnicolson / iOSKeyboardEscapeKeyEnablerBluetooth.c
Created January 23, 2019 23:47
Support for the corner home button on an iOS keyboard to act as an escape key by analysing Bluetooth packets
// clang -framework Carbon iOSKeyboardEscapeKeyEnablerBluetooth.c -o iOSKeyboardEscapeKeyEnablerBluetooth
// sudo ./iOSKeyboardEscapeKeyEnablerBluetooth
#include <stdio.h>
#include <stdlib.h>
#include <Carbon/Carbon.h>
void TriggerEscKey()
{
CGEventRef event;
@dnicolson
dnicolson / weatherspect.rb
Last active December 17, 2019 00:11
A brew formula for weatherspect, the changes on line 99 fix an SSL issue but the weather parsing no longer works
class Weatherspect < Formula
desc "Virtual weather environment in ASCII"
homepage "http://robobunny.com/projects/weatherspect/html/"
url "http://robobunny.com/projects/weatherspect/weatherspect_v1.11.tar.gz"
sha256 "6186b41c7db8529eaf98864c2760837a2664cf107d1fa53620beef686c2dc1b8"
depends_on "openssl"
resource "Curses" do
url "https://cpan.metacpan.org/authors/id/G/GI/GIRAFFED/Curses-1.34.tar.gz"