Post

Replies

Boosts

Views

Activity

How to get/track the active app name from the background app on Mac using SwiftUI?
I am using SwiftUI for MAC App. I am working on the track feature to get the active app on screen from the background. I have implemented the solution below but am unable to get it. let workspace = NSWorkspace.shared let applications = workspace.runningApplications for application in applications { if let url = (application.executableURL?.absoluteString) { os_log("%{public}s", log:scribe, type:.debug, url) } } } Or Is it possible to get?
1
0
585
Mar ’23
How to capture the screen on mac using SwiftUI?
I am a beginner in SwiftUI. My task to capture the image of the whole screen using SwiftUI includes other apps and title bar. I am unable to show the permission dialog of screen recording and capturing the image of the screen. I have implemented the solution below but did not get success. func screenshotWindowAndSuccess() -> Bool { let task = Process() task.launchPath = "/usr/sbin/screencapture" task.arguments = ["-cm"] task.launch() task.waitUntilExit() let status = task.terminationStatus return status == 0 } Please help me to get out of this task. Thank you in advance!
1
0
1.5k
Feb ’23
How to solve seconds gap in Timer using SwiftUI for macOS?
I am working on a macOS App using SwiftUI. My task is to trigger an event every one second on a Mac App using Swift even if the app is in background but unfortunately, I noticed that the second gap was between the triggering block of Timer. I have showed the logs and the code below here it is my code let timer = Timer.scheduledTimer(timeInterval: 10, repeats: true, block : { counter += 1 }) RunLoop.main.add(timer, forMode: .common) //Second code block which I tried Timer.scheduledTimer(intervaltime : 1, repeats: true, block: { timer in print("date is \(getDate())") } here, you can see the seconds gap
0
0
328
Jan ’23
How to track the key press events of keyboard using SwiftUI for MacOS?
I am unable to get the keyboard keys events in the background or Inactive state of the mac application. I am trying to get the global event using NSEvent.addGlobalMonitorForEvent(matching: [.keyDown], handler: { event in print("key pressed : \(event.keyCode)") return event }) This is working for mouse tracking but unable to track the events for keyboard...;( Please help me to track the event for the keyboard events in active/inactive and background.
1
0
1.5k
Dec ’22