102

I was using Linux for the last couple of years and I find it extremely useful to copy text by highlighting it as well as to paste by clicking a middle mouse button.

I'm using a Mac now and I wonder if I can achieve such behaviour on Mac OS X.

Loïc Wolff
  • 14,706
installero
  • 1,121
  • 13
    I cannot believe OSX does not do this ... linux rocks in so many ways – Scott Stensland Apr 30 '17 at 01:53
  • I wonder if there is a way to make this available by (partially) disabling SIP. Like if there would be a way to make it properly work, all answers in this thread don't provide a solution to copy selected text to a different buffer, without cluttering the clipboard. – astroboy Jul 19 '23 at 19:50

11 Answers11

33

I wrote a free little C program that does something similar to Gilligan's answer. Whenever you drag-highlight or double-click text, it copies to the clipboard buffer. Then you can middle-mouse-click in any window to paste it. It is called "macpaste" and on Github (https://github.com/lodestone/macpaste). It works globally for every program I use that has textual data.

In iTerm2, disable their middle-click in Preferences, otherwise you'll get double pastes.

remikz
  • 437
  • 4
  • 4
  • 3
    This is AWESOME! So close. If it only had a separate buffer to hold the highlighted text separately from normally copied text it would be almost as close to Linux as possible. Nice job – Ryan Martin Jun 24 '16 at 20:27
  • This is exactly what I was looking for :-) Thank you so much for sharing! – José Alfredo Romero L. Jul 28 '16 at 13:22
  • 7
    This works, however it unfortunately messes up with chrome/firefox/safari/anybrowser middle-click-link to open in new tab. Any way to get around this? – lenooh Aug 17 '16 at 14:33
  • Doesn't compile for me - Undefined symbols for architecture x86_64 – Peter Ehrlich Jun 02 '17 at 18:45
  • Cool! I've added below in my .bashrc and it works fine (xterm is only where I miss it): case "$(ps -ef | grep macpaste | grep -v "grep" | wc -l)" in
    0)  ~/bin/macpaste/macpaste > /dev/null &
        ;;
    1)  # all ok
        ;;
    *)  kill -9 $(pgrep macpaste)
        ~/bin/macpaste/macpaste > /dev/null &
        ;;
    esac
    
    

    The only one sad thing that I don't have middle button on my MM2 and don't want to setup that thirdparty stuff... Thanks @remik !

    – Egor Jul 27 '17 at 03:28
  • 1
    This would be so great if it would not beep on almost every click. – rien333 Aug 23 '17 at 20:49
  • 3
    The problem with macpaste is that it breaks middle click for everthing else. For example, I cannot middle-click to close tabs in Chrome, or middle-click to open a link in a new tab. – aggregate1166877 May 22 '19 at 21:13
20

You can try BetterTouchTool (legacy versions can be used with a free license available here). You can assign custom trackpad, mouse, and keyboard events to trigger specific actions on a global or application-specific basis.

Here's my configuration to bind a three-finger tap to ⌘V (as this is the global paste shortcut. Alternatively, you can select from dozens of other trackpad and mouse gestures to emulate the paste command.

Screenshot of BetterTouchTool's Gestures preferences

agarza
  • 2,274
adamrmcd
  • 1,540
  • 20
    FWIW this only solves the middle-click; I don't believe its possible to auto-copy highlighted text without an additional command. (Except for apps that specifically provide the feature, like iTerm2) – adamrmcd Nov 10 '11 at 19:00
  • 8
    And has anyone come up with a reasonable solution for that so far? I miss my select-wheelpaste SO MUCH!!! – Rubens Feb 27 '15 at 21:00
  • 6
    This is crazy that you cannot get this behavior in the built in terminal between windows....ahhh i miss linux. – DrCord Aug 04 '16 at 22:42
  • @Desphilboy The three comments above yours are primarily complaining about the lack of copy-on-select, which is not solved by your answer. – Kyle Strand Jul 11 '19 at 21:35
  • Only can be done in a terminal and my answer is specific to terminals . @KyleStrand – Desphilboy Jul 19 '19 at 02:52
  • What you could do is have a gesture for copy and a different gesture for paste - which I'm quite happy with for my use cases - which is just quickly get at text. – Att Righ Apr 26 '23 at 10:45
  • @adamrmcd It seems it is free only for 45 days then you have to buy a license to use it. – SebMa May 18 '23 at 12:31
17

The macOS terminal can do copy/paste with two separate buffers:

  1. The copy/paste buffer which is shared with all other applications. It can be accessed by CommandC/CommandV.
  2. A separate copy/past buffer which is shared only between (macOS) terminals. It can be filled (copy) by dragging over the text by mouse, double clicking, or ShiftCommand double-clicking for file names (no CommandV). The content of this buffer is pasted by the middle mouse button, by ShiftCommandV, or by Command + two-finger-click.
