Skip to content

Instantly share code, notes, and snippets.

View stephancasas's full-sized avatar

Stephan Casas stephancasas

View GitHub Profile
@stephancasas
stephancasas / ColorFloodExample.swift
Created June 28, 2023 15:51
Use Swift to flood/fill a PNG-format image with color
//
// ColorFloodExample.swift
// ColorFloodExample
//
// Created by Stephan Casas on 6/28/23.
//
import SwiftUI;
import Accelerate;
import CoreGraphics;
@stephancasas
stephancasas / swiftui-blur-textfield.swift
Last active June 25, 2023 15:29
SwiftUI focus-losing/first responder-losing (blur) text field
import SwiftUI
@main
struct ExampleApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
@stephancasas
stephancasas / SwiftUI_NSAlertExampleApp.swift
Last active June 20, 2023 14:10
Customizable NSAlert with suppression checkbox in SwiftUI
//
// SwiftUI_NSAlertExampleApp.swift
// SwiftUI_NSAlertExample
//
// Created by Stephan Casas on 6/20/23.
//
// This example requires the [NSViewProxy](https://github.com/stephancasas/NSViewProxy)
// package to acquire the pre-draw window context in `ContentView`.
//
@stephancasas
stephancasas / set-macos-user-accent-color.jxa.js
Last active October 26, 2023 05:54
Set macOS user accent color
#!/usr/bin/env osascript -l JavaScript
function run(argv) {
ObjC.bindFunction('NSColorGetUserAccentColor', ['int', []]);
ObjC.bindFunction('NSColorSetUserAccentColor', ['bool', ['int']]);
console.log($.NSColorGetUserAccentColor());
console.log($.NSColorSetUserAccentColor(4));
return 0;
@stephancasas
stephancasas / add-root-trust-ios.jxa.js
Created June 4, 2023 06:02
Add root trust to Xcode iOS Simulator
#!/usr/bin/env osascript -l JavaScript
const CERT_PATH = '/tmp/sim-cert-install.pem';
// NOTE: This is intended to be used as an Alfred Workflow.
// If you don't have Alfred, just replace the value of
// `argv` with the URL for the site whose root trust
// needs to be added.
function run([argv = '']) {
@stephancasas
stephancasas / last-finder-location.jxa.js
Created May 23, 2023 11:19
AppleScript: Open last Finder location
#!/usr/bin/env osascript -l JavaScript
const App = Application.currentApplication();
App.includeStandardAdditions = true;
function run(_) {
const finderPrefs = $.NSMutableDictionary.dictionaryWithContentsOfFile(
`${$.NSHomeDirectory().js}/Library/Preferences/com.apple.finder.plist`,
);
@stephancasas
stephancasas / main.m
Created May 23, 2023 01:06
Convert literal escaped unicode character to NSString.
//
// main.m
// EscapedUnicodeCharConvertExample
//
// Created by Stephan Casas on 5/22/23.
//
#import <Foundation/Foundation.h>
NSString* escapedUnicharToString(NSString* escapedUnicharString) {
@stephancasas
stephancasas / format-selected-text-to-unicode-monospace.jxa.js
Created May 22, 2023 22:01
AppleScript: Format selected text using unicode monospace glyph equivalents.
#!/usr/bin/env osascript -l JavaScript
const $attr = Ref();
const $windows = Ref();
const $children = Ref();
const UNICODE_PATTERN = '11110xxx10xxxxxx10xxxxxx10xxxxxx';
function run(_) {
const app = $.AXUIElementCreateApplication(
@stephancasas
stephancasas / toggle-do-not-disturb-ventura.jxa.js
Last active May 19, 2023 20:31
Toggle Do Not Disturb Ventura AppleScript
#!/usr/bin/env osascript -l JavaScript
/**
* -----------------------------------------------------------------------------
* Toggle Do Not Disturb Mode from Control Center
* -----------------------------------------------------------------------------
*
* Created on May 18, 2023 by Stephan Casas
*
* Options:
@stephancasas
stephancasas / new-untitled-textmate.jxa.js
Created May 18, 2023 16:58
Create New Untitled TextMate Document from AppleScript
#!/usr/bin/env osascript -l JavaScript
const $attr = Ref();
const $windows = Ref();
const $children = Ref();
function run(_) {
// Get TextMate AXUIElement
const textmatePid =
$.NSRunningApplication.runningApplicationsWithBundleIdentifier(