Hi,
I am counting number of keys pressed by the user. like calculating typing speed of the user.
Post
Replies
Boosts
Views
Activity
Following code i tried to implement in my MacOS App, but it can't able to create CGEvent.tapCreate
import Foundation
import CoreGraphics
func myCGEventCallback(proxy : CGEventTapProxy, type : CGEventType, event : CGEvent, refcon : UnsafeMutableRawPointer?) -> Unmanaged<CGEvent>? {
if type == .keyDown || type == .keyUp || type == .flagsChanged {
let keyCode = event.getIntegerValueField(.keyboardEventKeycode)
print(keyCode)
}
return Unmanaged.passRetained(event)
}
func KeyCounterEvent() {
let eventMask = (1 << CGEventType.keyDown.rawValue) | (1 << CGEventType.keyUp.rawValue) | (1 << CGEventType.flagsChanged.rawValue)
guard let eventTap = CGEvent.tapCreate(tap: .cgSessionEventTap, place: .headInsertEventTap, options: .defaultTap, eventsOfInterest: CGEventMask(eventMask), callback: myCGEventCallback, userInfo: nil) else {
debugPrint("Failed to create event tap")
exit(1)
}
let runLoopSource = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, eventTap, 0)
CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, .commonModes)
CGEvent.tapEnable(tap: eventTap, enable: true)
CFRunLoopRun()
}
Note: tried this code in separate console app works fine, but problem occurs when creating it in MacOS App with SandBox
Hi,
Following is my current code which is trying to implement in macOS App
var displayCount: UInt32 = 0;
var result = CGGetActiveDisplayList(0, nil, &displayCount)
if result != CGError.success {
print("error: \(result)")
return
}
let allocated = Int(displayCount)
let activeDisplays = UnsafeMutablePointer<CGDirectDisplayID>.allocate(capacity: allocated)
result = CGGetActiveDisplayList(displayCount, activeDisplays, &displayCount)
if result != CGError.success {
print("error: \(result)")
return
}
for i in 1...displayCount {
let fileUrl = URL(fileURLWithPath: "image\(i).jpg", isDirectory: true)
let screenShot:CGImage = CGDisplayCreateImage(activeDisplays[Int(i-1)])!
let bitmapRep = NSBitmapImageRep(cgImage: screenShot)
let jpegData = bitmapRep.representation(using: NSBitmapImageRep.FileType.jpeg, properties: [:])!
do {
try jpegData.write(to: fileUrl, options: .atomic)
} catch { print("error: \(error)") }
}
Note: I am implement same code in console app separately which it woks fine, but issue in macOS App
Tried using CGRequestScreenCaptureAccess first time it returns true, then after there is no return from that function which leads to stop executing the code.
As per my functionality calling permissions every time when application starts and executing particular code means it will be issue to user.
Is there any option to authenticate for the first time then after it need to run without authentication.
what will be the suggested solution for macOS App with SandBoxed
ok i will try with signed app
Tried signed macOS App still same issue.
Yes code running the else case in the guard statement in my masOS App.
Note: tried this code in separate console app works fine, but problem occurs when creating it in MacOS App with SandBox
Do you receive an error message ? If so, which ?
No
Did it stop running on all 3 Mac ?
Yes
If the exact same code was running on all 3 Mac before with the same code
are you absolutely sure you did not change anything to the app ?
Yes
I tried all the above mentioned probabilities.
Same url is working with postman
same url is working in windows system
So you don't get error here ?
Yes
What do you get in response and response.statusCode ?
200
What do you get for each print() in the code ?
responseString =
Is it an https or http URL ?
https
Do all the 3 Mac share the same AppleID ? If so, could you try from another AppleID ?
3 Mac sharing the same AppleID
We don't have another AppleID
Hi,
I am implementing the following link code in xpc service which it terminates the xpc service by saying memory issue.
link
I am trying to implement blocking websites in macOS
Hi,
i am trying to implemented block websites functionality as xpc service.
link
i am getting following error
[22516:3818158] [general] Attempting to perform block on main runloop, but the main thread has exited. This message will only log once. Break on _CFRunLoopError_MainThreadHasExited to debug
[22516:3818158] [general] Attempting to wake up main runloop, but the main thread as exited. This message will only log once. Break on _CFRunLoopError_MainThreadHasExited to debug.
which it terminates the xpc service saying
Message from debugger: Terminated due to memory issue
Hi,
I am trying to run Console App code in Swiftui project.
The Code with consists of SBApplication to get data from bundle identifier which is not working.
let safariObject: SafariApplication = SBApplication(bundleIdentifier: "com.apple.Safari")!
let frontWindow = safariObject.windows!()[0] as! SafariWindow
let activeTab = frontWindow.currentTab!
let url = activeTab.URL
let activeTab = BrowserTab.safari(activeTab)
Note: Same code working fine when it is implemented in console app
Hi,
Let us explain my implementation using above mentioned four points
added first and second point functionality in my app with sandbox disabled. which it is working fine after accepting fourth point permissions.
but my requirement is with first and second are implemented and sandbox enabled with accepting fourth point.