//
// AppDelegate.swift
// pickColor
//
// Created by BCZ on 2023/1/6.
//
import Cocoa
@main
class AppDelegate: NSObject, NSApplicationDelegate {
let statusItem = NSStatusBar.system.statusItem(withLength: -1)
@IBOutlet weak var statusMenu: NSMenu!
func applicationDidFinishLaunching(_ aNotification: Notification) {
// Insert code here to initialize your application
let icon = NSImage(named: "icon_VIP")
statusItem.button?.image = icon
statusItem.menu = statusMenu
print(NSScreen.main!.frame.size)
Timer.scheduledTimer(withTimeInterval: 0.1, repeats: true) { t in
let options = CGWindowListOption(arrayLiteral: .excludeDesktopElements, .optionOnScreenOnly)
let windowsListInfo = CGWindowListCopyWindowInfo(options, CGWindowID(0))
let infoList = windowsListInfo as! [[String:Any]]
let visibleWindows = infoList.filter{ $0["kCGWindowLayer"] as! Int == 0 && $0["kCGWindowOwnerName"] as? String == "微信" }
iflet wx = visibleWindows.first,
let frontApp = NSWorkspace.shared.frontmostApplication {
if frontApp.bundleIdentifier == "com.tencent.xinWeChat" {
print(wx)
}
}
}
}
funcapplicationWillTerminate(_ aNotification: Notification) {
// Insert code here to tear down your application
}
func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool {
return true
}
}
![](https://img-blog.csdnimg.cn/img_convert/03dc743df3176c51983846f18eae5124.png)
![](https://img-blog.csdnimg.cn/img_convert/7f2f4c67682816c43ca4ad081064ed8f.png)
Application is agent (UIElement) = YES (不在程序坞中显示)