Skip to content

Instantly share code, notes, and snippets.

View stephancasas's full-sized avatar

Stephan Casas stephancasas

View GitHub Profile
@stephancasas
stephancasas / AdvancedToolbarWindow.swift
Last active May 3, 2024 19:35
A SwiftUI-compatible window for macOS with advanced toolbar configurability.
//
// AdvancedToolbarWindow.swift
//
// Created by Stephan Casas on 3/17/23.
//
import SwiftUI;
import AppKit;
class AdvancedToolbarWindow<MainContent: View, ToolbarContent: View, TitleToolbarContent: View>: NSWindow, NSToolbarDelegate {
@stephancasas
stephancasas / sonoma-text-insertion-point-downgrade.jxa.js
Created October 7, 2023 02:58
Disable Sonoma Text Insertion Point ("Cursor" / "Caret")
#!/usr/bin/env osascript -l JavaScript
const App = Application.currentApplication();
App.includeStandardAdditions = true;
const kCFPrefsFeatureFlagsDir = '/Library/Preferences/FeatureFlags/Domain';
const kCFPrefsFeatureEnabledKey = 'Enabled';
const kUIKitDomainPrefsTemporaryPath = '/tmp/UIKit.plist';
const kUIKitRedesignedTextCursorKey = 'redesigned_text_cursor';
@stephancasas
stephancasas / NSApplication+openSettings.swift
Last active April 27, 2024 04:49
An extension enabling global access to settings scene of a macOS SwiftUI application.
//
// NSApplication+openSettings.swift
//
// Created by Stephan Casas on 12/3/23.
//
import SwiftUI;
fileprivate let kAppMenuInternalIdentifier = "app"
fileprivate let kSettingsLocalizedStringKey = "Settings\\U2026";
@stephancasas
stephancasas / MachVMReadWrite.swift
Last active April 25, 2024 17:18
Modern utility functions for Mach task read/write operations.
//
// MachVMReadWrite.swift
//
// Created by Stephan Casas on 4/25/24.
//
import Foundation;
/// Starting at the given address, read the byte values into the given buffer.
/// - Parameters:
@stephancasas
stephancasas / NSApplication+NSResponderDebug.swift
Created March 18, 2024 20:35
An extension on NSApplication providing a computed property that describes the current responder chain.
//
// NSApplication+NSResponderDebug.swift
//
// Created by Stephan Casas on 3/18/24.
//
import Cocoa;
extension NSApplication {
@stephancasas
stephancasas / NSViewReader.swift
Last active April 14, 2024 16:19
A SwiftUI view that can reliably access outer or inner instances of SwiftUI-managed NSView objects.
//
// NSViewReader.swift
//
// Created by Stephan Casas on 4/11/24.
//
import SwiftUI;
import AppKit;
import Combine;
@stephancasas
stephancasas / DumbHTTPServer.swift
Created March 29, 2024 16:28
A low-level HTTP server offering a SwiftUI-observable lifecycle.
//
// DumbHTTPServer.swift
// DumbHTTPServer
//
// Created by Stephan Casas on 3/29/24.
//
import SwiftUI;
import Combine;
@stephancasas
stephancasas / NSManagedObject+DynamicBindings.swift
Created March 31, 2024 21:07
Syntactically-clean and portable SwiftUI bindings for optional properties on CoreData entities.
//
// NSManagedObject+DynamicBindings.swift
//
// Created by Stephan Casas on 3/31/24.
//
import SwiftUI;
import CoreData;
protocol DynamicBindings: NSManagedObject { }
@stephancasas
stephancasas / CGEventSupervisor+Convenience.swift
Created March 18, 2024 18:46
A convenience extension for CGEventSupervisor which offers built-in discriminator types for keyboard events.
//
// CGEventSupervisor+Convenience.swift
//
// @see: https://github.com/stephancasas/CGEventSupervisor
//
// @note: This is provided as an extension because it is poorly-structured as a result of
// backward-compatibility consideration. There are several ways it can be improved.
//
// Created by Stephan Casas on 3/18/24.
//
@stephancasas
stephancasas / CustomMenuBarExtraCornerMask.swift
Last active March 17, 2024 23:57
A SwiftUI MenuBarExtra window with custom corners
//
// MenuBarTestApp.swift
// MenuBarTest
//
// Created by Stephan Casas on 7/7/23.
//
import SwiftUI
@main