Created
November 14, 2018 05:18
-
-
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/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: 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("[email protected]") | |
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("[email protected]") | |
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!!!! | |
} | |
Author
sneakyness
commented
Nov 14, 2018
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment