Skip to content

Instantly share code, notes, and snippets.

View stephancasas's full-sized avatar

Stephan Casas stephancasas

View GitHub Profile
@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 / CGWindowDictionary.swift
Last active December 4, 2023 00:45
A convenience type for working with the CFDictionary values returned by CGWindowListCopyWindowInfo(_:, _:)
//
// CGWindowDictionary.swift
//
// Created by Stephan Casas on 11/2/23.
//
import Foundation;
import CoreGraphics;
import AppKit;
@stephancasas
stephancasas / CIFilter+Knockout.swift
Created November 28, 2023 16:37
Color cube-style CoreImage filter enabling real-time alpha knock-out of solid colors.
//
// CIFilter+Knockout.swift
//
//
// Created by Stephan Casas on 10/13/23.
//
import Foundation
import CoreImage;
@stephancasas
stephancasas / CGCoordinateSpaces.swift
Created November 8, 2023 05:40
Extensions and utilities for working with CGPoint and CGRect across AppKit and CoreGraphics coordinate spaces.
//
// CGCoordinateSpaces.swift
//
// Created by Stephan Casas on 11/7/23.
//
import Foundation;
// MARK: - CGPoint
@stephancasas
stephancasas / open-messages-emoji-palette.jxa.js
Created October 26, 2023 15:00
Open the macOS Messages emoji palette.
#!/usr/bin/env osascript -l JavaScript
let _AXError;
const $attr = Ref();
const $windows = Ref();
const $children = Ref();
const kAXParentAttribute = 'AXParent';
const kAXChildrenAttribute = 'AXChildren';
@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 / merge-pdf-documents.jxa.js
Created August 9, 2023 00:37
Post-Ventura working AppleScript to merge multiple PDF documents
#!/usr/bin/env osascript -l JavaScript
function run(argv) {
const outputPath = `${$.NSHomeDirectory().js}/Downloads/output.pdf`;
const outputURL = $.NSURL.fileURLWithPath(outputPath);
const docPaths = [
'/path/to/some/document.pdf',
'/path/to/other/document.pdf',
];
@stephancasas
stephancasas / CGEventSupervisor.swift
Last active November 28, 2023 17:12
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 {
@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
@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;