John N
  • 1,487
Matthias
  • 171
5

Create the following Automator service: enter image description here

Assign it a keystroke, like shiftcontrol] (something unlikely to conflict with anything). Then, use BetterTouchTool to assign that keystroke to the middle mouse button.

The middle shell script comes from this fine answer. The first shell script copies the selection to the clipboard, the middle script clicks the mouse at its current location, and the AppleScript sends a V to paste the contents of the clipboard

Daniel
  • 34,803
  • 1
    This allows copying while clicking on the middle mouse. OP wants to highlight to copy by highlighting and then paste with the middle mouse button – Ulysse BN Jan 26 '18 at 01:24
  • Is there a way to have both middle click to open new tabs in Chrome and this functionality? – William Oct 09 '18 at 19:33
3

After highlighting text in the Terminal, I can middle-click to paste it back into the Terminal without using the copy/paste keyboard shortcuts. This does not seem to work when the text comes from other applications ie. I can't copy text from TextEdit and then paste into Terminal with a middle-click. I am running Lion and I did not have configure anything to get this default behavior. I'm not sure about other versions of OS X.

user27478
  • 338
2

I don't think there is a way in general but some programs will accept the middle button as paste

e.g.

  • Aquamacs - an OSX configured emacs

  • iTerm2 - a replacement for Terminal

For newer mice/trackballs clicking the scroll wheel acts as a third button

mmmmmm
  • 30,160
2

Select Text to be copied, then Drag and Drop your selection (White Plus sign in red circle will be displayed with the cursor). This will copy-paste the text.

You can Drag and Drop inside Terminal or between apps.

1

I tried the Automator script suggested by Daniel. It did NOT work for me on OS X 10.10.

I was able to make BetterTouchTool (v 1.15), alone, work for some applications. Like this:

enter image description here

I did Left Mouse twice for several reasons. The first one usually only changes the focus to the new window, but does not position the cursor. Also, clicking in a text box usually selects all of the text, which is then deleted when something is pasted there. I usually want the original text to stay.

Gilligan

1

The following Karabiner Complex Modification maps the middle mouse button to V and shift middle mouse button to V:

{
  "title": "Edit-related mappings",
  "rules": [
    {
      "description": "MouseButton3 to Cmd+v: Paste",
      "manipulators": [
        {
          "type": "basic",
          "from": {
            "pointing_button": "button3",
            "modifiers": {
              "optional": [
                "caps_lock"
              ]
            }
          },
          "to": [
            {
              "pointing_button": "button1"
            },
            {
              "key_code": "v",
              "modifiers": [
                "command"
              ]
            }
          ]
        }
      ]
    },
    {
      "description": "Shift+MouseButton3 to Shift+Cmd+v: Pasteboard",
      "manipulators": [
        {
          "type": "basic",
          "from": {
            "pointing_button": "button3",
            "modifiers": {
              "mandatory": [
                "shift"
              ],
              "optional": [
                "caps_lock"
              ]
            }
          },
          "to": [
            {
              "pointing_button": "button1"
            },
            {
              "key_code": "v",
              "modifiers": [
                "shift",
                "command"
              ]
            }
          ]
        }
      ]
    }
  ]
}

The following maps the left mouse button to perform C after selection:

    {
      "description": "MouseButton1 to Cmd+c: Copy",
      "manipulators": [
        {
          "type": "basic",
          "from": {
            "pointing_button": "button1",
            "modifiers": {
              "optional": [
                "caps_lock"
              ]
            }
          },
          "to_if_alone": [
            {
              "pointing_button": "button1",
              "halt": true
            }
          ],
          "to_if_held_down": [
            {
              "pointing_button": "button1"
            }
          ],
          "to_after_key_up": [
            {
              "key_code": "c",
              "modifiers": [
                "command"
              ]
            }
          ]
        }
      ]
    }

Behavior of using this rule is a bit delayed. With the default Karabiner settings, you'll have to wait a little bit after starting a selection and moving the mouse. Changing some Karabiner settings may help with this but may have other consequences (I've set to_if_alone_timeout_milliseconds to 200 and to_if_held_down_threshold_milliseconds to 200).

Noel Yap
  • 151
0

I would like to add that, if the problem is, as it was with me, that you couldn't get stuff that was highlit in an X-Quartz window onto the clipboard, the secret to that is to highlight, then XQuartz menu-> Edit -> Copy. That way, it is available for paste in every ordinary Mac OS app.

Andrew
  • 21
0

In majority of terminals you can drag and drop the highlighted text or alternatively you can use: Shift + ⌘ + v

It will act like in Linux pressing middle-mouse button ( is a copy and paste together)