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?
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
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!
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
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.