自动化捕抓当前终端会话

在此之前我先把code写在下面。code中如果你在程序中出现问题就看code前的注意,我在执行时出现以下错误。

1:在我标注红色字体的是最容易出错的地方,因为它直接影响你的捕抓当前窗口的大小,也只有这个地方要你改的,但该起来容易,主要是在分析,看分析这个code?

2:但你按照程序的如入是会出现这个错误,就是“xwininfo 帮助信息”。原因出在哪儿?

3:出错原因就是你的[color=red]当前终端会话标题[/color],把下面的红色字体,改为你当前终端会话标题,但又不能乱改。怎么改才合理?

4:使用"xwininfo -root -tree" 这个命令,来获取你的当前终端会话窗口,看下面一行,就是我的当前会话id 窗口名 (括号里的你不用管) Width[color=red]x[/color]Height+0+0 +x+y,(其中的x和y就是程序里的了),这样就找到了我的当前会话窗口了,然后把code的红色字体改了你的当前会话名,就可以了。

0x2600019 [color=red]"Desktop : bash": [/color]("konsole" "Konsole") 843x591+0+0 +470+50

#!/bin/bash

# A simple shell script wrapper to record current terminal session of a linux

# desktop. May work under other Unix like operating systems too.

# Tested on RHEL 6.x, Debian 6.x, and Ubuntu Linux

# ----------------------------------------------------------------------------

# Written by Vivek Gite <http://www.cyberciti.biz/> 这是原代码官方

# (c) 2012 nixCraft under GNU GPL v2.0+

# ----------------------------------------------------------------------------
# Last updated: 19/Aug/2012
# ----------------------------------------------------------------------------


_xw=/usr/bin/xwininfo

_recd=/usr/bin/recordmydesktop

_awk=/usr/bin/awk

_grep=/bin/grep

_file="$1"

_output=""

# change this to match your PS1 settings

[color=red]_regex='"Desktop : bash":'[/color]

die(){

echo -e "$1"

exit ${2:9999}

}

[ $# -eq 0 ] && die "Usage: $0 filename.ogv\n\nRecord terminal desktop sessions under Linux or Unix." 1

# add extension .ogv if not given

_ext="${_file%%.ogv}"

[[ "$_ext" == "$_file" ]] && _output="$_file.ogv" || _output="$_file"


[ ! -x "$_xw" ] && die "Error: $_xw not found or set correct \$_xw in $0" 2

[ ! -x "$_recd" ] && die "Error: $_recd not found or set correct \$_recd in $0" 3

[ ! -x "$_awk" ] && die "Error: $_awk not found or set correct \$_awk in $0" 4

[ ! -x "$_grep" ] && die "Error: $_grep not found or set correct \$_grep in $0" 5


#get terminal window id

_id=$($_xw -root -tree | $_grep "$_regex" | $_awk '{ print $1}')


#get terminal windows x,y, width, and hight

_x=$($_xw -id $_id | $_grep 'Absolute upper-left X' | $_awk '{ print $4}')

_y=$($_xw -id $_id | $_grep 'Absolute upper-left Y' | $_awk '{ print $4}')

_w=$($_xw -id $_id | $_grep 'Width:' | $_awk '{ print $2}')

_h=$($_xw -id $_id | $_grep 'Height:' | $_awk '{ print $2}')

x=$(( $_x + 8 ))

y=$(( $_y + 57 ))

width=$(( $_w -31 ))

height=$(( $_h -62 ))

$_recd --no-sound -x $x -y $y --width $width --height $height -o $_output


怎么使用代码?这里我原文里的不翻译了。

Open a terminal.
Open Tab.
Run script as:
./script.sh foo.ogv

Switch to tab # 1 and run your command.
When done switch back to tab #2 and press CTRL + C to save recording to foo.ogv.

To run foo.ogv type:
gnome-open foo.ogv
or
mplayer foo.ogv

[color=red]More aritcle about linux Link:http://note.sdo.com/u/_mr.jian/[/color]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值