<?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>programmer</title>
	<atom:link href="http://programmer.aleksandarsabo.com/feed" rel="self" type="application/rss+xml" />
	<link>http://programmer.aleksandarsabo.com</link>
	<description>Just another programmer weblog</description>
	<lastBuildDate>Thu, 23 Jun 2011 12:38:15 +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>Detect User idle time on Mac OS X</title>
		<link>http://programmer.aleksandarsabo.com/code-snippets/detect-user-idle-time-on-mac-os-x</link>
		<comments>http://programmer.aleksandarsabo.com/code-snippets/detect-user-idle-time-on-mac-os-x#comments</comments>
		<pubDate>Wed, 25 Aug 2010 15:00:48 +0000</pubDate>
		<dc:creator>Aleksandar Sabo</dc:creator>
				<category><![CDATA[Code snippets]]></category>
		<category><![CDATA[c/c++]]></category>
		<category><![CDATA[os-x]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[xcode]]></category>

		<guid isPermaLink="false">http://programmer.aleksandarsabo.info/?p=35</guid>
		<description><![CDATA[When you're developing an application to track time or some work done on a computer, you need to know how long that user was actually in front of the screen, working on a task. If user has left his seat, your application should detect that and pause the timer.]]></description>
			<content:encoded><![CDATA[<p>When you&#8217;re developing an application to track time or some work done on a computer, you need to know how long that user was actually in front of the screen, working on a task. If user has left his seat, your application should detect that and pause the timer.</p>
<p>This can be done by comparing user idle time with predefined amount of seconds, for which we are shure that user is left his place, usualy 300 or 600 seconds (5-10 minutes).</p>
<p>The idle time is stored as a property of the IOHIDSystem class; the name is HIDIdleTime. It&#8217;s stored as a 64-bit int, measured in nanoseconds. To figure out the idle time of the system we use IOKit. Here&#8217;s the code that will return how long user was inactive in seconds:</p>
<p><code><br />
</code></p>
<pre><code>
<pre class="brush: cpp; title: ; notranslate">
#include &lt;IOKit/IOKitLib.h&gt;
#include &lt;CoreFoundation/CFNumber.h&gt;

/**
Returns the number of seconds the machine has been idle or -1 if an error occurs.
The code is compatible with Tiger/10.4 and later (but not iOS).
*/
int64_t SystemIdleTime(void) {
	int64_t idlesecs = -1;
	io_iterator_t iter = 0;
	if (IOServiceGetMatchingServices(kIOMasterPortDefault, IOServiceMatching(&quot;IOHIDSystem&quot;), &amp;iter) == KERN_SUCCESS) {
		io_registry_entry_t entry = IOIteratorNext(iter);
		if (entry)  {
			CFMutableDictionaryRef dict = NULL;
			if (IORegistryEntryCreateCFProperties(entry, &amp;dict, kCFAllocatorDefault, 0) == KERN_SUCCESS) {
				CFNumberRef obj = (CFNumberRef) CFDictionaryGetValue(dict, CFSTR(&quot;HIDIdleTime&quot;));
				if (obj) {
					int64_t nanoseconds = 0;
					if (CFNumberGetValue(obj, kCFNumberSInt64Type, &amp;nanoseconds)) {
						idlesecs = (nanoseconds / 1000000000); // Convert from nanoseconds to seconds.
					}
				}
				CFRelease(dict);
			}
			IOObjectRelease(entry);
		}
		IOObjectRelease(iter);
	}
	return idlesecs;
}</pre>
<p></code></pre>
<p><code><br />
</code><br />
This code has been <a href="http://www.danandcheryl.com/2010/06/how-to-check-the-system-idle-time-using-cocoa" target="_blank">released</a> as public domain, so you are free to copy it and use it for your own projects.</p>
<p>&nbsp;</p>
<p>In the end I just want to point out the two things:</p>
<ul>
<li>If you need &#8220;user idle time&#8221; in other units then seconds, you need to change the divisor in line:</li>
</ul>
<pre class="brush: cpp; first-line: 20; title: ; notranslate">
idlesecs = (nanoseconds / 1000000000); // Slower and accurate
</pre>
<ul>
<li>If you need dirty speedup of this code and you don&#8217;t need really accurate time you can change calculation from  to:</li>
</ul>
<p><code><br />
</code></p>
<pre><code>
<pre class="brush: cpp; first-line: 20; title: ; notranslate">
idlesecs = (nanoseconds &gt;&gt; 30); // Faster
</pre>
<p></code></pre>
<p><code><br />
</code><br />
<strong>Note</strong>: To use this code in X Code project, you need to add frameworks:</p>
<p>&nbsp;</p>
<ul>
<li>IOKit.framework</li>
<li>CoreFoundation.framework</li>
</ul>
<p><img class="size-full wp-image-49 alignnone" title="Add framework" src="http://programmer.aleksandarsabo.com/uploads/2010/08/Screen-shot-2010-08-25-at-14.29.01.png" alt="" width="500" height="307" /></p>



Share:


	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fprogrammer.aleksandarsabo.com%2Fcode-snippets%2Fdetect-user-idle-time-on-mac-os-x&amp;title=Detect%20User%20idle%20time%20on%20Mac%20OS%20X&amp;notes=When%20you%27re%20developing%20an%20application%20to%20track%20time%20or%20some%20work%20done%20on%20a%20computer%2C%20you%20need%20to%20know%20how%20long%20that%20user%20was%20actually%20in%20front%20of%20the%20screen%2C%20working%20on%20a%20task.%20If%20user%20has%20left%20his%20seat%2C%20your%20application%20should%20detect%20that%20and%20pause%20the%20timer." title="del.icio.us"><img src="http://programmer.aleksandarsabo.com/wordpress/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fprogrammer.aleksandarsabo.com%2Fcode-snippets%2Fdetect-user-idle-time-on-mac-os-x&amp;title=Detect%20User%20idle%20time%20on%20Mac%20OS%20X" title="StumbleUpon"><img src="http://programmer.aleksandarsabo.com/wordpress/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=Detect%20User%20idle%20time%20on%20Mac%20OS%20X%20-%20http%3A%2F%2Fprogrammer.aleksandarsabo.com%2Fcode-snippets%2Fdetect-user-idle-time-on-mac-os-x" title="Twitter"><img src="http://programmer.aleksandarsabo.com/wordpress/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fprogrammer.aleksandarsabo.com%2Fcode-snippets%2Fdetect-user-idle-time-on-mac-os-x&amp;t=Detect%20User%20idle%20time%20on%20Mac%20OS%20X" title="Facebook"><img src="http://programmer.aleksandarsabo.com/wordpress/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://programmer.aleksandarsabo.com/code-snippets/detect-user-idle-time-on-mac-os-x/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Daemon Tools Lite &#8211; Mount images on your Computer</title>
		<link>http://programmer.aleksandarsabo.com/instructions/daemon-tools-lite-mount-images-on-your-computer</link>
		<comments>http://programmer.aleksandarsabo.com/instructions/daemon-tools-lite-mount-images-on-your-computer#comments</comments>
		<pubDate>Sat, 22 May 2010 18:50:44 +0000</pubDate>
		<dc:creator>Aleksandar Sabo</dc:creator>
				<category><![CDATA[Instructions]]></category>
		<category><![CDATA[begginer]]></category>
		<category><![CDATA[install]]></category>
		<category><![CDATA[mounting]]></category>

		<guid isPermaLink="false">http://programmer.aleksandarsabo.info/instructions/daemon-tools-lite-mount-images-on-your-computer</guid>
		<description><![CDATA[DAEMON Tools is an advanced application for Microsoft Windows which provides optical media emulation. DAEMON Tools enables you to use your CD/DVD images as if they were already burned to CD/DVD.
]]></description>
			<content:encoded><![CDATA[<p><strong>Level</strong>: <em>Beginner</em></p>
<p>DAEMON Tools is an advanced application for Microsoft Windows which provides optical media emulation. DAEMON Tools enables you to use your CD/DVD images as if they were already burned to CD/DVD.</p>
<p><img style="border: 0px initial initial;" src="http://programmer.aleksandarsabo.com/uploads/2010/05/00-daemon.jpg" border="0" alt="00-daemon" width="490" height="369" /></p>
<p>There are three version of Daemon Tools software: <em><strong>Daemon Tools Pro Advanced</strong></em>, <em><strong>Daemon Tools Pro Standard</strong></em> and <em><strong>Daemon Tools Lite</strong></em>.<br />
<span id="more-5"></span></p>
<p>Version we are interested in is <strong><em>Daemon Tools Lite. </em></strong>It enables you to emulate up to 4 Virtual CD/DVD drives on your PC and to create image files from original disks inserted in physical drives.</p>
<p>This software is free if you going to use it at home personally and not for commercial purpose.</p>
<p>For more information about this software visit product page: <strong><a href="http://www.daemon-tools.cc/eng/products/dtLite" target="_blank">Daemon Tools Lite</a></strong>.</p>
<h2><strong>Install Instructions</strong></h2>
<p>Here is the instruction how to install Daemon Tools Lite and how to mount image in Virtual Disk.</p>
<p><strong>Step 1</strong></p>
<p>Open <a href="http://www.daemon-tools.cc/eng/products/dtLite">http://www.daemon-tools.cc/eng/products/dtLite</a> in your browser.</p>
<p><img style="border: 0px initial initial;" src="http://programmer.aleksandarsabo.com/uploads/2010/05/01-daemon-tools-lite.jpg" border="0" alt="01-daemon-tools-lite" width="450" height="283" /></p>
<p>Click on a Download link at the end of the page.</p>
<p><img style="border: 0px initial initial;" src="http://programmer.aleksandarsabo.com/uploads/2010/05/02-dtlite-download.jpg" border="0" alt="02-dtlite-download" width="447" height="86" /></p>
<p><img style="border: 0px initial initial;" src="http://programmer.aleksandarsabo.com/uploads/2010/05/03-dtlite-download-2.jpg" border="0" alt="03-dtlite-download-2" width="450" height="121" /></p>
<p><strong>Step 2</strong></p>
<p>Start installation and install Daemon Tools Lite</p>
<p><img style="border: 0px initial initial;" src="http://programmer.aleksandarsabo.com/uploads/2010/05/04-dtl-welcome.jpg" border="0" alt="04-dtl-welcome" width="450" height="350" /></p>
<p><img style="border: 0px initial initial;" src="http://programmer.aleksandarsabo.com/uploads/2010/05/05-dtl-license.jpg" border="0" alt="05-dtl-license" width="450" height="350" /></p>
<p><img style="border: 0px initial initial;" src="http://programmer.aleksandarsabo.com/uploads/2010/05/06-dtl-license-type.jpg" border="0" alt="06-dtl-license-type" width="450" height="350" /></p>
<p><img style="border: 0px initial initial;" src="http://programmer.aleksandarsabo.com/uploads/2010/05/07-dtl-components.jpg" border="0" alt="07-dtl-components" width="450" height="350" /></p>
<p>Uncheck Browser&#8217;s Start Page</p>
<p><img style="border: 0px initial initial;" src="http://programmer.aleksandarsabo.com/uploads/2010/05/08-dtl-support.jpg" border="0" alt="08-dtl-support" width="450" height="350" /></p>
<p>You can leave default location or you can select new one where you want program to be installed.</p>
<p><img style="border: 0px initial initial;" src="http://programmer.aleksandarsabo.com/uploads/2010/05/09-dtl-location.jpg" border="0" alt="09-dtl-location" width="450" height="350" /></p>
<p><img style="border: 0px initial initial;" src="http://programmer.aleksandarsabo.com/uploads/2010/05/10-dtl-install-progress.jpg" border="0" alt="10-dtl-install-progress" width="450" height="350" /></p>
<p>Select Don&#8217;t Intall if you don&#8217;t need Desktop Gadget</p>
<p><img style="border: 0px initial initial;" src="http://programmer.aleksandarsabo.com/uploads/2010/05/11-dtl-desktop-gadget.jpg" border="0" alt="11-dtl-desktop-gadget" width="414" height="266" /></p>
<p><img style="border: 0px initial initial;" src="http://programmer.aleksandarsabo.com/uploads/2010/05/12-dtl-finished.jpg" border="0" alt="12-dtl-finished" width="450" height="350" /></p>
<h2>Mount Image Instructions</h2>
<p><strong>Step 3.</strong></p>
<p>Double click DAEMON Tools Lite icon on your Desktop to start the program</p>
<p><img style="border: 0px initial initial;" src="http://programmer.aleksandarsabo.com/uploads/2010/05/13-daemon-tools-icon.jpg" border="0" alt="13-daemon-tools-icon" width="76" height="103" /></p>
<p>DAEMON Tools Lite icon is show in taskbar.</p>
<p><strong>Step 4.</strong></p>
<p>Right click on DAEMON Tools icon in taskbar and select Virtual Devices &gt; Add SCSI Virtual Device.</p>
<p><img style="border: 0px initial initial;" src="http://programmer.aleksandarsabo.com/uploads/2010/05/14-add-scsi-virtual-device.jpg" border="0" alt="14-add-scsi-virtual-device" width="410" height="273" /></p>
<p>New Virtual drive is enabled and ready.</p>
<p><strong>Step 5</strong></p>
<p>Load image to created virtual drive. Right click om DAEMON Tools icon in taskbar and select Virtual Devices &gt; Device X: No Media &gt; Mount Image&#8230;</p>
<p><img style="border: 0px initial initial;" src="http://programmer.aleksandarsabo.com/uploads/2010/05/15-mount-image.jpg" border="0" alt="15-mount-image" width="410" height="240" /></p>
<p>Select image dialog is opened. Browse for image file on your computer to load it to virtual drive.</p>
<p><img style="border: 0px initial initial;" src="http://programmer.aleksandarsabo.com/uploads/2010/05/16-select-image-file.jpg" border="0" alt="16-select-image-file" width="450" height="338" /></p>
<p><strong>Step 6</strong></p>
<p>New Drive is now present in your Computer directory. Now you can use it as any other drive.</p>
<p><img style="border: 0px initial initial;" src="http://programmer.aleksandarsabo.com/uploads/2010/05/17-new-drive-in-computer.jpg" border="0" alt="17-new-drive-in-computer" width="450" height="338" /></p>



Share:


	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fprogrammer.aleksandarsabo.com%2Finstructions%2Fdaemon-tools-lite-mount-images-on-your-computer&amp;title=Daemon%20Tools%20Lite%20-%20Mount%20images%20on%20your%20Computer%20%20%20&amp;notes=DAEMON%20Tools%20is%20an%20advanced%20application%20for%20Microsoft%20Windows%20which%20provides%20optical%20media%20emulation.%20DAEMON%20Tools%20enables%20you%20to%20use%20your%20CD%2FDVD%20images%20as%20if%20they%20were%20already%20burned%20to%20CD%2FDVD.%0D%0A" title="del.icio.us"><img src="http://programmer.aleksandarsabo.com/wordpress/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fprogrammer.aleksandarsabo.com%2Finstructions%2Fdaemon-tools-lite-mount-images-on-your-computer&amp;title=Daemon%20Tools%20Lite%20-%20Mount%20images%20on%20your%20Computer%20%20%20" title="StumbleUpon"><img src="http://programmer.aleksandarsabo.com/wordpress/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=Daemon%20Tools%20Lite%20-%20Mount%20images%20on%20your%20Computer%20%20%20%20-%20http%3A%2F%2Fprogrammer.aleksandarsabo.com%2Finstructions%2Fdaemon-tools-lite-mount-images-on-your-computer" title="Twitter"><img src="http://programmer.aleksandarsabo.com/wordpress/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fprogrammer.aleksandarsabo.com%2Finstructions%2Fdaemon-tools-lite-mount-images-on-your-computer&amp;t=Daemon%20Tools%20Lite%20-%20Mount%20images%20on%20your%20Computer%20%20%20" title="Facebook"><img src="http://programmer.aleksandarsabo.com/wordpress/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://programmer.aleksandarsabo.com/instructions/daemon-tools-lite-mount-images-on-your-computer/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

