Skip to content

Instantly share code, notes, and snippets.

@brentsimmons
Created January 6, 2026 04:11
Show Gist options
  • Select an option

  • Save brentsimmons/8dbe00e8acbeede26baaaebd06a867fc to your computer and use it in GitHub Desktop.

Select an option

Save brentsimmons/8dbe00e8acbeede26baaaebd06a867fc to your computer and use it in GitHub Desktop.
Disable all menu item images in a Mac app.
//
// NSMenuItem+RSCore.swift
// RSCore
//
// Created by Brent Simmons on 1/5/26.
//
#if os(macOS)
import AppKit
import ObjectiveC
extension NSMenuItem {
/// Disables all icons in all menu items.
///
/// Call `NSMenuItem.disableIcons` early (from AppDelegate.init is good).
public static func disableIcons() {
let originalSelector = #selector(getter: image)
let nilImageSelector = #selector(returnNilInsteadOfImage)
guard let originalMethod = class_getInstanceMethod(NSMenuItem.self, originalSelector),
let newMethod = class_getInstanceMethod(NSMenuItem.self, nilImageSelector) else {
return
}
method_exchangeImplementations(originalMethod, newMethod)
}
@objc private func returnNilInsteadOfImage() -> NSImage? {
nil
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment