Author |
Message |
technosaurus

Joined: 18 May 2008 Posts: 4786 Location: Kingwood, TX
|
Posted: Sun 08 Jul 2012, 04:23 Post subject:
xdotool |
|
xdotool is one of those invaluable tools for automating desktop tasks. but it can also be used for much more demanding works such as providing an interface to keyboard only viewer such as in vlc-gtk
here is an example that will activate firefox/seamonkey and paste the clipboard contents into the url bar:
Code: | #!/bin/sh
xdotool search --classname Navigator \
windowactivate --sync key --delay 250 ctrl+t ctrl+k ctrl+v Return |
Description |
|

Download |
Filename |
xdotool.tar.gz |
Filesize |
30.27 KB |
Downloaded |
1624 Time(s) |
_________________ Check out my github repositories. I may eventually get around to updating my blogspot.
|
Back to top
|
|
 |
sc0ttman

Joined: 16 Sep 2009 Posts: 2571 Location: UK
|
Posted: Sun 08 Jul 2012, 07:46 Post subject:
|
|
Fancy hacking the source to get the following command working?
Code: | xdotool search --name "VLC" behave %@ mouse-click exec 'myscript' |
It should run 'myscript' when you click on a VLC (nogui) playback window... But it doesn't...
_________________ Akita Linux, VLC-GTK, Pup Search, Pup File Search
|
Back to top
|
|
 |
miriam

