如何通过Terminal或Swift禁用macOS应用的三指轻按查词手势?
Hey there! Let's work through this for your macOS app built with Xcode and Swift. You want to retain text highlighting/selection but turn off that three-finger tap gesture that pops up word definitions. Below are two reliable approaches—one for app-specific control (using Swift) and another for system-wide changes (via Terminal):
1. Swift Code Solutions (App-Only, Recommended)
These methods only affect your app, so you won't mess with the user's system-wide settings.
Global App-Wide Disable
The simplest way to block the lookup gesture across all your app's components (NSTextView, WKWebView, etc.) is to add this to your AppDelegate.swift's launch method:
func applicationDidFinishLaunching(_ aNotification: Notification) { // Block the system's three-finger tap lookup gesture in your app NSApp.suppressGesture(withIdentifier: .lookup) }
This completely stops the lookup popup while leaving text selection fully functional.
Target Specific NSTextViews
If you only want to disable the gesture on certain text views, create a custom NSTextView subclass to filter out the three-finger tap gesture:
class NoLookupTextView: NSTextView { override func awakeFromNib() { super.awakeFromNib() // Find and disable the three-finger tap gesture recognizer gestureRecognizers?.forEach { gesture in if let clickGesture = gesture as? NSClickGestureRecognizer, clickGesture.numberOfTouchesRequired == 3 { clickGesture.isEnabled = false } } } }
Then just set your text view's class to NoLookupTextView in your Storyboard or XIB file.
Target WKWebViews
For web views, combine the global app disable with a configuration tweak to ensure no lookup triggers from WebKit:
let webConfig = WKWebViewConfiguration() // Disable WebKit's built-in lookup panel trigger webConfig.preferences.setValue(false, forKey: "allowLookupPanel") // Initialize your web view with this config let webView = WKWebView(frame: .zero, configuration: webConfig)
The global suppressGesture call will still apply here, giving you double protection against the lookup popup.
2. Terminal Command (System-Wide Disable)
If you want to turn off the three-finger tap lookup across the entire system (note: this affects all apps, not just yours), run these commands in Terminal:
# Disable the global three-finger tap gesture defaults write NSGlobalDomain com.apple.trackpad.threeFingerTapGesture -int 0 # Restart Finder to apply changes immediately killall Finder
To revert back later, use:
defaults write NSGlobalDomain com.apple.trackpad.threeFingerTapGesture -int 1 killall Finder
Quick Notes
- Stick with the Swift code approach if you can—it's the most user-friendly, as it doesn't alter their system settings outside your app.
- All these methods preserve full text highlighting and selection functionality—exactly what you need.
内容的提问来源于stack exchange,提问作者Noah H

