<?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>The Baydin Blog &#124; Email, Startups, and Search &#187; script</title>
	<atom:link href="http://baydin.com/blog/tag/script/feed/" rel="self" type="application/rss+xml" />
	<link>http://baydin.com/blog</link>
	<description>Baydin takes the work out of email.</description>
	<lastBuildDate>Tue, 31 Jan 2012 01:55:43 +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>5 Sikuli Pitfalls (and how to avoid them!)</title>
		<link>http://baydin.com/blog/2010/06/5-sikuli-pitfalls-and-how-to-avoid-them/</link>
		<comments>http://baydin.com/blog/2010/06/5-sikuli-pitfalls-and-how-to-avoid-them/#comments</comments>
		<pubDate>Thu, 24 Jun 2010 16:21:11 +0000</pubDate>
		<dc:creator>Mario Maldonado</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[machine vision]]></category>
		<category><![CDATA[MIT]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[sikuli]]></category>

		<guid isPermaLink="false">http://baydin.com/blog/?p=207</guid>
		<description><![CDATA[Introduction Project Sikuli, a machine-vision research project from MIT, allows users to write scripts that automate UI-driven tasks. This tool, while very powerful and simple, can cause a number of headaches if you&#8217;re not careful. In this post, I&#8217;ll talk about some issues you might encounter, as well as how to avoid them. If you&#8217;ve ]]></description>
			<content:encoded><![CDATA[<h3>Introduction</h3>
<p><a href="http://groups.csail.mit.edu/uid/sikuli/" onclick="pageTracker._trackPageview('/outgoing/groups.csail.mit.edu/uid/sikuli/?referer=');">Project Sikuli</a>, a machine-vision research project from MIT, allows users to write scripts that automate UI-driven tasks. This tool, while very powerful and simple, can cause a number of headaches if you&#8217;re not careful. In this post, I&#8217;ll talk about some issues you might encounter, as well as how to avoid them. If you&#8217;ve never used Sikuli before, you can see demos <a href="http://groups.csail.mit.edu/uid/sikuli/demo.shtml" onclick="pageTracker._trackPageview('/outgoing/groups.csail.mit.edu/uid/sikuli/demo.shtml?referer=');">here</a>, or download the IDE <a href="http://groups.csail.mit.edu/uid/sikuli/download.shtml" onclick="pageTracker._trackPageview('/outgoing/groups.csail.mit.edu/uid/sikuli/download.shtml?referer=');">here</a>.</p>
<h3>5. Not <a href="http://sikuli.org/trac/wiki/reference-0.10#wait" onclick="pageTracker._trackPageview('/outgoing/sikuli.org/trac/wiki/reference-0.10_wait?referer=');">wait()</a>ing</h3>
<p>If you&#8217;re a long-time user of a particular program or operating system, you can probably describe many common tasks from memory. For example, I might describe how to access the &#8220;Uninstall or change a program&#8221; dialog in Windows 7 as follows:</p>
<ol>
<li>Click on the start menu</li>
<li>Click on &#8220;Control Panel&#8221;</li>
<li>Click on &#8220;Uninstall a Program&#8221; under the &#8220;Programs&#8221; heading</li>
</ol>
<p>If you&#8217;re new to Sikuli, you might be tempted to script this simple process like this:</p>
<p><a href="http://baydin.com/blog/wp-content/uploads/2010/06/UninstallWithoutWaits.png"><img class="alignnone size-full wp-image-208" src="http://baydin.com/blog/wp-content/uploads/2010/06/UninstallWithoutWaits.png" alt="How not to do it" width="230" height="128" /></a></p>
<p>You could then run your script and not notice a single issue for a long time. Then, one day, your computer is busy running multiple background tasks and you run your script again. The start menu takes a few seconds to display its contents, and your script raises an exception. The problem is that Sikuli doesn&#8217;t automatically wait for an image to be visible on-screen before trying to <a href="http://sikuli.org/trac/wiki/reference-0.10#click" onclick="pageTracker._trackPageview('/outgoing/sikuli.org/trac/wiki/reference-0.10_click?referer=');">click()</a> it, so if it doesn&#8217;t see &#8220;Control Panel&#8221; on your screen very soon after clicking on the start menu, it will raise an exception. In order to force it to behave properly, you&#8217;ll need to insert wait() statements:</p>
<p><a href="http://baydin.com/blog/wp-content/uploads/2010/06/UninstallWithWaits.png"><img class="alignnone size-full wp-image-209" src="http://baydin.com/blog/wp-content/uploads/2010/06/UninstallWithWaits.png" alt="A better way to do it" width="221" height="185" /></a></p>
<p>If you&#8217;ve added wait()s and you&#8217;re still having problems, try <a href="http://sikuli.org/trac/wiki/reference-0.10#wait" onclick="pageTracker._trackPageview('/outgoing/sikuli.org/trac/wiki/reference-0.10_wait?referer=');">setting a longer wait time</a>.</p>
<h3>4. Having trouble with context-sensitive/popup menus</h3>
<p>If you tried to follow along with the previous example, you likely ran into a problem when you tried to capture the &#8220;Control Panel&#8221; option in the start menu. After opening the start menu, switching focus back to the Sikuli IDE will cause the start menu to close, thwarting your effort to capture an image. Now, you could use PrintScreen while the start menu is open, paste the image into an image processor, and then use Sikuli to capture the image from the image processor, but thankfully, there&#8217;s a better way.</p>
<p>Sikuli installs hotkeys for common tasks like capturing an image (CTRL + SHIFT + 2 by default), and they don&#8217;t cause the current program to lose focus. So you can simply open the start menu/context-sensitive menu of your choice and use the hotkey to capture the screen. That way the menu won&#8217;t disappear in the process.</p>
<h3>3. click()ing when you should be <a href="http://sikuli.org/trac/wiki/reference-0.10#type" onclick="pageTracker._trackPageview('/outgoing/sikuli.org/trac/wiki/reference-0.10_type?referer=');">type()</a>ing</h3>
<p>Sikuli&#8217;s pretty good at finding stuff on-screen, but it&#8217;s still a costly and error-prone process. If you can navigate a user interface by emulating keystrokes rather than clicks, you&#8217;ll save yourself a lot of trouble. Typing also has the benefit of sending events sequentially to the current program&#8217;s <a href="http://en.wikipedia.org/wiki/Event-driven_programming" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Event-driven_programming?referer=');">event queue</a>, so if your program is stalling on something, your type() commands will wait for that task to be done, meaning you&#8217;ll run into problem #5 a lot less often. If you were to instead use click()s, you would have to tell your script in advance how long to wait() before it can take its next action, giving you inconsistent results if your machine is running slower than expected. Keep in mind that Sikuli can emulate <a href="http://sikuli.org/trac/wiki/reference-0.10#ModifierKeys" onclick="pageTracker._trackPageview('/outgoing/sikuli.org/trac/wiki/reference-0.10_ModifierKeys?referer=');">key modifiers</a>, <a href="http://sikuli.org/trac/wiki/reference-0.10#SpecialKeys" onclick="pageTracker._trackPageview('/outgoing/sikuli.org/trac/wiki/reference-0.10_SpecialKeys?referer=');">function keys, arrow keys, etc.</a>, so you can specify some pretty complex interactions using only type() commands.</p>
<h3>2. Forgetting that you&#8217;re using Python</h3>
<p>Sikuli is a powerful and flexible tool, but remember that Sikuli scripts are written in an incredibly powerful and flexible language. Before writing that fancy UI-driven script to do something simple like change the system date/time, consider that the same task can be done in about three lines in Python or a shell script, saving you a great deal of time and headache. Whenever a task seems unnecessarily complex in Sikuli, ask yourself if it might be better solved programmatically, rather than visually.</p>
<h3>1. Not knowing where to find help</h3>
<p>Since Sikuli is still in the early stages of development, finding online resources to help you can be very difficult, to say the least. Here are some of the pages that I find most useful when I&#8217;m writing Sikuli scripts:</p>
<ul>
<li><a href="http://sikuli.org/trac/wiki/reference-0.10" onclick="pageTracker._trackPageview('/outgoing/sikuli.org/trac/wiki/reference-0.10?referer=');">Documentation / Guide</a> &#8211; Perhaps the best Sikuli reference out there. Complete documentation of Sikuli, along with some example code.</li>
<li><a href="https://bugs.launchpad.net/sikuli" onclick="pageTracker._trackPageview('/outgoing/bugs.launchpad.net/sikuli?referer=');">Bug Reporting / Tracking</a> &#8211; Sikuli is still in beta. See if that problem you&#8217;re having is really a bug in Sikuli, not your script.</li>
<li><a href="http://blog.sikuli.org/" onclick="pageTracker._trackPageview('/outgoing/blog.sikuli.org/?referer=');">Blog</a> &#8211; Contains useful code examples and news</li>
<li><a href="https://answers.launchpad.net/sikuli" onclick="pageTracker._trackPageview('/outgoing/answers.launchpad.net/sikuli?referer=');">Q&amp;A</a> &#8211; If you&#8217;re having an issue, there might be someone else who&#8217;s been there before.</li>
</ul>
<p><em>[Mario is a summer intern with Baydin, and he is spending part of the summer automating functional tests for </em><a href="http://www.baydin.com/boomerang" onclick="pageTracker._trackPageview('/outgoing/www.baydin.com/boomerang?referer=');"><span style="font-weight: normal;"><em>Boomerang</em></span></a><span style="font-weight: normal;"><em> using Project Sikuli]</em></span></p>
]]></content:encoded>
			<wfw:commentRss>http://baydin.com/blog/2010/06/5-sikuli-pitfalls-and-how-to-avoid-them/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

