Scripting for X Productivity
Returning to the URL example, we can pass a URL to a browser without typing by using xclip, which captures the last mouse selection and echoes it. We put it together with the utility gnome-moz-remote, which either starts a new instance of Mozilla or opens the given URL with your already-running Mozilla. Put the following command in a script:
gnome-moz-remote --newwin "'xclip -o'" \ &> /dev/null &
Call it start_browser.sh, and bind it to a macro to run it from the application that must be enabled to launch external clients. In mutt, such a macro could be:
macro pager \cn "!start_browser.sh\n" 'open URL'
At this point, whenever we see a URL inside mutt, we'll simply highlight it with the mouse and press Ctrl-N. Inside the script, xclip echoes the selected text, and everything is as if we had started the browser by hand and then typed that text in the Location window.
xclip has a couple of distant cousins, xclipboard and xcutsel, that manage the X clipboard and cut buffer. These two programs are useful when it is necessary to see the clipboard content and to move the selection between applications that don't support them. Check the related man pages for more information.
How do we make X believe we are moving the cursor with the mouse and using its buttons when we actually are pressing or releasing keys? The xbut program performs both these tasks. You can set up a simple configuration file to make keys work like mouse movements or clicks.
It is possible to go even farther with xwit, the X Window Interactive Tool, which directly places the X pointer to an absolute screen position. Besides warping the pointer, xwit moves and iconifies windows. To iconify the current xterm, sleep, and then pop it back up, use:
xwit -iconify; sleep 2; xwit -pop
This tool can be handy for long-running tasks; substitute the program name for the sleep command, and it will iconify the window, do the work and get back in your face when it's done.
Finally, a flexible X-automation tool is xte, part of the xautomation package. Use xte -h to see a list of the X events it supports. This example goes to a point 320 pixels from the left edge of the screen and 50 pixels down and then fakes a click there with button 1:
xte 'mousemove 320 50' 'mousedown 1' 'mouseup 1'
A fast and effective environment is one in which you can start any authorized process (whether in the background or interactive, text or GUI-based) on every other machine to which you have access as quickly, securely and transparently as possible. Of course, the right way to do it is through OpenSSH. But even if you're using RSA or DSA authentication for security—and to save having to remember a password per host—you have to type your SSH passphrase for every connection. Luckily, a valuable SSH partner, ssh-agent, remembers your SSH private key or keys and takes over the job of performing any authentication that requires the private key. Practically speaking, this means if you start X as a child process of ssh-agent, every local X client started later is able to use ssh-agent for authentication.
You can start your window manager as a child of ssh-agent in .xinitrc or .Xsession; put ssh-agent before the window manager. If you have sawfish, change it to ssh-agent sawfish, and everything that runs in your X session, including any SSH programs, will be able to use ssh-agent.
GNOME starts ssh-agent by default. To add it to KDE, find your KDE startup script and add ssh-agent to it as you would for a window manager.
The ssh-add command is the one that actually makes available identities known to the agent. You can make sure ssh-agent is running and knows your identity with ssh-add -L.
If the computer is left unattended, everybody walking by has immediate access, no questions asked, to all hosts where you can log in. Log out, or use ssh-add -D to delete your identity from the agent.
Articles about Digital Rights and more at http://stop.zona-m.net CV, talks and bio at http://mfioretti.com
Webinar: 8 Signs You’re Beyond Cron
11am CDT, April 29th
Join Linux Journal and Pat Cameron, Director of Automation Technology at HelpSystems, as they discuss the eight primary advantages of moving beyond cron job scheduling. In this webinar, you’ll learn about integrating cron with an enterprise scheduler.Join us!
|Android Candy: Intercoms||Apr 23, 2015|
|"No Reboot" Kernel Patching - And Why You Should Care||Apr 22, 2015|
|Return of the Mac||Apr 20, 2015|
|DevOps: Better Than the Sum of Its Parts||Apr 20, 2015|
|Play for Me, Jarvis||Apr 16, 2015|
|Drupageddon: SQL Injection, Database Abstraction and Hundreds of Thousands of Web Sites||Apr 15, 2015|
- Tips for Optimizing Linux Memory Usage
- "No Reboot" Kernel Patching - And Why You Should Care
- DevOps: Better Than the Sum of Its Parts
- Return of the Mac
- Android Candy: Intercoms
- Drupageddon: SQL Injection, Database Abstraction and Hundreds of Thousands of Web Sites
- Non-Linux FOSS: .NET?
- Play for Me, Jarvis
- Designing Foils with XFLR5