`

解决 google chrome 浏览器里复制的内容不能粘贴到vmware workstation虚拟机里的问题

阅读更多

解决 google chrome 浏览器里复制的内容不能粘贴到vmware workstation虚拟机里的问题

1、现象:

ubuntu 上安装的google chrome 浏览器复制的内容不能粘贴到vmware workstation虚拟机里,但能正常复制到其他地方,如gedit里:

google chrome 里复制内容 ---粘贴---》vmware workstation虚拟机 (不能

google chrome 里复制内容 ---粘贴---》其他地方,如gedit里(正常

发现发生问题的软件版本:

ubuntu 14.04 + google chrome (36,37的版本都会,35正常) + vmware workstation 10.0.3 build-1895310(虚拟 windows 8.1 32位)

 

2、解决办法:

论坛上发现的老外搞的办法,用python来在后台监视剪贴板变化,发现是chrome引起的就运行“xsel -o -b|xsel -i -p;xsel -o -p|xsel -i -b”命令,具体原理后面在去了解,先分享方法出来给难兄难弟,呵呵。

老外脚本地址(由衷感谢他的分享大笑):

https://gist.github.com/solariz/2ec85f1f8fe0d4f44b6f

 

拿过来要改下,监控google chrome引起的剪贴板变化就行了,记得先安装xdotool和xsel

1、安装软件:

sudo apt-get install xdotool xsel

2、改脚本(脚本我命名为cpchrome.py)

3、运行脚本:

nohup python cpchrome.py &

4、google chrome 里复制内容 ---粘贴---》vmware workstation虚拟机 (OK,oo)

5、附上我改过的脚本cpchrome.py(“#sjw add”为我改过的地方):

#!/usr/bin/python
## License: CC0
## Author: Marco Goetze
## Web: http://solariz.de
## Version: 1.2
## DIZ:
## Little Helper Script for Linux to make my KeePass Copy and Paste cooperate again with
## Chrome Browser.
## You need to have the latest keepass version and XSEL installed.
## Tested with:
##     xsel 1.2.0
##  keepass 2.27
##  xdpyinfo 1.3.1
##  chrome 36
##  on Linux Mint Qiana (x64) on MATE and Cinnamon but should work on any gnome based desktop
##
## Plese see this chrome topic for discussion: https://productforums.google.com/forum/#!topic/chrome/4s5_Sx-e4z0
##
 
 
## You can edit this if needed, I use it since v1.2 to prevent the clipboard copy operation on each Copy Action
## it should only run when invoked by LastPass. To make this happen be sure you have 'xdotool' & 'xsel' installed
## apt-get install xdotool xsel
## without this script will not work!
##
#window_name_matches = ['KeePass', 'kdbx', 'Edit Entry', 'Add Entry'] #sjw change
window_name_matches = ['Google Chrome'] #sjw add
## no need for changes below here
from gi.repository import Gtk, Gdk
import subprocess
 
glob_inhalt = ""
print "KeePass Linux Clipboard Workaround"
print "Version 1.2 by Marco Goetze (www.solariz.de)"
 
def test(*args):
    global glob_inhalt
    found = False
    # Get Clipboard
    task = subprocess.Popen("xsel -o -b", shell=True, stdout=subprocess.PIPE)
    data = task.stdout.read()
    assert task.wait() == 0
    # check if changed
    if data != glob_inhalt:
        glob_inhalt = data
        print "Clipboard changed, checking if Lastpass Window is active..."
        task = subprocess.Popen("xdotool getactivewindow getwindowname", shell=True, stdout=subprocess.PIPE)
        winID = task.stdout.read().rstrip('\n')
        ##print winID
        winID = winID.rpartition('-')[2].strip()  #sjw add
        ##print winID
        for s in window_name_matches:
            if s in winID:
                found = True
 
        if found == True:
            print "Match detected, processing Clipboard..."
            # wtf... yes, this works. From Clipboard to Primaty to clipboard and chome have it in CTRL-V
            task = subprocess.Popen("xsel -o -b|xsel -i -p;xsel -o -p|xsel -i -b", shell=True, stdout=subprocess.PIPE)
            data = task.stdout.read()
            assert task.wait() == 0
        else:
            print "No Match."
 
clip = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
clip.connect('owner-change',test)
Gtk.main()

 

2015-10-28 最新重写版代码见 http://sjwpython.iteye.com/blog/2252843

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics