bash 如何使用 xdotool 键盘输入变量?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8979332/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to keyboard type a variable using xdotool?
提问by H_7
I am coding a little script to save some data from Internet every single day.
So I am using xdotool to simulate all my navigation until the point I have the save window of firefox in front of me, I mean, in front of my script. OK, all right until here... But, when I try to use the day of the week(or any data in the ivariable) as a part of the filename to be saved........... hmmm --> "nothing happens". =(
我正在编写一个小脚本来每天从 Internet 保存一些数据。所以我使用 xdotool 来模拟我的所有导航,直到我面前有 Firefox 的保存窗口,我的意思是,在我的脚本前面。好的,直到这里...但是,当我尝试使用星期几(或i变量中的任何数据)作为要保存的文件名的一部分时.......嗯--> “什么也没发生”。=(
Well, I guess I have some simple problem here, I have tryed very ways to use the content of the variable I got with the date function, or simple pipe directly, but xdotool refuses to type this info into the filename box in save file window, which is obvius selected and text highlighted.
好吧,我想我这里有一些简单的问题,我已经尝试了很多方法来使用我通过日期函数或简单管道获得的变量的内容,但是 xdotool 拒绝将此信息输入到保存文件窗口的文件名框中,这是显而易见的选择并突出显示文本。
Some light in the path, Masters! I am a terrible noob! Sorry! =) So this is the code I tryed,(problem in last line):
路上有些光,大师们!我是一个可怕的菜鸟!对不起!=) 所以这是我试过的代码,(最后一行的问题):
#!/bin/bash
i=|date +%A
echo $i
WID=`xdotool search --name "Mozilla Firefox" | head -1`
xdotool windowactivate $WID
xdotool key ctrl+l
xdotool type "http://whatever.com.au"
xdotool key Return
sleep 2
xdotool key ctrl+s
sleep 2
xdotool type WeekDayIs$i
I guess I am missing something really obvius, maybe some typecasting....
我想我错过了一些非常明显的东西,也许是一些类型转换......
I'm really a begginner, so don't blame me so much. I tryed with "$i"and {"$i"}and '$'too.. nothing works... =/ Thanks everybody.
我真的是初学者,所以不要怪我。我tryed与"$i"和{"$i"}和'$'也..什么作品?= /谢谢大家。
ps: AND, if some nice dude want to point me out a straight way to save directly some web content to a file, maybe I walk on my knees to him.. ;-) EDIT : I got the answer to this question too here
ps:而且,如果有好心人想指出一种直接将某些 Web 内容保存到文件的方法,也许我会向他跪下…… ;-) 编辑:我也在这里得到了这个问题的答案
EDIT POS-SOLUTION:
编辑位置解决方案:
yes shellter, this code prints out Tuesday and YesTuesday and not 3 more times Tuesday. hehe, one day after another. Thanks for your attention.
是的shellter,此代码打印出星期二和YesTuesday,而不是星期二再打印3 次。呵呵,一天又一天。感谢您的关注。
#!/bin/bash
i=|date +%A
echo $i
echo $i
echo $i
i=$(date +%A)
echo Yes$i
回答by shellter
I don't know anything about xdotool, but one issue is obvious, correct this and then edit your post if it is not resolved, and include specific text of error messages.
我对 xdotool 一无所知,但有一个问题很明显,请更正此问题,然后在未解决的情况下编辑您的帖子,并包含错误消息的特定文本。
change
改变
i=|date +%A
to
到
i=$(date +%A)
Then when you execute your last line
然后当你执行你的最后一行
xdotool type WeekDayIs$i
$i will have a value.
$i 会有值。
I hope this helps.
我希望这有帮助。
P.S. Welcome to StackOverflow (S.O.) Please remeber to read the FAQs, vote for good Q/A by using the gray triangles, http://i.imgur.com/kygEP.png, and to accept the answer that bes solves your problem, if any, by pressing the checkmark sign , http://i.imgur.com/uqJeW.png
PS 欢迎使用 StackOverflow (SO) 请记住阅读常见问题解答,使用灰色三角形为好的 Q/A 投票, http://i.imgur.com/kygEP.png ,并接受可以解决您问题的答案,如果有的话,按复选标记,http://i.imgur.com/uqJeW.png

