//
// 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://www.toymoban.com/news/detail-796817.html
Application is agent (UIElement) = YES (不在程序坞中显示)文章来源地址https://www.toymoban.com/news/detail-796817.html
到了这里,关于MacOS 任务栏程序&获取指定程序窗口信息的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!