OSX and X11 cut/paste

Is there a program that will automatically synchronize the X clipboard to the OSX pasteboard?

When something in MacOS-land copies something to the pasteboard, X11.app automatically copies that to the X11-land "clipboard" selection, which is good. But when something in X11-land copies something to the X11 clipboard selection, it is not automatically copied to the OSX pasteboard, and that's lame.

When running XEmacs under X11 (local or remote) I find that

    (setq interprogram-cut-function 'own-clipboard
          interprogram-paste-function 'get-clipboard-foreign)
makes things do almost the right thing...

I really wish there was some way to make drag-and-drop of selected text work with XEmacs, though. But that doesn't even work in Linux.

Update: No, scratch that, using interprogram-paste-function is useless. It seems that sometimes copying things in OSX programs updates the X11 clipboard, but not always. I can't figure out when it does and when it doesn't.

Update 2: Incidentally, it is not lost on me that the most frustrating parts of my Mac experience involve X11, which I'm only using at because I just can't put down the Emacs crack-pipe, despite it being the source of much suffering.

Update 3: My current guess as to what is going on is that, every time focus moves from an OSX program to an X11 program, the X11 clipboard is overwritten with the OSX pasteboard (regardless of which is newer). Conversely, when focus moves from an X11 program to an OSX program, nothing is changed at all.

Update 4: Why I don't use Carbon Xemacs: select the following u-umlaut character in Safari -- ü -- copy it; then paste it into Carbon Xemacs and watch it crash. (Oddly, it does not crash if you copy it from Firefox instead of Safari!)

Update 5: Andrew sent me a patch that fixes the Carbon XEmacs crash, yay! I assume it'll be on his site soon.

Tags: , , , ,

52 Responses:

  1. justinjs says:

    This isn't exactly answering your original question, but since your reason for caring about this is probably mostly driven by XEmacs...

    I was driven nuts by this exact same problem.

    Then I built a copy of Carbon XEmacs, it works great, and now I don't care about X11's clipboard anymore. It turns out that there's nothing I need X11 for now that I use in a clipboard-relevant way.

    Drag-and-drop isn't there, but at least XEmacs has its kill-and-yank unified with the OSX clipboard.

    • jwz says:

      I used Carbon XEmacs for a while, but it crashes all the fucking time. Ironically, about one third of the time that I try to paste anything into it.

      • davachu says:

        I've used it since 10.3, and a recent download on a clean 10.4 install has been crash free. Usually, crashiness has been me doing random alt-tabs while using scroll bars causing events to get posted wrongly.

        I don't even have X11 on my Mac now. Probably the first time in 20 years I've not had a machine that could run an X server...

        • jwz says:

          The version I have is a self-compiled 21.5.20 on 10.4, which is, I think, still the latest version.

          I have a bunch of remote machines I have to admin, so I don't think that totally giving up on remote X11 xemacsen is in my future.

          • davachu says:

            Hm, no VPN?

            I've been VPN-ed in to $client today, mounted some shares, edited locally, wrote back.

            Much as I love lumpy X over the internet, I'd rather have a snappy local editor and a slow load/save of files.

            • jwz says:

              I have never used VPN. I know almost nothing about it, but it frightens me.

              Also, none of my servers run NFS and never will as long as I'm still breathing.

              • davachu says:

                Do have a look at openvpn. It's low tech, can be tunneled over ssh. Or is uses the SSL protocols in a good way. IPSec is scary, bad and wrong IMHO.

                Who uses NFS these days anyway[0]? Samba all the way. At least for simple stuff like this.

                [0] Yeah, yeah.

                • jwz says:

                  Doesn't "Samba" mean "NFS levels of reliability, plus Microsoft levels of security"?

                  • davachu says:

                    For stuff like having a Mac pick files up off a linux server for editing purposes it's plenty reliable.

                    As for security - we're VPN-ed in to $client's LAN. It's a reasonably trusted environment, surely?

        • jwz says:

          See update -- copy "ü" in Safari and paste in Carbon Xemacs to crash it.

          • davachu says:

            Nope, yanked into Carbon emacs perfectly for me.

            Maybe I'm running some Eurotrash locale that expects it?

            BTW I'm running:

            GNU Emacs (powerpc-apple-darwin8.1.0) of 2005-06-07 on iBookG4.local

            And meta-W then apple-V just worked to paste that string the other way.

            • jwz says:

              Hello, "Carbon Emacs" != "Carbon XEmacs".

              • davachu says:

                Now we're splitting hairs. Obviously this matters to you, but to me Emacs is Emacs, X or otherwise. I switch freely between the two. One works for me and doesn't crash. Sorry it doesn't work for you.

  2. shayel says:

    There's pbcopy, which takes the standard input and places it in the pasteboard. pbpaste does the opposite.
    I don't know of a way to force quartz-wm to sync the pasteboard to the clipboard (but hope there is one.)

    • jwz says:

      Yes, I know about those. In what way is that even remotely an answer to the question I asked?

      • shayel says:

        shell-command that in interprogram-cut-function? (It's a bit rube-ish, but should work.)

        • jwz says:

          Yes, I am fully capable of writing a program that does this. Please note that I asked "is there a program that", not "how would I go about writing."

          • scosol says:

            awful bitchy today eh?

            lemme answer your question- "no".

            • ciphergoth says:

              awful bitchy today eh?

              You must be new here.

              JWZ: perhaps you need a bit of boilerplate every time you ask the Lazyweb a question that says "If you don't know the exact answer to the exact question I asked, kindly fuck right off". You usually end up adding it after the fact anyway.

  3. fdaapproved says:

    The closest I've ever been able to get to integrating the two clipboards is is by using autocutsel. I know there are people out there claiming that you don't need it anymore but they appear to be lying.

    Oh, and the patch in my patch directory tells me that autocutsel.c:506 should read setpgrp(0,0); rather than setpgrp();

    • ctdean says:

      Before I switched to a Carbon Emacs, I also used autocutsel.

      My notes say this: If you are having difficulty using copy and paste between X11 X?Emacs you can use autocutsel to keep the different X11 selection buffers in sync. Just use the emacs C-y and M-w to paste and copy from the Mac copy buffer.

      autocutsel can be installed via fink or http://www.lepton.fr/tools/autocutsel/

      You can set the selection-sets-clipboard XEmacs variable if you're still having problems. (setq selection-sets-clipboard t)

    • jwz says:

      The documentation for autocutsel says that it synchronizes the X11 clipboard with the X11 cut buffer. I don't use anything that uses cut buffers. I want to synch the X11 clipboard with the OSX pasteboard. (The reverse of that already happens.)

      • fdaapproved says:

        Yeah, I know. I suspect that quartz-wm sucks and picks up the cut buffer with the pasteboard rather than syncing the clipboard like it should. So, using autocutsel to sync the clipboard and the cut buffer ends up also syncing the pasteboard.

        • jwz says:

          All autocutsel seems to do is periodically overwrite the X clipboard with the contents of the OSX pasteboard. It never goes the other way, so running it has the side effect that anything copied in an X11 program just tends to vanish in favor of whatever the previous thing copied by an OSX program was. That's pretty much worse than useless...

      • phs says:

        I'm unclear on the terminology here, but the Quartz WM seems to automatically synchronize CLIPBOARD to the Mac OS pasteboard, but it only puts PRIMARY to the pasteboard when one hits Command-C.

        I got around this by hacking up X11.app to copy PRIMARY to CLIPBOARD whenever they were different. (quartzwm is closed-source for some unknown reason.) Also, I inserted code to swap Command and Option before the key event was passed to the MacOS menus so that I could use Command for Meta without causing random services to fire on some emacs chords.

        This solution pretty much sucks. Sorry.

  4. irilyth says:

    I use XDarwin rather than X11.app, but the clipboards automatically synch for me. (This might've been one of the reasons why I stuck with XDarwin, which I had been using since 10.1, when X11.app came out.)

  5. clubjuggler says:

    Why don't you just run the OS X native version of XEmacs? That should avoid the entire problem of two different "clipboards".

    • jwz says:

      Because it crashes all the fucking time, usually when I'm trying to paste something into it.

      • clubjuggler says:

        Ok, that sucks. I would recommend using the native version of GNU Emacs, since it's been rock solid for me, but I guess that wouldn't go over well considering.

  6. spikenheimer says:

    uh... in 10.3 land, the X11 has a Copy which is cmd - C that seems to work.

    and i realize thats not how X does it. but it does seem to work.

    • jwz says:

      WOW, NO SHIT?

    • dagbrown says:

      And the great thing about that "solution" is that you have your choice of either having a meta key or a cut-and-paste shortcut! Not both! Who would ever want to use the inferior meta key as a (yuck) meta key, once they'd seen the glory of Apple's perfect keyboard shortcuts?

      This has been pissing me off for quite a number of months now, and the answer to the problem is inevitably "suck it up, you can't have your cake and eat it, you know." Which has the astounding effect of making the MacOS cut-and-paste even more broken from the point of view of Me, The Guy Actually Trying To Use The Box, than X11's is normally by itself.

      MacOS X has so much hate.

      • mark242 says:

        Why not just use an xmodmap file to remap, oh, say, the key right next door to the command key as your meta key?

        • phs says:

          Possibly because he has a TiBook like me, where the option key is the size of a flea and just about as durable.

          After both of mine broke (which took about three to four months each) I implemented the evil X11 source hack described above and have been happy since.

      • jwz says:

        I have "enable keyboard shortcuts" un-checked in the X11 preferences, meaning OSX mostly doesn't interfere with XEmacs. But, that's why I want X11 to treat the X11 clipboard and the OSX pasteboard as one and the same thing: so that there (appears to be) only one paste command, not two.

  7. kirinator says:

    Sorry for being completely off topic, but you were wondering about anti-aliasing on OS X making coloured text look bolded... I only just noticed when looking at your site, but it looks like 10.4.2 has substantially changed the way text is rendered... this blog looks boo-tiful now :).

  8. grahams says:

    Update: No, scratch that, using interprogram-paste-function is useless. It seems that sometimes copying things in OSX programs updates the X11 clipboard, but not always. I can't figure out when it does and when it doesn't.

    Are you using Apple's 'quartz-wm' or another WM? If you are using another WM, there There is some coverage of how to enable selection proxying:


    If you are using quartz-wm, then I'm not sure why it's not always working (I don't use X11 enough)... I know you hate speculation, but I wonder if the reason why it sometimes works for you has to do with the API used to develop the OSX app (Carbon vs. Cocoa)... Nothing about this is mentioned in the above FAQ.

  9. baconmonkey says:

    recompile greasemonkey.