Skip to content

Instantly share code, notes, and snippets.

@dnicolson
dnicolson / switchbot.js
Created February 9, 2020 15:11
Script to a control a SwitchBot device without depending on gatttool
const noble = require('@abandonware/noble');
const address = '';
const uuidPrimary = 'cba20d00224d11e69fb80002a5d5c51b';
const uuidWrite = 'cba20002224d11e69fb80002a5d5c51b';
noble.on('stateChange', state => {
if (state === 'poweredOn') {
noble.startScanning([uuidPrimary], false);
} else {
@dnicolson
dnicolson / toggle-lightbulb.sh
Created January 18, 2020 16:30
Control a HomeKit lightbulb from the Touch Bar with this Quick Action (requires getting the pairing keys from the Keychain)
PYTHON=/Users/dave/.asdf/shims/python3
STATUS=`$PYTHON -m homekit.get_characteristic -f ~/.homekit_python/pairing.json -a iHaper -c 1.13`
if [[ "$STATUS" =~ "true" ]]; then
$PYTHON -m homekit.put_characteristic -f ~/.homekit_python/pairing.json -a iHaper -c 1.13 false
else
$PYTHON -m homekit.put_characteristic -f ~/.homekit_python/pairing.json -a iHaper -c 1.13 true
fi
@dnicolson
dnicolson / MediaRemoteEvents.m
Created December 24, 2019 18:16
Use the MediaRemote private framework to get and set the playing state of the Touch Bar based on media change events
// clang -x objective-c -framework Foundation -framework MediaRemote -F /System/Library/PrivateFrameworks TouchBarMediaKeys.m -o TouchBarMediaKeys
// ./TouchBarMediaKeys
#import <Foundation/Foundation.h>
#import <MediaPlayer/MediaPlayer.h>
enum {
kMRPlaybackStateUnknown = 0,
kMRPlaybackStatePlaying,
kMRPlaybackStatePaused,
@dnicolson
dnicolson / mediaremote.m
Created December 24, 2019 17:55
MediaRemote.framework method signatures
enum {
kMRPlaybackStateUnknown = 0,
kMRPlaybackStatePlaying,
kMRPlaybackStatePaused,
kMRPlaybackStateStopped,
kMRPlaybackStateInterrupted
};
typedef uint32_t MRPlaybackState;
typedef void (^MRMediaRemoteGetNowPlayingPlayerCompletion)(id playbackPlayer);
@dnicolson
dnicolson / get_uuid.c
Created December 14, 2019 22:58
Get the volume UUID (DAVolumeUUID)
// clang -framework DiskArbitration -framework Carbon disk.c -o disk
#include <Carbon/Carbon.h>
void printUUID()
{
DADiskRef disk;
CFDictionaryRef descDict;
DASessionRef session = DASessionCreate(NULL);
@dnicolson
dnicolson / fetch-videos.js
Created July 29, 2019 17:34
Aggregate videos from multiple channels in the last hours
const fetchVideos = (channels, apiKey, lastHours) => {
return Promise.all(
channels.map(channel => {
const url = `https://www.googleapis.com/youtube/v3/search?key=${apiKey}&channelId=${channel}&part=snippet,id&order=date&maxResults=20`;
return fetch(url)
.then(response => response.json())
.then(json => {
return json.items
.filter(item => item.id.kind === 'youtube#video')
@dnicolson
dnicolson / pixelsnap2.rb
Created May 22, 2019 09:44
This cask installs PixelSnap 2 from a disk image in the current directory
require 'uri'
cask "pixelsnap2" do
version "2.0"
sha256 "04e2d1892593d904f3d528c70b5fc4ec773c957b2d3bdd0e8a8876045ff458c8"
url "file://#{URI::encode(File.expand_path(File.dirname(ARGV[1] ? ARGV[1] : '')))}/PixelSnap-2-2.0.dmg"
name "PixelSnap 2"
homepage "https://getpixelsnap.com/"
app "PixelSnap 2.app"
@dnicolson
dnicolson / airbuddy.rb
Last active July 3, 2019 20:17
This cask installs AirBuddy from a zip file in the current directory
require 'uri'
cask 'airbuddy' do
version '1.0.4'
sha256 '793c396ecdf242a7b90433efa790c11b84209b6a9d621d5c1a68d201654b20cc'
url "file://#{URI.encode(File.expand_path(File.dirname(ARGV[1] || '')))}/S3KtOo0aHZ_AirBuddy_v1.0.4_18.zip"
name 'AirBuddy'
homepage 'https://gumroad.com/l/airbuddy'
@dnicolson
dnicolson / setlist-music.js
Last active July 2, 2019 18:20
Takes a setlist.fm setlist ID and creates a playlist in iTunes based on the setlist
#!/usr/bin/env node
/* global Application */
/* eslint-disable no-console */
const fetch = require('node-fetch');
const osa = require('osa2');
require('array-flat-polyfill');
const API_KEY = 'd1be89b2-08b8-4b93-9ebd-eeca6544bdbd';
@dnicolson
dnicolson / youtube.sh
Last active February 24, 2019 23:26
After generating a new provisioning profile, this will re-sign and deploy the old YouTube app to an Apple TV
#!/bin/bash
# npm install -g applesign ios-deploy
APPLE_TV=xxx
YOUTUBE_IPA="YouTube 1.2.1.ipa"
provision() {
cd ~/Library/MobileDevice/Provisioning\ Profiles