9

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
2
  • oh, output of echo $i is "Monday" . there just to check.
    – H_7
    Jan 23, 2012 at 22:12
  • Thanks Shellter, you just saved my day. =) Correct answer checked.
    – H_7
    Jan 24, 2012 at 5:02

1 Answer 1

11

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

8
  • YES, YES, YES! Great help shellter! I can't upvote your answer because I am too new yet on S.O. , but this literally solved my problem. Only thing I didn't understood yet, is: how 'echo $i' gave me "Monday" but only with your syntax I have this value too with xdotool?
    – H_7
    Jan 24, 2012 at 5:01
  • Maybe you be glad to know xdotool, its a very powerfull library/command (?) to simulate key and mouse movements, clicks, and more. Take a look at the project page. Maybe this pays a little for your help. Thanks again.
    – H_7
    Jan 24, 2012 at 5:04
  • Hi @H_7, glad to hear that helped, and thanks for the quick introduction to xdotool. I'm going to read up on it, as it seems like it will be really useful. Let me know if I can help again. Good luck!
    – shellter
    Jan 24, 2012 at 7:03
  • When you do i|date +'%A' nothing is happening between the i| and the following command. You are seeing the output of date '%A' and the i=| is getting thrown away. More technically, you're running two processes. a=... is inside the current process of your shell and expects a normal assignment like a="aValue", but the 2nd process (with a pipe) (date ...) just executes. There is nothing coming through the pipe. date '+%A' "echo"s out is value (just as if you typed it by itself on the command-line), without any regard to the a=| in front of it. I hope this makes sense. Good luck.
    – shellter
    Jan 24, 2012 at 7:13
  • Nice @shellter. Nice you liked xdotool, its really amazing. All makes a lot of sense except by this point: as you can see, on the 2nd line I have echo $i which prints out "Monday" (!). How, if I got nothing with i=|date +%A and also nothing later with xdotool type WeekDayIsi$ ?
    – H_7
    Jan 24, 2012 at 16:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.