You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Terminal或Swift禁用macOS应用的三指轻按查词手势?

Fix: Disable Three-Finger Tap Word Lookup in Your macOS Swift App (Keep Text Selection)

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):

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 10:35:31