Skip to content

Instantly share code, notes, and snippets.

View stephancasas's full-sized avatar

Stephan Casas stephancasas

View GitHub Profile
@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 / 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 / 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 / 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 / set-macos-user-accent-color.jxa.js
Last active December 3, 2024 10:27
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 / 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 / swiftui-blur-textfield.swift
Last active October 28, 2024 23:35
SwiftUI focus-losing/first responder-losing (blur) text field
import SwiftUI
@main
struct ExampleApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
@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 / CustomMenuBarExtraCornerMask.swift
Last active April 28, 2025 12:59
A SwiftUI MenuBarExtra window with custom corners
//
// MenuBarTestApp.swift
// MenuBarTest
//
// Created by Stephan Casas on 7/7/23.
//
import SwiftUI
@main
@stephancasas
stephancasas / CGEventSupervisor.swift
Last active January 10, 2025 21:28
A service class for monitoring global keyboard events in macOS Swift applications.
//
// CGEventSupervisor.swift
// Mouseless Messenger Pro
//
// Created by Stephan Casas on 4/24/23.
//
import Cocoa;
class CGEventSupervisor {