设为首页 收藏本站
查看: 1523|回复: 0

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

[复制链接]

尚未签到

发表于 2016-1-7 14:04:49 | 显示全部楼层 |阅读模式
解决 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”命令,具体原理后面在去了解,先分享方法出来给难兄难弟,呵呵。

老外脚本地址(由衷感谢他的分享 DSC0000.gif ):

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.iyunv.com/blog/2252843

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-161534-1-1.html 上篇帖子: VMWare 添加虚拟硬盘到 CentOS,自动挂载,清空磁盘 下篇帖子: 使用VMware虚拟机硬件安装Ubuntu 8.04 LTS 详细图解
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表