Forums
New posts
Articles
Product Reviews
Policies
FAQ
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Menu
Log in
Register
Install the app
Install
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
Showing a list of all running windows - Swift
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="renegadeandy" data-source="post: 1758498" data-attributes="member: 191510"><p>Hi everyone! I am new to swift - and new in general to programming on mac osx.</p><p></p><p>I want to get an array of open windows - loop through them and print out to a console each of the names of the open windows.</p><p></p><p>So far I have made a new Cocoa application, in Swift, and in my AppDelegate.swift added the following code:</p><p></p><p>[CODE]</p><p></p><p>import Cocoa</p><p></p><p>@NSApplicationMain</p><p>class AppDelegate: NSObject, NSApplicationDelegate {</p><p></p><p></p><p></p><p> func applicationDidFinishLaunching(_ aNotification: Notification) {</p><p> // Insert code here to initialize your application</p><p> </p><p> println("hello world");</p><p> CFArray windows = CGWindowListCopyWindowInfo(CGWindowListOption.optionAll, CGWindowID.kCGNullWindowID);</p><p> </p><p> }</p><p></p><p> func applicationWillTerminate(_ aNotification: Notification) {</p><p> // Insert code here to tear down your application</p><p> }</p><p></p><p></p><p>}</p><p></p><p>[/CODE]</p><p></p><p>Needless to say - it doesn't like my println line - can't find the write syntax to just write text to a console <img src="/mac_images/images/smilies/Angry-Tongue.png" class="smilie" loading="lazy" alt=":Angry-Tongue:" title="Angry Tongue :Angry-Tongue:" data-shortname=":Angry-Tongue:" /> and also - it seems I am not declaring the CFArray correctly - to store the response array of dictionaries from my CGWindowListCopyWindowInfo call.</p><p></p><p>Am I on the right track? What should I change the syntax to? Any pointers would be ace!</p></blockquote><p></p>
[QUOTE="renegadeandy, post: 1758498, member: 191510"] Hi everyone! I am new to swift - and new in general to programming on mac osx. I want to get an array of open windows - loop through them and print out to a console each of the names of the open windows. So far I have made a new Cocoa application, in Swift, and in my AppDelegate.swift added the following code: [CODE] import Cocoa @NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate { func applicationDidFinishLaunching(_ aNotification: Notification) { // Insert code here to initialize your application println("hello world"); CFArray windows = CGWindowListCopyWindowInfo(CGWindowListOption.optionAll, CGWindowID.kCGNullWindowID); } func applicationWillTerminate(_ aNotification: Notification) { // Insert code here to tear down your application } } [/CODE] Needless to say - it doesn't like my println line - can't find the write syntax to just write text to a console :Angry-Tongue: and also - it seems I am not declaring the CFArray correctly - to store the response array of dictionaries from my CGWindowListCopyWindowInfo call. Am I on the right track? What should I change the syntax to? Any pointers would be ace! [/QUOTE]
Verification
Name this item 🌈
Post reply
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
Showing a list of all running windows - Swift
Top