2

I want to let xdotool type the current date automatically and wrote this bash script as a first try:

#!/bin/bash          
STR="Hello World!"
xdotool type $STR

Unfortunately, it already fails at this point. It just types ... something ... Something like "<[<[<" or "H[ll==]l{₁". Why is this? How do I make it type a string or the current date (format: YYYY-MM-DD, so today is 2016-01-06)?

3
  • 1
    Strange, it works on my end. Can you do a quick test? Move your ~/.bashrc e.g. to ~/.bashrc.bak, copy a fresh .bashrc from /etc/skel to ~/, start a new Bash instance (exec bash) and try again. Does that still happen?
    – kos
    Commented Jan 6, 2016 at 13:00
  • Both the .bashrc in my home folder and the one in /etc/skel have the sha256sum 6fec775ff07e8424bbd774f8d6659dadfca37fd77ee66e2b9db92e3d045273ba. So it doesn't work. My .bashrc file isn't even modified.
    – UTF-8
    Commented Jan 6, 2016 at 16:43
  • I just tested it on a virtual machine (not Ubuntu, though) and it really worked. But it doesn't on my actual system.
    – UTF-8
    Commented Jan 6, 2016 at 16:53

2 Answers 2

0
#!/bin/bash          
xdotool type `date +%Y-%m-%d`
3
  • Thank you! I knew there was this way but I wasn't able to remember it. But can you tell me why typing the content of the variable didn't work?
    – UTF-8
    Commented Jan 6, 2016 at 16:45
  • It works in a terminal window but if I use it as a shortcut, (depending on the application) it either does nothing (GEdit), types some characters (it types +%-%-% into the dash), or has some other weird behavior (zooms out and kicks me out of the textarea I'm writing this in in Firefox).
    – UTF-8
    Commented Jan 6, 2016 at 16:59
  • I now accepted this as an answer because it works on my Ubuntu 16.04 system.
    – UTF-8
    Commented Apr 29, 2016 at 12:21
0

I used STR="Hello World!" && xdotool type $STR which seemed to work. Not sure why yours didn't work. if you want to debug bash scripts you can use the shell built-in set -xv to get verbose details.

#!/bin/bash          
set -xv
STR="Good Bye Cruel World!"  && xdotool type $STR
1
  • It prints this: pastebin.com/ugE6C1Gg Which is ... kind of even more confusing, I guess ...
    – UTF-8
    Commented Jan 12, 2016 at 21:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .