2016-06-23 6 views

答えて

1

インポートCoreGraphicsとチェックアウトCGWindowListCopyWindowInfo

import CoreGraphics 

let kCGNullWindowID: UInt32 = 0 

// Check the documentation for other options 
guard let windows = CGWindowListCopyWindowInfo([.OptionOnScreenOnly], kCGNullWindowID) as NSArray? as? [[String: AnyObject]] else { 
    fatalError("Can't find windows") 
} 

var windowCount = [String: Int]() 
windows.forEach { 
    let ownerName = $0[kCGWindowOwnerName as String] as! String 
    if let count = windowCount[ownerName] { 
     windowCount[ownerName] = count + 1 
    } else { 
     windowCount[ownerName] = 1 
    } 
} 

print(windowCount) 
+0

が正常に動作しない、結果は '[ "Xcodeの":1、 "ドック":2、 "サファリ":1、 "ファインダー":1 、 "SystemUIServer":2、 "Spotlight":1、 "Window Server":2] 'などがありますが、' Dock'、 'SystemUIServer'、' Spotlight'、 'Window Server'などのバックグラウンドプロセスにはウィンドウがありません。テストのために私はFinderウィンドウを閉じたが、そのカウントも '1'と宣言した。 – HelloToYou

関連する問題