<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Structure in the flow &#187; linux</title>
	<atom:link href="http://www.fsavard.com/flow/tag/linux/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.fsavard.com/flow</link>
	<description>Programming, personal knowledge management. Topics unstable.</description>
	<lastBuildDate>Sat, 10 Dec 2011 20:38:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Using xsel, xbindkeys and xmacro to insert common strings (date, name, etc.) in Linux</title>
		<link>http://www.fsavard.com/flow/2008/06/using-xsel-xbindkeys-and-xmacro-to-insert-common-strings-date-name-etc-in-linux/</link>
		<comments>http://www.fsavard.com/flow/2008/06/using-xsel-xbindkeys-and-xmacro-to-insert-common-strings-date-name-etc-in-linux/#comments</comments>
		<pubDate>Sun, 29 Jun 2008 22:28:49 +0000</pubDate>
		<dc:creator>Francois</dc:creator>
				<category><![CDATA[Technical tips]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[tip]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://gator461.hostgator.com/~fsavard/blog/?p=10</guid>
		<description><![CDATA[Goal: insert a date string (e.g. &#8220;2008/06/29&#8243;) in almost whatever text area/graphical program I&#8217;m using currently with a single keyboard shortcut. Basic principle: copy the date string to the clipboard and emulate the Ctrl-V key combination, which activates the Paste operation in most programs. Limitations: The current program must support Ctrl-V as the Paste shortcut [...]]]></description>
			<content:encoded><![CDATA[<p><strong>G</strong><strong>oal</strong>: insert a date string (e.g. &#8220;2008/06/29&#8243;) in almost whatever text area/graphical program I&#8217;m using currently with a single keyboard shortcut.</p>
<p><strong>Basic principle</strong>: copy the date string to the clipboard and emulate the Ctrl-V key combination, which activates the Paste operation in most programs.</p>
<p><strong>Limitations</strong>:</p>
<ul>
<li>The current program must support Ctrl-V as the Paste shortcut (won&#8217;t work on the command line, for example).</li>
<li>The <strong>current clipboard data is erased</strong>, replaced by the string inserted.</li>
</ul>
<h3>The bare steps I took</h3>
<p>I&#8217;m using Ubuntu, but I guess this should work with most distributions, by adapting the installation instructions.</p>
<p>1. I installed the necessary utilities.</p>
<pre>    sudo apt-get install xsel xbindkeys xbindkeys-config xmacro</pre>
<p>2. I created a default xbindkeys configuration file.</p>
<pre>    xbindkeys --defaults &gt; ~/.xbindkeysrc</pre>
<p>3. I wrote this <a href="http://www.fsavard.com/files/insert_date.sh" target="_blank"><strong>shell script</strong></a>, which I saved on my local disk.</p>
<p>4. I configured xbindkeys using xbindkeys-config to launch the script when the Windows-D shortcut is pressed.</p>
<p style="padding-left: 30px;">a. I loaded &#8220;xbindkeys-config&#8221; by typing that on the command line.</p>
<p style="padding-left: 30px;">b. I created a new shortcut and associated it with the script.</p>
<p style="text-align: center;"><a href="http://www.fsavard.com/images/xbindkeys-config_screenshot.jpg" target="_blank"><img src="http://www.fsavard.com/images/xbindkeys-config_screenshot_tn.jpg" alt="" width="600" height="372" /></a></p>
<p style="padding-left: 30px;">c. I associated it with the Windows-D shortcut by pressing &#8220;Get Key&#8221; and then pressing Windows-D.</p>
<p style="padding-left: 30px;">d. I saved and exited.</p>
<p style="padding-left: 30px;">e. I arranged it so the &#8220;xbindkeys&#8221; command would run on every logon, which can be done by adding the line &#8220;xbindkeys&#8221; to a logon script (/home/&#8230;/.bash_profile, for example).</p>
<h3>The underlying explanations</h3>
<p>I often find it useful to insert the date in personal notes I take. So often, in fact, that it&#8217;s quite handy to automate the insertion. On Windows, there&#8217;s this handy app and scripting language called AutoIT which may be used to automate common tasks. But under Linux, quick googling doesn&#8217;t reveal any self-evident choice for an all-encompassing scripting language, so I went looking into more application-specific options.</p>
<p>The first key element to my solution, <strong>xsel</strong>, is a program that allows one to control the X selection and clipboard from the command line. The second utility, <strong>xbindkeys</strong> (and its configuration GUI, xbindkeys-config), as you guessed, allows you to associate keyboard shortcuts to commands. Finally, <strong>xmacro</strong> is a program that allows you to emulate specific keyboard key events, like key presses, and mouse events.</p>
<p>I therefore associated (using xbindkeys) a keyboard shortcut to a script that copies the date string to the clipboard (using xsel) and emulates the Paste keyboard shortcut (using xmacro). That&#8217;s a pretty complicated solution, but all in all it didn&#8217;t take so much time to set up. I commented the script so you may get a better understanding of the parameters used.</p>
<p>I could have used other shortcuts that Windows-D, but the Windows key isn&#8217;t used under Ubuntu, so this was a great occasion to capitalize on keyboard real estate.</p>
<p>As an <strong>alternative approach</strong>, which doesn&#8217;t replace the clipboard data, you can use xmacro to insert every single character in the date string, one at a time. I began by doing this, since it&#8217;s much simpler. The problem I ran into is instability: some programs need a delay between keypresses, otherwise they mix up the letters, and the insertion seems slow and sometimes misses letters. That limitation prompted me to try this solution.</p>
<p>If anyone has a suggestion as to how to improve this solution, feel free to post a comment about it.</p>
<h3>Further reading and references</h3>
<ul>
<li><a href="http://whynotwiki.com/GNU/Linux_/_Desktop">http://whynotwiki.com/GNU/Linux_/_Desktop</a>: useful information and examples on the use of xmacro, xbindkeys</li>
</ul>
 <img src="http://www.fsavard.com/flow/wp-content/plugins/feed-statistics.php?view=1&post_id=10" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://www.fsavard.com/flow/2008/06/using-xsel-xbindkeys-and-xmacro-to-insert-common-strings-date-name-etc-in-linux/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

