Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keyboard type a variable using xdotool?

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 i variable) as a part of the filename to be saved........... hmmm --> "nothing happens". =(

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.

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.

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

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.

#!/bin/bash
i=|date +%A
echo $i
echo $i
echo $i

i=$(date +%A)

echo Yes$i
like image 665
H_7 Avatar asked Jan 23 '12 22:01

H_7


1 Answers

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.

change

i=|date +%A

to

i=$(date +%A)

Then when you execute your last line

xdotool type WeekDayIs$i

$i will have a value.

IHTH

like image 112
shellter Avatar answered Oct 21 '22 18:10

shellter