-
-
Notifications
You must be signed in to change notification settings - Fork 517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pasting fails on High Sierra #161
Comments
I nailed the issue down to enabling the sandbox 😞 It seems like sending a "CMD+V" event silently fails on High Sierra while succeeding in Catalina. What a mess. |
FTR Pasting works fine on Mojave so it's only High Sierra issue. |
Anyone else who's still running High Sierra and has similar issue is welcome to try ☝️ too! |
I'm on vacation this week but will test next week. Thanks. |
The current implementation of pasting is as simple as "simulate CMD+V keyboard press": // Based on https://github.com/Clipy/Clipy/blob/develop/Clipy/Sources/Services/PasteService.swift.
func paste() {
guard accessibilityAllowed else {
Maccy.returnFocusToPreviousApp = false
// Show accessibility window async to allow menu to close.
DispatchQueue.main.async(execute: showAccessibilityWindow)
return
}
DispatchQueue.main.async {
let vCode = UInt16(kVK_ANSI_V)
let source = CGEventSource(stateID: .combinedSessionState)
// Disable local keyboard events while pasting
source?.setLocalEventsFilterDuringSuppressionState([.permitLocalMouseEvents, .permitSystemDefinedEvents],
state: .eventSuppressionStateSuppressionInterval)
let keyVDown = CGEvent(keyboardEventSource: source, virtualKey: vCode, keyDown: true)
let keyVUp = CGEvent(keyboardEventSource: source, virtualKey: vCode, keyDown: false)
keyVDown?.flags = .maskCommand
keyVUp?.flags = .maskCommand
keyVDown?.post(tap: .cgAnnotatedSessionEventTap)
keyVUp?.post(tap: .cgAnnotatedSessionEventTap)
}
} Apple Developer support believes it's a bug that it does nothing in the sandboxed version of Maccy in High Sierra. Given it is okay in the newer macOS version - it won't be fixed. As an alternative, I found an AppleScript that can simulate pasting (https://stackoverflow.com/questions/25747253/applescript-to-paste-clipboard): tell application "System Events" to keystroke "v" using command down It works in all OSes but suffers from the flaw that it also takes into account other pressed key modifiers. So, if someone pastes by pressing OPTION+5, it might fail if OPTION is not released yet - the app would receive CMD+OPTION+V which is wrong. There are various hacks that might improve this, but I'm not sure I want to go that route. Another possible solution would be of course to simply disable the sandbox, but that has 2 problems:
I'm going to give a shot and submit the app as-is to the App Store. It might still be blocked due to I'll revert to disabling sandbox if in the very end there will be no way to pass the App Store review. Though there are various clipboard managers out there that somehow work and passed the review, so I haven't lost the hope yet. |
Ok, the application has passed the review in the App Store. With that said, I lean towards the easiest route which is to drop support for High Sierra at all. One can still keep using the old version that works without a sandbox (v0.14.1). if anyone can come up with a different solution where I can work it around in High Sierra, I'll be happy to bring support back. I understand how disappointed High Sierra users might be and I'd love to make it work, but I just don't see a way. |
Since v0.15.0 the sandbox has been enabled in the app. This in fact broke pasting on High Sierra. Unfortunately, the sandbox prevents emitted paste event from reaching the application on this particular version of macOS. Apple Developer support stated that this is a bug which has probably been fixed in Mojave, but won't even be in High Sierra. At the same time, I haven't found any reliable alternative to pasting event. One of those was to use AppleScript but it suffers from other problems. See discussion in #161 for more details. In the very end, it seems like there are 2 ways: either stop supporting High Sierra as pasting doesn't work there or disable the sandbox. Given I plan to distribute the app in the App Store, the former is really the only way to go for now.
@p0deje - I guess there really isn't much point me testing now. I would upgrade from High Sierra, but it's not important enough for me to bother with the possible issues on my 2011 MBP - happy to just keep it ticking along for a while longer 👍 Thanks for your efforts though. For now, I've gone back to Clipy. |
@mul14 - that version does seem to work as expected - thanks! Is this a version you modified yourself? |
When trying to paste on High Sierra - nothing happens. It might the issue of focusing the application back.
The text was updated successfully, but these errors were encountered: