Skip to content

Instantly share code, notes, and snippets.

View danielbayley's full-sized avatar
👨‍💻
Working on too many things…

Daniel Bayley danielbayley

👨‍💻
Working on too many things…
View GitHub Profile
@danielbayley
danielbayley / seticon.swift
Created February 25, 2023 15:27
Set icon for file or folder from image, existing app or folder.
#! /usr/bin/xcrun swift
import Cocoa
let args = CommandLine.arguments[1...]
let (target, icon) = (URL(fileURLWithPath: args.first!).path, args[2])
var folder: ObjCBool = false
FileManager.default.fileExists(atPath: icon, isDirectory: &folder)
let image: NSImage = folder.boolValue
@n8henrie
n8henrie / OpenTerminalToFinderWindow.js
Last active August 10, 2023 17:39
JXA to open a Terminal window to the frontmost Finder window
#!/usr/bin/osascript -l JavaScript
'use strict';
const DEBUG = false;
(function () {
const terminal = Application("Terminal")
// A few seconds to focus the appropriate Finder window
url scheme:
x-apple.systempreferences:com.apple.KEY[.KEY]?SUB-PANE
examples:
x-apple.systempreferences:com.apple.systempreferences.AppleIDSettings?iCloud
x-apple.systempreferences:com.apple.preference.keyboard?Shortcuts
urls:
com.apple.systempreferences.ApplelDSettings
@raven
raven / fetch-xcode.sh
Created September 23, 2022 12:24
Download Xcode without Apple ID
# Fetch ADCDownloadAuth cookie
curl --cookie-jar cookie_file 'https://developerservices2.apple.com/services/download?path=%2FDeveloper_Tools%2FXcode_14%2FXcode_14.xip'
# Download Xcode using fetched ADCDownloadAuth cookie
curl --cookie cookie_file --remote-name 'https://download.developer.apple.com/Developer_Tools/Xcode_14/Xcode_14.xip'
@monkeydom
monkeydom / ks_changeset.sh
Created May 3, 2022 08:13
Script to put 2 folders into a single changeset git and diff it using ksdiff to see the changeset nicely
#!/bin/sh
# ks_changeset v0.9 - 2022-05-03
# Enable "safe" mode - see http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -euo pipefail
IFS=$'\n\t'
if [[ $# -lt 3 ]]; then
echo "Usage: ks_changeset.sh <FolderA> <FolderB> <DestinationGit>"
@mattmc3
mattmc3 / optparsing_demo.zsh
Last active April 5, 2024 21:22
Zsh option parsing example
# Manual opt parsing example
#
# Features:
# - supports short and long flags (ie: -v|--verbose)
# - supports short and long key/value options (ie: -f <file> | --filename <file>)
# - supports short and long key/value options with equals assignment (ie: -f=<file> | --filename=<file>)
# - does NOT support short option chaining (ie: -vh)
# - everything after -- is positional even if it looks like an option (ie: -f)
# - once we hit an arg that isn't an option flag, everything after that is considered positional
function optparsing_demo() {
getJsonValue() {
# $1: JSON string to process, $2: Desired JSON key
osascript -l 'JavaScript' -e "JSON.parse(\`$1\`).$2;"
}
# String sent by a rogue API endpoint
json='{}`);const app = Application.currentApplication(); app.includeStandardAdditions = true;app.displayAlert("👾🔥🙈");JSON.parse(`{}';
fullName=$(getJsonValue "$json" name)
@atelierbram
atelierbram / create-a-persistent-directory-stack-in-zsh.md
Last active October 31, 2023 16:58
Create a persistent directory stack in zsh
import Cocoa
import MediaPlayer
let bundle = CFBundleCreate(kCFAllocatorDefault, NSURL(fileURLWithPath: "/System/Library/PrivateFrameworks/MediaRemote.framework"))
let MRMediaRemoteRegisterForNowPlayingNotificationsPointer = CFBundleGetFunctionPointerForName(
bundle, "MRMediaRemoteRegisterForNowPlayingNotifications" as CFString
)
typealias MRMediaRemoteRegisterForNowPlayingNotificationsFunction = @convention(c) (DispatchQueue) -> Void
let MRMediaRemoteRegisterForNowPlayingNotifications = unsafeBitCast(MRMediaRemoteRegisterForNowPlayingNotificationsPointer, to: MRMediaRemoteRegisterForNowPlayingNotificationsFunction.self)