Skip to content

Instantly share code, notes, and snippets.

@sneakyness
Created November 14, 2018 05:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sneakyness/e975bac990e6c423a3efcb9827522e05 to your computer and use it in GitHub Desktop.
Save sneakyness/e975bac990e6c423a3efcb9827522e05 to your computer and use it in GitHub Desktop.
Generate a statuslabel.png tinted the color of your MacOS Accent Color and save it in ~/Documents/Shared Playground/Directory/
//: A Cocoa based Playground to present user interface
import AppKit
import PlaygroundSupport
import Foundation
import CoreImage
import ImageIO
let nibFile = NSNib.Name("MyView")
var topLevelObjects : NSArray?
Bundle.main.loadNibNamed(nibFile, owner:nil, topLevelObjects: &topLevelObjects)
let views = (topLevelObjects as! Array<Any>).filter { $0 is NSView }
// Present the view in Playground
PlaygroundPage.current.liveView = views[0] as! NSView
if let accentColor = CIColor(color: NSColor.controlAccentColor) {
let coreServicesString = "/System/Library/CoreServices/"
let dockResourcesPath = URL(fileURLWithPath: coreServicesString+"Dock.app/Contents/Resources")
let finderResourcesPath = URL(fileURLWithPath: coreServicesString+"Finder.app/Contents/Resources")
let statusLabelPath = dockResourcesPath.appendingPathComponent("statuslabel.png")
let statusLabel2xPath = dockResourcesPath.appendingPathComponent("statuslabel@2x.png")
let image = NSImage(byReferencing: statusLabelPath)
let ciiimage = CIImage(cgImage: image.cgImage(forProposedRect: nil, context: nil, hints: nil)!)
let image2x = NSImage(byReferencing: statusLabel2xPath) // Wtf both w 54 h 54 (it's points)
image.recommendedLayerContentsScale(0.0)
image2x.recommendedLayerContentsScale(0.0) // Huh, TIL
let parameters = [
kCIInputColorKey: accentColor,
kCIInputIntensityKey: 1.0,
kCIInputImageKey: ciiimage] as [String : Any]
let filter = CIFilter(name: "CIColorMonochrome", parameters: parameters)
let context = CIContext(options: nil)
let imageRef = context.createCGImage(filter!.outputImage!, from: CGRect(origin: CGPoint.zero, size: image.size))
let bitmapImageData = NSBitmapImageRep(cgImage: imageRef!)
let pngRep = bitmapImageData.representation(using: .png, properties: [:])
let failURL = playgroundSharedDataDirectory.appendingPathComponent("statuslabel@2x.png")
do {
try pngRep?.write(to: failURL)
} catch {
print(error)
}
let isReadableFile = FileManager.default.isReadableFile(atPath: statusLabelPath.relativePath)
let isWritableFile = FileManager.default.isWritableFile(atPath: statusLabelPath.relativePath)
// let me out!!!!
}
@sneakyness
Copy link
Author

sneakyness commented Nov 14, 2018

statuslabelstatuslabelbluestatuslabelpinkstatuslabelorangestatuslabelredstatuslabelgreenstatuslabelyellowstatuslabelgray

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment