【发布时间】:2013-12-14 05:55:21
【问题描述】:
如何使 Google chrome 远程桌面自动化,以便可以远程初始化或从命令行初始化,让会话始终运行(不涉及使用 x11vnc、teamviewer、logmein)
为什么抛出异常失败:错误 - 无法打开 chrome 远程桌面会话?
我有这个 BASH 脚本,它可以打开 chromium-browser 并允许远程访问,但它无法启动。
$ /var/tmp/chromote.sh :0.0 此标志已弃用。假设您的意思是 --name (窗口名称)。 此标志已弃用。假设您的意思是 --name (窗口名称)。 错误 - 无法打开 chrome 远程桌面会话
#!/bin/bash
#
# chromote.sh - a simple bash script to start up chrome remote desktop
# sharing of the linux desktop automatically from a text
# terminal, and report back the access code.
#
# usage: bash> chromote.sh <X11_display>
# where <X11_display> is the value of the DISPLAY environment variable
# that you would use to send X11 commands to the desired screen.
#
# example: bash> chromote.sh :3
#
# author: richard.t.jones at uconn.edu
# version: july 20, 2013
#
# notes:
#
# 1. Besides a running X11 server, three other tools must be installed
# in order for the script to run. Both are available as standard
# linux packages and can be installed using the local package manager.
# Each of these are assumed to exist within the user's shell PATH.
# a. chrome - basic browser with remote desktop extension installed
# b. xdotool - general tool for simulating mouse and keyboard
# control events in a X11 environment.
# c. xclip - general tool for reading from and writing into the
# paste buffer in a X11 environment.
#
# 2. The chromote script works by automatically performing the mouse clicks
# that would be required to start up a chrome remote desktop session in
# the standard fashion. As such, it assumes a certain geometry of the
# google remote desktop sharing page, as well as the way windows pop up
# on the user's desktop. To accommodate random changes in either of
# these, the script supports a "calibration" mode. To calibrate, try
# bash> chromote.sh --calibrate <X11_display>
# these settings my be customized for each host
export DISPLAY=:0.0
chromeRD_URL="chrome-extension://gbchcmhmhahfdphkhkmpfmihenigjmpp/main.html"
urlWindowX=140
urlWindowY=80
okButtonX=339
okButtonY=386
shareButtonX=648
shareButtonY=366
codeLeftX=248
codeLeftY=424
codeRightX=449
codeRightY=423
copyItemX=483
copyItemY=436
minimizeWinX=632
minimizeWinY=40
# these are system preferences
chromeWinX=0
chromeWinY=0
chromeWinWidth=700
chromeWinHeight=900
function activate_browser() {
chromewin=
for winid in `xdotool search --title "Remote Desktop"`; do
chromewin=$winid
done
if [[ -z $chromewin ]]; then
chromium-browser >/dev/null 2>&1 &
sleep 5 # wait for window to appear, adjust as needed
chromewin=`xdotool getwindowfocus`
xdotool windowmove $chromewin $chromeWinX $chromeWinY
xdotool windowsize $chromewin $chromeWinWidth $chromeWinHeight
xdotool mousemove $urlWindowX $urlWindowY
xdotool click 1
xdotool click 1
xdotool click 1
xdotool type "$chromeRD_URL
"
sleep 5 # wait for page to load, adjust as needed
chromewin=`xdotool search --title "Remote Desktop"`
if [[ "$chromewin" = "" ]]; then
echo "Error - unable to open chrome remote destop session" >&2
exit 2
fi
fi
resp=`xdotool windowactivate $chromewin 2>&1`
[[ $resp = "" ]]
}
function calibrate() {
echo "Calibration procedure for chromote.sh is starting."
echo "If running this script in a terminal within your X11 display,"
echo "please move it to the right so that it remains visible when"
echo "the chrome browser window pops up. DO NOT move the chrome"
echo "browser window when it opens, because it needs to pop up in"
echo "exactly the same place on the screen each time it opens."
echo
echo -n "Press <enter> when ready:"
read resp
scriptwin=`xdotool getwindowfocus`
chromium-browser >/dev/null 2>&1 &
sleep 3
chromewin=`xdotool getwindowfocus`
xdotool windowmove $chromewin $chromeWinX $chromeWinY
xdotool windowsize $chromewin $chromeWinWidth $chromeWinHeight
xdotool windowmove $scriptwin `expr $chromeWinX + $chromeWinWidth` \
$chromeWinY
xdotool windowactivate $scriptwin
echo
echo "A new chrome browser window should have appeared on the screen."
echo "Go to the first tab and navigate to the chrome remote desktop"
echo "web page. If you have not installed it yet, you can find it"
echo "in the Google Store. Open a new tab if you need to. When you"
echo "reach the right page, there should be a green 'Share' button"
echo "near the right side of the page."
echo
echo "Now click on the window running this script to return the focus"
echo "here, then hover the mouse at a spot near the start of the url"
echo "at the top of the browser window as if you were going to"
echo "double-click it to type a new url. Do not click anything yet,"
echo "just position the mouse."
echo
echo -n "Press return to continue:"
read resp
loc=`xdotool getmouselocation`
urlWindowX=`echo $loc | awk -F'[ :]' '{print $2}'`
urlWindowY=`echo $loc | awk -F'[ :]' '{print $4}'`
xdotool mousemove $urlWindowX $urlWindowY
xdotool click 1
xdotool click 1
xdotool click 1
echo
echo "The url of the chrome remote desktop page should be highlighted"
echo "now in the window. If not, please hit Ctrl-C and start again."
echo "If it is, right-click with the mouse and select 'Copy' to save"
echo "the url in the paste buffer."
echo
echo -n "Select this window and press return to continue:"
read resp
chromeRD_URL=`xclip -o`
echo
echo "A button 'share' (maybe green) should be visible near the right"
echo "side of the page. Hover the mouse over the middle of the share,"
echo "button, but do not click it."
echo
echo -n "Press <enter> when ready:"
read resp
loc=`xdotool getmouselocation`
shareButtonX=`echo $loc | awk -F'[ :]' '{print $2}'`
shareButtonY=`echo $loc | awk -F'[ :]' '{print $4}'`
xdotool mousemove $shareButtonX $shareButtonY
xdotool click 1
echo "A popup window should have appeared, displaying in large"
echo "letters an access code for you to use when making the remote"
echo "connection. Position the mouse to the left of the numbers,"
echo "as if you were going to drag over them to highlight them, but"
echo "do not click anything."
xdotool windowactivate $scriptwin
echo
echo -n "Press <enter> when ready:"
read resp
loc=`xdotool getmouselocation`
codeLeftX=`echo $loc | awk -F'[ :]' '{print $2}'`
codeLeftY=`echo $loc | awk -F'[ :]' '{print $4}'`
echo
echo "Now move (not drag) the mouse over to the right side of the"
echo "number code and position it in the white space past the last digit."
echo
echo -n "Press <enter> when ready:"
read resp
loc=`xdotool getmouselocation`
codeRightX=`echo $loc | awk -F'[ :]' '{print $2}'`
codeRightY=`echo $loc | awk -F'[ :]' '{print $4}'`
xdotool mousemove $codeLeftX $codeLeftY
xdotool mousedown 1
sleep 1
xdotool mousemove $codeRightX $codeRightY
xdotool mouseup 1
xdotool click 3
echo
echo "The number code should now be highlighted, and a popup copy/paste"
echo "menu should be visible. You now have 5 seconds to position the"
echo "mouse over the 'Copy' option. Just hold it there, do not click."
echo
sleep 5
loc=`xdotool getmouselocation`
copyItemX=`echo $loc | awk -F'[ :]' '{print $2}'`
copyItemY=`echo $loc | awk -F'[ :]' '{print $4}'`
xdotool mousemove $copyItemX $copyItemY
xdotool click 1
sleep 1
xdotool click 1
code=`xclip -o`
echo
echo "The number code should be \"$code\". If this is not correct,"
echo "hit Ctrl-C now and start again. If everything worked so far,"
echo "position the mouse over the 'minimize window' square at the"
echo "top of the browser window."
echo
xdotool windowactivate $scriptwin
echo -n "Press <enter> when ready:"
read resp
loc=`xdotool getmouselocation`
minimizeWinX=`echo $loc | awk -F'[ :]' '{print $2}'`
minimizeWinY=`echo $loc | awk -F'[ :]' '{print $4}'`
echo
echo "Now stop the desktop sharing session by clicking on the 'Cancel'"
echo "button in the browser. A popup should have appeared saying that"
echo "sharing has stopped. Position the mouse in the middle of the"
echo "'ok' button in that popup, but do not click it."
echo
echo -n "Press <enter> when ready:"
read resp
loc=`xdotool getmouselocation`
okButtonX=`echo $loc | awk -F'[ :]' '{print $2}'`
okButtonY=`echo $loc | awk -F'[ :]' '{print $4}'`
xdotool mousemove $minimizeWinX $minimizeWinY
xdotool click 1
echo
echo "The desktop sharing window should have minimized itself to the"
echo "taskbar. If so, everything is correct, and you should copy/paste"
echo "the settings below into the header of the chromote.sh script,"
echo "replacing the defaults."
echo
echo "chromeRD_URL=\"$chromeRD_URL\""
echo "urlWindowX=$urlWindowX"
echo "urlWindowY=$urlWindowY"
echo "okButtonX=$okButtonX"
echo "okButtonY=$okButtonY"
echo "shareButtonX=$shareButtonX"
echo "shareButtonY=$shareButtonY"
echo "codeLeftX=$codeLeftX"
echo "codeLeftY=$codeLeftY"
echo "codeRightX=$codeRightX"
echo "codeRightY=$codeRightY"
echo "copyItemX=$copyItemX"
echo "copyItemY=$copyItemY"
echo "minimizeWinX=$minimizeWinX"
echo "minimizeWinY=$minimizeWinY"
exit 0
}
# make sure all necessary tools are available
for tool in chromium-browser xdotool xclip; do
if [[ ! -x `which $tool` ]]; then
echo "Required tool $tool not found in the user PATH" >&2
exit 1
fi
done
# parse command arguments
if [[ "$1" = "--calibrate" ]]; then
shift
export DISPLAY=$1
calibrate
elif [[ $# != 1 ]]; then
echo "Usage: chromote.sh [--calibrate] <X11_display>" >&2
exit 1
else
export DISPLAY=$1
fi
# look for an existing chrome browser open to the RD page,
# if none exists then start a new browser window
activate_browser
if [[ $? != 0 ]]; then
echo -n "Chrome Remote Desktop sharing session already connected"
echo " on display $1"
echo "Cancel the existing one before trying to create a new one!"
exit 1
fi
# click the OK button, in case an old session-closed message is pending
xdotool mousemove $okButtonX $okButtonY
xdotool click 1
sleep 1 # wait for the old session popup to go away, if any
# find the "SHARE" button and press it
xdotool mousemove $shareButtonX $shareButtonY
xdotool click 1
sleep 1 # wait for the new session popup to appear, adjust as needed
# highlight the access code string with the mouse
xdotool mousemove $codeLeftX $codeLeftY
xdotool mousedown 1
sleep 1 # pause for the drag motion to initiate, adjust as needed
xdotool mousemove $codeRightX $codeRightY
xdotool mouseup 1
# copy the highlighted string into the paste buffer
xdotool click 3
sleep 1 # wait for the copy/paste menu to appear, adjust as needed
xdotool mousemove $copyItemX $copyItemY
xdotool click 1
sleep 1 # wait for the copy/paste menu to go away, adjust as needed
# remove the highlighting by clicking in some white space
xdotool click 1
# shrink the chrome window to the taskbar
xdotool mousemove $minimizeWinX $minimizeWinY
xdotool click 1
# report the result and exit
echo the share code is `xclip -o`
exit 0
【问题讨论】:
标签: bash google-chrome ubuntu centos