Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Fri 25 Jul 2014, 03:06
All times are UTC - 4
 Forum index » Advanced Topics » Additional Software (PETs, n' stuff) » Utilities
xdotool
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
Page 1 of 1 Posts_count  
Author Message
technosaurus


Joined: 18 May 2008
Posts: 4278

PostPosted: 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
xdotool.tar.gz
Description 
gz

 Download 
Filename  xdotool.tar.gz 
Filesize  30.27 KB 
Downloaded  927 Time(s) 

_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send_private_message 
sc0ttman


Joined: 16 Sep 2009
Posts: 2372
Location: UK

PostPosted: 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... Sad

_________________
Akita Linux, VLC-GTK, Pup Search, Pup File Search
Back to top
View user's profile Send_private_message 
miriam


Joined: 06 Dec 2006
Posts: 268
Location: Queensland, Australia

PostPosted: 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! Very Happy

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. Smile

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. Smile

_________________
A life! Cool! Where can I download one of those from?
Back to top
View user's profile Send_private_message Visit_website 
seaside

Joined: 11 Apr 2007
Posts: 886

PostPosted: 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. Smile


miriam.

Here's another way to scratch Smile
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
View user's profile Send_private_message 
miriam


Joined: 06 Dec 2006
Posts: 268
Location: Queensland, Australia

PostPosted: 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! Smile

_________________
A life! Cool! Where can I download one of those from?
Back to top
View user's profile Send_private_message Visit_website 
sc0ttman


Joined: 16 Sep 2009
Posts: 2372
Location: UK

PostPosted: 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
View user's profile Send_private_message 
technosaurus


Joined: 18 May 2008
Posts: 4278

PostPosted: 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// /+}

_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send_private_message 
seaside

Joined: 11 Apr 2007
Posts: 886

PostPosted: 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 Very Happy

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
View user's profile Send_private_message 
technosaurus


Joined: 18 May 2008
Posts: 4278

PostPosted: 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

_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send_private_message 
goingnuts

Joined: 07 Dec 2008
Posts: 779

PostPosted: 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
xdotool-2.20110530.1_static.tar.gz
Description 
gz

 Download 
Filename  xdotool-2.20110530.1_static.tar.gz 
Filesize  95.93 KB 
Downloaded  489 Time(s) 
Back to top
View user's profile Send_private_message Visit_website 
musher0


Joined: 04 Jan 2009
Posts: 4228
Location: Gatineau (Qc), Canada

PostPosted: 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 !!! Laughing
Cure here is simply cntrl-C, luckily. Smile

_________________
"Logical entities must not be multiplied needlessly." / "Il ne faut pas multiplier les êtres logiques inutilement." (Ockham)
Back to top
View user's profile Send_private_message Visit_website 
greengeek

Joined: 20 Jul 2010
Posts: 2406
Location: New Zealand

PostPosted: 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
View user's profile Send_private_message 
miriam


Joined: 06 Dec 2006
Posts: 268
Location: Queensland, Australia

PostPosted: 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. Smile

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
Code:
echo $PATH
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
View user's profile Send_private_message Visit_website 
greengeek

Joined: 20 Jul 2010
Posts: 2406
Location: New Zealand

PostPosted: 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. Smile

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
View user's profile Send_private_message 
miriam


Joined: 06 Dec 2006
Posts: 268
Location: Queensland, Australia

PostPosted: 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
View user's profile Send_private_message Visit_website 
Display_posts:   Sort by:   
Page 1 of 1 Posts_count  
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » Advanced Topics » Additional Software (PETs, n' stuff) » Utilities
Jump to:  

Rules_post_cannot
Rules_reply_cannot
Rules_edit_cannot
Rules_delete_cannot
Rules_vote_cannot
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1107s ][ Queries: 13 (0.0091s) ][ GZIP on ]