Joined: 06 Dec 2006 Posts: 362 Location: Queensland, Australia
|
Posted: Thu 06 Sep 2012, 07:26 Post subject:
another nice use for xdotool, improving text editors |
|
I'd grown progressively more and more impatient with geany (well, to more accurate, all text editors) and lack of extensibility. Today I was editing a fairly long text file and adding some simple html markup. After a while, the inability to easily put bold, or other tags around a bit of highlighted text was really starting to bug me.
I knew I could use xclip to fiddle with the clipboard (I use it in a nice little script to rename files from the context menu, but more of that another time), however I was unable to paste the clip back into the text in the editor... until I realised xdotool could be used to do that. Yay!
So, I wrote the tiny, 2-line script below: Code: | #! /bin/sh
# ht_b
# miriam 2012-09-06
# adds bold tags around a selection of text in any text editor
xclip -o | sed 's/^/<b>/' | sed 's/$/<\/b>/' | xclip -selection clipboard
xdotool type "`xclip -out -selection clipboard`" | The script is put in the command path and I drop the icon for it on my desktop. Now, when I want to put bold tags around any text in any editor, I highlight the text and click on the "ht_b" icon on the desktop and it replaces the highlighted text with the same text but with html bold tags around it.
It probably isn't necessary, but I'll briefly explain how it works:
"xclip -o" takes the current selection (what I've highlighted in the text editor window) and pipes it to sed where "<b>" is added to the beginning ("^" is the regular expression for start-of-line), then this is piped to another sed command where "</b>" is added to the end ("$" is the regular expression for end-of-line), then this is piped to xclip where it is put into the clipboard.
The next line uses xdotool to type into the active window at the cursor, replacing the currently selected text. What it types in is taken from the clipboard through xclip again. Simple, huh? Well, it looks simple, but you wouldn't believe the hair-pulling it took me to get to this.
I've made a number of other small scripts to do the same for other tags (italic, headlines 1/2/3, and blockquote) and I've put their icons on the desktop too. Clicking on them is a lot easier than hand-editing editing arbitrary text. (It would be even easier if I could get keyboard shortcuts to work properly too instead of having to mouse-click on an icon, but I can't stop the keyboard shortcuts from producing multiple events.)
Another itch scratched.
_________________ A life! Cool! Where can I download one of those from?
|
Back to top
|
|
 |
seaside
Joined: 11 Apr 2007 Posts: 917
|
Posted: Fri 07 Sep 2012, 23:43 Post subject:
Re: another nice use for xdotool, improving text editors |
|
miriam wrote: |
I've made a number of other small scripts to do the same for other tags (italic, headlines 1/2/3, and blockquote) and I've put their icons on the desktop too. Clicking on them is a lot easier than hand-editing editing arbitrary text. (It would be even easier if I could get keyboard shortcuts to work properly too instead of having to mouse-click on an icon, but I can't stop the keyboard shortcuts from producing multiple events.)
Another itch scratched.  |
miriam.
Here's another way to scratch
Code: | #!/bin/sh
# substitute a selection with <tag>selection</tag>
# assign script to hotkey
SEL=`Xdialog --no-tags --stdout --title "List of Tags" \
--menu "Please Choose a Tag:" 20 51 4 \
"b" "Bold" \
"i" "Italic" \
"h2" "Large Heading" \
"p" "Paragraph" \
"hr" "Horizontal Rule" \
"br" "Line Break"`
xclip -o | sed 's/^/<'"$SEL"'>/' | sed 's/$/<\/'"$SEL"'>/' | xclip -selection clipboard
xdotool key ctrl+v |
Cheers,
s
|
Back to top
|
|
 |
miriam

Joined: 06 Dec 2006 Posts: 362 Location: Queensland, Australia
|
Posted: Sat 08 Sep 2012, 09:12 Post subject:
|
|
Nice idea!
Multiple choice slows my editing, but is much more compact than having several icons on the desktop.
I think I'll use it for less commonly needed tags. Thank you!
_________________ A life! Cool! Where can I download one of those from?
|
Back to top
|
|
 |
sc0ttman

Joined: 16 Sep 2009 Posts: 2571 Location: UK
|
Posted: Sat 08 Sep 2012, 11:44 Post subject:
|
|
sc0ttman wrote: | Fancy hacking the source to get the following command working?
Code: | xdotool search --name "VLC" behave %@ mouse-click exec 'myscript' |
|
yeah sc0ttman, good idea!
_________________ Akita Linux, VLC-GTK, Pup Search, Pup File Search
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 4786 Location: Kingwood, TX
|
Posted: Sat 08 Sep 2012, 13:56 Post subject:
|
|
for more commonly used actions, I like to set up a jwm hotkey (for instance Ctrl+g to google the clipboard in default browser)
defaultbrowser https://www.google.com/search?q=${CLIPBOARD// /+}
_________________ Check out my github repositories. I may eventually get around to updating my blogspot.
|
Back to top
|
|
 |
seaside
Joined: 11 Apr 2007 Posts: 917
|
Posted: Sat 08 Sep 2012, 18:25 Post subject:
|
|
sc0ttman wrote: | sc0ttman wrote: | Fancy hacking the source to get the following command working?
Code: | xdotool search --name "VLC" behave %@ mouse-click exec 'myscript' |
|
yeah sc0ttman, good idea! |
scOttman,
He sure does have good ideas
Would this do-
Code: | xdotool search --name "VLC" behave %@ focus exec echo Yes |
Strickly speaking, it's not "mouse-click, but it does fire whenever clicked...
technosaurus:,
That's a handy technique. Also Parcellite can perform actions with clipboard/selection items and have them assigned to it's own hotkey.
Regards,
s
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 4786 Location: Kingwood, TX
|
Posted: Sun 21 Oct 2012, 02:56 Post subject:
|
|
annoying mouse fun
Code: | while :; do xdotool mousemove_relative -- -$(($RANDOM % 10)) $(($RANDOM % 10)); xdotool mousemove_relative -- $(($RANDOM % 10)) -$(($RANDOM % 10)); done |
_________________ Check out my github repositories. I may eventually get around to updating my blogspot.
|
Back to top
|
|
 |
goingnuts
Joined: 07 Dec 2008 Posts: 903
|
Posted: Sun 21 Oct 2012, 09:44 Post subject:
|
|
technosaurus wrote: | annoying mouse fun | Yeah - kind of shaking...attached - for now quite untested - static build of xdotool-2.20110530.1
|
Back to top
|
|
 |
musher0

Joined: 04 Jan 2009 Posts: 12072 Location: Gatineau (Qc), Canada
|
Posted: Sun 21 Oct 2012, 09:53 Post subject:
|
|
technosaurus wrote: | annoying mouse fun
Code: | while :; do xdotool mousemove_relative -- -$(($RANDOM % 10)) $(($RANDOM % 10)); xdotool mousemove_relative -- $(($RANDOM % 10)) -$(($RANDOM % 10)); done |
|
People with Parkinson's won't think it's funny !!!
Cure here is simply cntrl-C, luckily.
_________________ musher0
~~~~~~~~~~
"Logical entities must not be multiplied beyond necessity." | |
« Il ne faut pas multiplier les entités logiques sans nécessité. » (Ockham)
|
Back to top
|
|
 |
greengeek

Joined: 20 Jul 2010 Posts: 4933 Location: Republic of Novo Zelande
|
Posted: Tue 20 Nov 2012, 14:39 Post subject:
|
|
Thanks for the xdotool file. I have tried placing it in /usr/bin and /usr/sbin and it seems to work regardless of which of those two places I put it. Which location would you recommend please? Does it matter? Thanks
|
Back to top
|
|
 |
miriam

Joined: 06 Dec 2006 Posts: 362 Location: Queensland, Australia
|
Posted: Fri 23 Nov 2012, 18:29 Post subject:
|
|
Hi greengeek. I'm not sure how much of the following you know, so I'll just rattle on about it and you can take what you want from it.
The $PATH variable shows all the places your computer looks for executable programs that you can run without having to type their location, for example the "echo" command is probably in /bin but you don't need to tell the machine where it is in order for Linux to find it. You can show the $PATH variable by typing into a terminal, and you can see that /bin is listed there, along with /usr/bin and /usr/sbin and a number of other places.
The $PATH variable is usually defined in your /etc/profile file, though it can be added to and modified at any time, which can be dangerous. A while back I installed a program which wrecked my $PATH and caused my system to suddenly not recognise many of the programs on my machine. It took me quite a while to track down. Instead of using the standard method of extending the PATH Code: | PATH=$PATH:/the/new/dir/of/programs | they simply gave the new dir without including the old $PATH but luckily it defined the new $PATH in an additional file called /etc/profile.local. I just commented the damaging lines out and my machine was good after the next reboot.
Why do some programs go in some directories and not others? It seems to be a mix of history and whim of the programmer who writes the installer script. I think /sbin and /usr/sbin and /usr/local/sbin are supposedly reserved for "system" programs, but you can find any kind of program in there. (After all, how exactly does one define a "system" program?) All the bin directories (and there are lots of them) hold all kinds of executables and script programs. It is a bit of a mess. I think the base level executables (/bin and /sbin) hold files that the system needs during boot-up. The deeper level ones, such as those in /usr and /usr/local are supposedly related to files made available for multiple users. The main focus of Puppy is as a single-user OS so this is less important for us.
For the standard rationalisations, see http://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard
For the real reasons, see http://www.osnews.com/story/25556/Understanding_the_bin_sbin_usr_bin_usr_sbin_Split/
I've long felt the Linux filing system needed an overhaul. It is not likely to happen though. It surprises me how conservative Linux enthusiasts can be and how much anger can be provoked by such suggestions. My personal feeling is that Linux is simply a tool -- a brilliant tool. It seems to me that the better a tool is, the more important it should be that we not let it get rusty. I think this is the great value of Puppy Linux. Barry Kauler, and the community of people who've come together with Puppy, have produced an efficient, fast, tool that works far more effectively than most Linuxes, but there will always remain more to be done.
_________________ A life! Cool! Where can I download one of those from?
|
Back to top
|
|
 |
greengeek

Joined: 20 Jul 2010 Posts: 4933 Location: Republic of Novo Zelande
|
Posted: Fri 23 Nov 2012, 19:25 Post subject:
|
|
Oh My Gosh. Thanks Miriam. I had no idea of the complexity behind what I was asking. I wondered why no-one had chimed in with a quick answer...
Thanks for taking the time to expand my knowledge base.
EDIT:
OK, so it seems that echo $path and echo $PATH are different things...Now I have to worry about lowercase versus uppercase??? Tccchhh! I'll never get the hang of this stuff...
EDIT again:
Ha! I had to laugh at his description of the Linux filesystem:
Quote: | This is like buying a beautiful car, only to realise the engine is made of cake and rotting brocolli. ..Mac OS X is especially egregious in this regard - open a terminal and check the directory listing at root - it's an even bigger mess than regular UNIX. |
|
Back to top
|
|
 |
miriam

Joined: 06 Dec 2006 Posts: 362 Location: Queensland, Australia
|
Posted: Fri 23 Nov 2012, 19:57 Post subject:
|
|
Don't worry. It is surprising how quickly you'll get used to the operating system being case-sensitive. Case-insensitive operating systems cause all kinds of subtle problems.
Some commands in Linux allow you to look for things in a case-insensitive way, for example: Code: | find ./ -iname "*txt" | looks in the current directory (./) and below for files ending in "txt", regardless of uppercase or lowercase. It will find hello.txt, SomeTxt, BLAH.TXT, and so on in any directory deeper than the directory the command was issued from.
Coming from an operating system that doesn't see the distinction between upper and lower case feels confusing at first, but after a little while you'll wonder how you put up with it. It becomes particularly annoying when dealing with VFAT-formatted thumbdrives. If you try to put two different files, "readme" and "README" on it then VFAT can't see the difference and will want to overwrite one of them. Be careful.
VFAT also imposes annoying limitations on the letters you can use in filenames (no ? or : or various other characters). Infuriating when giving files to MSWindows friends.
_________________ A life! Cool! Where can I download one of those from?
|
Back to top
|
|
 |
|