Skip to content

Instantly share code, notes, and snippets.

View stormychel's full-sized avatar
🍏

Michel Storms stormychel

🍏
View GitHub Profile
@stormychel
stormychel / macOS_SytemPrefs.md
Created January 8, 2026 09:59 — forked from rmcdongit/macOS_SytemPrefs.md
Apple System Preferences URL Schemes

macOS 10.15 System Preference Panes

Below are a list of System Preference pane URLs and paths that can be accessed with scripting to assist users with enabling macOS security settings without having to walk them through launching System Preferences, finding panes, and scrolling to settings. Not all panes have an accessible anchor and some are OS specific.

To find the Pane ID of a specific pane, open the System Preferences app and select the desired Preference Pane. With the pane selected, open the ScriptEditor.app and run the following script to copy the current Pane ID to your clipboard and display any available anchors:

tell application "System Preferences"
	set CurrentPane to the id of the current pane
	set the clipboard to CurrentPane
@stormychel
stormychel / quartz-point.swift
Created November 9, 2025 08:49
Cocoa to Quartz point conversion
/// Converts a Cocoa global point (origin at lower-left) into Quartz display coordinates (origin at upper-left). - #763
static func quartzPoint(from cocoaPoint: CGPoint) -> CGPoint {
let screens = NSScreen.screens
// Find screen containing the point; fall back to main screen
let targetScreen = screens.first { NSMouseInRect(cocoaPoint, $0.frame, false) } ?? NSScreen.main
guard let screen = targetScreen else { return cocoaPoint }
// Translate into screen-local coordinates
let localY = cocoaPoint.y - screen.frame.origin.y
@stormychel
stormychel / pbcopy.ps1
Last active April 15, 2025 09:23
PowerShell pbcopy function for Windows (mimics macOS pbcopy)
<#
pbcopy.ps1 — A PowerShell function to mimic macOS `pbcopy`
📌 Usage:
"Hello world" | pbcopy
pbcopy # then type text, Ctrl+Z + Enter
📁 Install:
- Save this file somewhere on disk, e.g. C:\Scripts\pbcopy.ps1
- Open your PowerShell profile: notepad $PROFILE
@stormychel
stormychel / gist:91ddb46a529526150a7b2d2b41491815
Created September 23, 2024 03:02
Conditionally Display SwiftUI View Based on a Boolean
extension View {
/// Conditionally displays the view based on the provided Boolean condition.
///
/// This modifier allows you to show or hide a view depending on the value of `condition`.
/// If `condition` is `true`, the view is displayed as is.
/// If `condition` is `false`, the view is replaced by an `EmptyView`, which effectively removes it from the layout.
///
/// - Parameter condition: A Boolean value that determines whether the view should be displayed. If `true`, the view is shown; if `false`, it is hidden.
/// - Returns: Either the view itself, or an `EmptyView` if the condition is `false`.
///
@stormychel
stormychel / URLResponse+HTTP.swift
Created May 9, 2024 04:33 — forked from messeb/URLResponse+HTTP.swift
URLResponse as HTTPURLResponse and check if call has status code 2xx
extension URLResponse {
/// Returns casted `HTTPURLResponse`
var http: HTTPURLResponse? {
return self as? HTTPURLResponse
}
}
extension HTTPURLResponse {
/// Returns `true` if `statusCode` is in range 200...299.
/// Otherwise `false`.
@stormychel
stormychel / Iso369_1.swift
Created June 22, 2023 15:18 — forked from proxpero/Iso369_1.swift
A Swift 4.0 enum representing ISO 639-1 codes (used to classify languages)
// taken 2018-03-19 from wikipedia. https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
public enum Iso639_1: String {
case ab = "AB"
case aa = "AA"
case af = "AF"
case ak = "AK"
case sq = "SQ"
case am = "AM"
case ar = "AR"
@stormychel
stormychel / gist:a372bc4ea4acf015dad21546829adf18
Last active March 5, 2023 01:01
Check whether active window is in fullscreen mode on macOS / Cocoa
/// Check whether active window is in fullscreen mode.
/// - Parameter processIdentifier: the pid given by "NSWorkspace.shared.frontmostApplication?.processIdentifier"
/// - Returns: true if fullscreen, false if windowed
func isFullScreen(processIdentifier: pid_t) -> Bool {
if let winArray: CFArray = CGWindowListCopyWindowInfo(.excludeDesktopElements, kCGNullWindowID) {
for i in 0..<CFArrayGetCount(winArray) {
if let window: [String : Any] = unsafeBitCast(CFArrayGetValueAtIndex(winArray, i), to: CFDictionary.self) as? [String : Any] {
if let pid = window["kCGWindowOwnerPID"] as? Int32 {
if pid == processIdentifier {
if let bounds: [String : Any] = window["kCGWindowBounds"] as? [String : Any], let boundsWidth = bounds["Width"] as? CGFloat, let boundsHeight = bounds["Height"] as? CGFloat {
@stormychel
stormychel / SwiftExtensions.swift
Created December 6, 2022 22:19
Return UIHostingController for a SwiftUI View, ready to use with UIKit.
extension AnyView {
/// Return UIHostingController for a SwiftUI View.
/// - Usage: let vc = AnyView( YourSwiftUIViewHere() ).asUIHostingController()
/// - Created by Michel Storms.
/// - Returns: UIHostingController ready to use with UIKit.
func asUIHostingController() -> UIHostingController<AnyView> {
return UIHostingController(rootView: self)
}
}
@stormychel
stormychel / PreviousViewController.swift
Created November 27, 2022 23:29 — forked from susieyy/PreviousViewController.swift
Access previous view controller in navigation stack
extension UIViewController {
var previousViewController: UIViewController? {
guard let navigationController = navigationController else { return nil }
let count = navigationController.viewControllers.count
return count < 2 ? nil : navigationController.viewControllers[count - 2]
}
}
@stormychel
stormychel / gist:e6683e6b6c35e88cea6534c755be65d1
Created November 20, 2022 21:21
CoreData: NSManagedObject extension that prints all data to console. Usage: nsManagedObjectName.printContent()
extension NSManagedObject {
/// Print content of object to console.
func printContent() {
print("\nNSManagedObjectID: \(self.objectID) - key/value dump:")
for key in self.entity.attributesByName.keys {
print("\(key): \(self.value(forKey: key) ?? "nil")")
}
print("\n")
}
}