<?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>Matt [Danger] &#187; Mac OS X</title>
	<atom:link href="http://mattdanger.net/tag/mac-os-x/feed/" rel="self" type="application/rss+xml" />
	<link>http://mattdanger.net</link>
	<description>One step closer to world domination</description>
	<lastBuildDate>Wed, 25 Apr 2012 02:09:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Safari 5 hanging on page loads</title>
		<link>http://mattdanger.net/2010/09/safari-5-hanging-on-page-loads/</link>
		<comments>http://mattdanger.net/2010/09/safari-5-hanging-on-page-loads/#comments</comments>
		<pubDate>Tue, 14 Sep 2010 17:22:07 +0000</pubDate>
		<dc:creator>Matt Danger</dc:creator>
				<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[terminal]]></category>
		<category><![CDATA[Safari 5]]></category>

		<guid isPermaLink="false">http://mattdanger.net/?p=289</guid>
		<description><![CDATA[Is your Safari 5 hanging when loading pages? Try switching your DNS servers or dumping your Safari cache: rm -r ~/Library/Caches/com.apple.Safari]]></description>
			<content:encoded><![CDATA[<p>Is your Safari 5 <a href="http://discussions.info.apple.com/thread.jspa?threadID=2453384">hanging when loading pages</a>? Try <a href="http://discussions.info.apple.com/thread.jspa;jsessionid=97F2128925281CEA0817DC515B33471F.node0?messageID=11758096">switching your DNS servers</a> or dumping your Safari cache:</p>
<p><code>rm -r ~/Library/Caches/com.apple.Safari</code></p>
]]></content:encoded>
			<wfw:commentRss>http://mattdanger.net/2010/09/safari-5-hanging-on-page-loads/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scripting Login Tasks in Mac OS X</title>
		<link>http://mattdanger.net/2009/01/scripting-login-tasks-in-mac-os-x/</link>
		<comments>http://mattdanger.net/2009/01/scripting-login-tasks-in-mac-os-x/#comments</comments>
		<pubDate>Thu, 22 Jan 2009 03:19:49 +0000</pubDate>
		<dc:creator>Matt Danger</dc:creator>
				<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[terminal]]></category>
		<category><![CDATA[10.5]]></category>
		<category><![CDATA[GlobalLoginItems]]></category>
		<category><![CDATA[Leopard]]></category>
		<category><![CDATA[login items]]></category>
		<category><![CDATA[LoginHooks]]></category>
		<category><![CDATA[SystemLoginItems]]></category>

		<guid isPermaLink="false">http://mattdanger.net/?p=90</guid>
		<description><![CDATA[Recently I wanted to configure some of our lab computers to automatically configure printers when a user logged on. While reading Apple&#8217;s documentation to find a solution I learned about the possible ways to script login procedures in Mac OS X 10.5. Login Hooks The first method of scripting a login action is the use&#8230;]]></description>
			<content:encoded><![CDATA[<p>Recently I wanted to configure some of our lab computers to automatically configure printers when a user logged on. While reading Apple&#8217;s documentation to find a solution I learned about the possible ways to script login procedures in Mac OS X 10.5.</p>
<h3>Login Hooks</h3>
<p>The first method of scripting a login action is the use of a <strong>Login Hook</strong>. A Login Hook is a script that is executed immediately after the user logs on but before other login processes are performed. The script runs as root and needs to be chmod&#8217;d +x to be made executable. This feature has existed in OS X for some time and is handy for some account specific tasks.</p>
<p>To configure OS X to run your script run the following command as root in Terminal:</p>
<p><code>defaults write com.apple.loginwindow LoginHook /path/to/script</code> </p>
<p>This modifies root&#8217;s login window properties in <code>/var/root/Library/Preferences/</code>. In Leopard login hooks do not work in any other user or system-wide com.apple.loginwindow preference file. I&#8217;m not sure if they did in previous versions.</p>
<p>More information about LoginHooks can be found on <a href="http://support.apple.com/kb/HT2420">Apple&#8217;s developer site</a>.</p>
<h3>System Login Items (Deprecated)</h3>
<div>
<p>SystemLoginItems was an old login script mechanism that has now been deprecated and will be removed in Snow Leopard. Scripts were executed when the Login Window was displayed and ran as root. When a user logged in the script died and was executed again as the user.</p>
<p>In Leopard SystemLoginItems behaves oddly. Applications do not launch upon login, instead they launch when the user logs out and attempt to run behind the Login Window.</p>
<p>Example usage of SystemLoginItems:</p>
<p><code>defaults write /Library/Preferences/com.apple.SystemLoginItems AutoLaunchedApplicationDictionary -array-add '{ "Path" = "/path/to/script"; "Hide" = 0; }'</code></p>
<p>SystemLoginItems was not well documented by Apple and it&#8217;s believed Apple created them specifically for a few developers. Now that Launchd exists SystemLoginItems is no longer necessary, likely the reason it is to be removed.</p>
<p>A brief discussion of SystemLoginItems can be found in <a href="http://lists.psu.edu/cgi-bin/wa?A2=ind0901&amp;L=macenterprise&amp;D=0&amp;T=0&amp;P=208243">this</a> MacEnterprise thread.</p>
<h3>Global Login Items</h3>
<p>GlobalLoginItems has superseded SystemLoginItems, and in some cases LoginHooks, as the best method for launching a login script. Unlike LoginHooks, a Global Login Item executes after all the login processes have completed and is meant for GUI applications. You can even configure whether you would like the application&#8217;s GUI to appear or not.</p>
<p>To configure a Global Login Item run the following command as root:</p>
<p><code>defaults write /Library/Preferences/loginwindow AutoLaunchedApplicationDictionary -array-add '{ "Path" = "/path/to/script"; "Hide" = "0"; }'</code></p>
<p>To remove the global login item either delete <code>/Library/Preferences/loginwindow</code> or run the following command as root:</p>
<p><code>defaults delete /Library/Preferences/loginwindow AutoLaunchedApplicationDictionary</code></p>
<p>Note that we are modifying the <code>loginwindow.plist</code> file and not the more popular <code>com.apple.loginwindow.plist</code> file. A reboot may also be required after deleting a global login item</p>
<p>More information about Login Items can be found in this <a href="http://developer.apple.com/technotes/tn2005/tn2083.html#SECGLOBALLOGINITEM">Apple Technical Note</a>.</div>
]]></content:encoded>
			<wfw:commentRss>http://mattdanger.net/2009/01/scripting-login-tasks-in-mac-os-x/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adjust Mac OS X display brightness from the Terminal</title>
		<link>http://mattdanger.net/2008/12/adjust-mac-os-x-display-brightness-from-the-terminal/</link>
		<comments>http://mattdanger.net/2008/12/adjust-mac-os-x-display-brightness-from-the-terminal/#comments</comments>
		<pubDate>Wed, 17 Dec 2008 20:24:16 +0000</pubDate>
		<dc:creator>Matt Danger</dc:creator>
				<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[display brightness]]></category>
		<category><![CDATA[terminal]]></category>

		<guid isPermaLink="false">http://mattdanger.net/?p=73</guid>
		<description><![CDATA[One of the classrooms I maintain is comprised of 2.4Ghz iMacs (MB323LL/A) that are dual booted with Windows XP and Mac OS X. Sometimes when the workstations are restarted from XP to OS X the display brightness gets changed to its dim power saver setting. This requires the user manually increase the display brightness by pressing the&#8230;]]></description>
			<content:encoded><![CDATA[<p>One of the classrooms I maintain is comprised of 2.4Ghz iMacs (MB323LL/A) that are dual booted with Windows XP and Mac OS X. Sometimes when the workstations are restarted from XP to OS X the display brightness gets changed to its dim power saver setting. This requires the user manually increase the display brightness by pressing the F2 key, which is inconvenient. I haven&#8217;t been able to determine the cause of this issue so I wanted to create a login hook to increases the brightness as a temporary fix.</p>
<p>OS X doesn&#8217;t ship with a command line utility that let&#8217;s you change display brightness. Fortunately, <a href="http://njr.sabi.net/">Nicholas Riley</a> has <a href="http://dev.sabi.net/svn/dev/trunk/LocationDo/brightness.c">written a utility</a> that uses OS X frameworks to accomplish this quickly and easily. Here&#8217;s the code:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include &lt;stdio.h&gt;</span>
<span style="color: #339900;">#include &lt;unistd.h&gt;</span>
<span style="color: #339900;">#include &lt;IOKit/graphics/IOGraphicsLib.h&gt;</span>
<span style="color: #339900;">#include &lt;ApplicationServices/ApplicationServices.h&gt;</span>
&nbsp;
<span style="color: #0000ff;">const</span> <span style="color: #0000ff;">int</span> kMaxDisplays <span style="color: #000080;">=</span> <span style="color: #0000dd;">16</span><span style="color: #008080;">;</span>
<span style="color: #0000ff;">const</span> CFStringRef kDisplayBrightness <span style="color: #000080;">=</span> CFSTR<span style="color: #008000;">&#40;</span>kIODisplayBrightnessKey<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #0000ff;">const</span> <span style="color: #0000ff;">char</span> <span style="color: #000040;">*</span>APP_NAME<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">void</span> errexit<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> <span style="color: #0000ff;">char</span> <span style="color: #000040;">*</span>fmt, ...<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
  <span style="color: #0000ff;">va_list</span> ap<span style="color: #008080;">;</span>
  <span style="color: #0000dd;">va_start</span><span style="color: #008000;">&#40;</span>ap, fmt<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000dd;">fprintf</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">stderr</span>, <span style="color: #FF0000;">&quot;%s: &quot;</span>, APP_NAME<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000dd;">vfprintf</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">stderr</span>, fmt, ap<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000dd;">fprintf</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">stderr</span>, <span style="color: #FF0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000dd;">exit</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">void</span> usage<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
  <span style="color: #0000dd;">fprintf</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">stderr</span>, <span style="color: #FF0000;">&quot;usage: %s [-m|-d display] [-v] &lt;brightness&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>, APP_NAME<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000dd;">fprintf</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">stderr</span>, <span style="color: #FF0000;">&quot;   or: %s -l [-v]<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>, APP_NAME<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000dd;">exit</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> argc, <span style="color: #0000ff;">char</span> <span style="color: #000040;">*</span> <span style="color: #0000ff;">const</span> argv<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
  APP_NAME <span style="color: #000080;">=</span> argv<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>argc <span style="color: #000080;">==</span> <span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span>
    usage<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
  <span style="color: #0000ff;">int</span> verbose <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">long</span> displayToSet <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">enum</span> <span style="color: #008000;">&#123;</span> ACTION_LIST, ACTION_SET_ALL, ACTION_SET_ONE <span style="color: #008000;">&#125;</span> action <span style="color: #000080;">=</span> ACTION_SET_ALL<span style="color: #008080;">;</span>
  <span style="color: #0000ff;">extern</span> <span style="color: #0000ff;">char</span> <span style="color: #000040;">*</span>optarg<span style="color: #008080;">;</span>
  <span style="color: #0000ff;">extern</span> <span style="color: #0000ff;">int</span> optind<span style="color: #008080;">;</span>
  <span style="color: #0000ff;">int</span> ch<span style="color: #008080;">;</span>
&nbsp;
  <span style="color: #0000ff;">while</span> <span style="color: #008000;">&#40;</span> <span style="color: #008000;">&#40;</span>ch <span style="color: #000080;">=</span> getopt<span style="color: #008000;">&#40;</span>argc, argv, <span style="color: #FF0000;">&quot;lmvd:&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">!</span><span style="color: #000080;">=</span> <span style="color: #000040;">-</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">switch</span> <span style="color: #008000;">&#40;</span>ch<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">case</span> <span style="color: #FF0000;">'l'</span><span style="color: #008080;">:</span>
      <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>action <span style="color: #000080;">==</span> ACTION_SET_ONE<span style="color: #008000;">&#41;</span> usage<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
      action <span style="color: #000080;">=</span> ACTION_LIST<span style="color: #008080;">;</span>
      <span style="color: #0000ff;">break</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">case</span> <span style="color: #FF0000;">'v'</span><span style="color: #008080;">:</span>
      verbose <span style="color: #000080;">=</span> <span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>
      <span style="color: #0000ff;">break</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">case</span> <span style="color: #FF0000;">'m'</span><span style="color: #008080;">:</span>
      <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>action <span style="color: #000040;">!</span><span style="color: #000080;">=</span> ACTION_SET_ALL<span style="color: #008000;">&#41;</span> usage<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
      action <span style="color: #000080;">=</span> ACTION_SET_ONE<span style="color: #008080;">;</span>
      displayToSet <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">long</span><span style="color: #008000;">&#41;</span>CGMainDisplayID<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
      <span style="color: #0000ff;">break</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">case</span> <span style="color: #FF0000;">'d'</span><span style="color: #008080;">:</span>
      <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>action <span style="color: #000040;">!</span><span style="color: #000080;">=</span> ACTION_SET_ALL<span style="color: #008000;">&#41;</span> usage<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
      action <span style="color: #000080;">=</span> ACTION_SET_ONE<span style="color: #008080;">;</span>
      <span style="color: #0000ff;">errno</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
      displayToSet <span style="color: #000080;">=</span> <span style="color: #0000dd;">strtoul</span><span style="color: #008000;">&#40;</span>optarg, <span style="color: #0000ff;">NULL</span>, <span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
      <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">errno</span> <span style="color: #000080;">==</span> EINVAL <span style="color: #000040;">||</span> <span style="color: #0000ff;">errno</span> <span style="color: #000080;">==</span> <span style="color: #0000ff;">ERANGE</span><span style="color: #008000;">&#41;</span>
	errexit<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;display must be an integer index (0) or a hexadecimal ID (0x4270a80)&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
      <span style="color: #0000ff;">break</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">default</span><span style="color: #008080;">:</span> usage<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  argc <span style="color: #000040;">-</span><span style="color: #000080;">=</span> optind<span style="color: #008080;">;</span>
  argv <span style="color: #000040;">+</span><span style="color: #000080;">=</span> optind<span style="color: #008080;">;</span>
&nbsp;
  <span style="color: #0000ff;">float</span> brightness<span style="color: #008080;">;</span>
  <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>action <span style="color: #000080;">==</span> ACTION_LIST<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>argc <span style="color: #000080;">&gt;</span> <span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span> usage<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #008000;">&#125;</span> <span style="color: #0000ff;">else</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>argc <span style="color: #000040;">!</span><span style="color: #000080;">=</span> <span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span> usage<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000ff;">errno</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
    brightness <span style="color: #000080;">=</span> strtof<span style="color: #008000;">&#40;</span>argv<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#93;</span>, <span style="color: #0000ff;">NULL</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">errno</span> <span style="color: #000080;">==</span> <span style="color: #0000ff;">ERANGE</span><span style="color: #008000;">&#41;</span>
      usage<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>brightness <span style="color: #000080;">&lt;</span> <span style="color: #0000dd;">0</span> <span style="color: #000040;">||</span> brightness <span style="color: #000080;">&gt;</span> <span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span>
      errexit<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;brightness must be between 0 and 1&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  CGDirectDisplayID display<span style="color: #008000;">&#91;</span>kMaxDisplays<span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
  CGDisplayCount numDisplays<span style="color: #008080;">;</span>
  CGDisplayErr err<span style="color: #008080;">;</span>
  err <span style="color: #000080;">=</span> CGGetActiveDisplayList<span style="color: #008000;">&#40;</span>kMaxDisplays, display, <span style="color: #000040;">&amp;</span>numDisplays<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>err <span style="color: #000040;">!</span><span style="color: #000080;">=</span> CGDisplayNoErr<span style="color: #008000;">&#41;</span>
    errexit<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;cannot get list of displays (error %d)<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>, err<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
  CFWriteStreamRef stdoutStream <span style="color: #000080;">=</span> <span style="color: #0000ff;">NULL</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>verbose<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    CFURLRef devStdout <span style="color: #000080;">=</span>
      CFURLCreateWithFileSystemPath<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">NULL</span>, CFSTR<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;/dev/stdout&quot;</span><span style="color: #008000;">&#41;</span>,
				    kCFURLPOSIXPathStyle, <span style="color: #0000ff;">false</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    stdoutStream <span style="color: #000080;">=</span> CFWriteStreamCreateWithFile<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">NULL</span>, devStdout<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>stdoutStream <span style="color: #000080;">==</span> <span style="color: #0000ff;">NULL</span><span style="color: #008000;">&#41;</span>
      errexit<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;cannot create CFWriteStream for /dev/stdout&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #000040;">!</span>CFWriteStreamOpen<span style="color: #008000;">&#40;</span>stdoutStream<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
      errexit<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;cannot open CFWriteStream for /dev/stdout&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #008000;">&#125;</span>								  
&nbsp;
  <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span>CGDisplayCount i <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> i <span style="color: #000080;">&lt;</span> numDisplays<span style="color: #008080;">;</span> <span style="color: #000040;">++</span>i<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    CGDirectDisplayID dspy <span style="color: #000080;">=</span> display<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
    CFDictionaryRef originalMode <span style="color: #000080;">=</span> CGDisplayCurrentMode<span style="color: #008000;">&#40;</span>dspy<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>originalMode <span style="color: #000080;">==</span> <span style="color: #0000ff;">NULL</span><span style="color: #008000;">&#41;</span>
      <span style="color: #0000ff;">continue</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>action <span style="color: #000080;">==</span> ACTION_LIST<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
      <span style="color: #0000dd;">printf</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;display %d: &quot;</span>, i<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
      <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>CGMainDisplayID<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">==</span> dspy<span style="color: #008000;">&#41;</span>
	<span style="color: #0000dd;">printf</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;main display, &quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
      <span style="color: #0000dd;">printf</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;ID 0x%x<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>, <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span><span style="color: #008000;">&#41;</span>dspy<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
      <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>verbose<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	CFStringRef error <span style="color: #000080;">=</span> <span style="color: #0000ff;">NULL</span><span style="color: #008080;">;</span>
	CFPropertyListWriteToStream<span style="color: #008000;">&#40;</span>originalMode, stdoutStream,
				    kCFPropertyListXMLFormat_v1_0, <span style="color: #000040;">&amp;</span>error<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>error <span style="color: #000040;">!</span><span style="color: #000080;">=</span> <span style="color: #0000ff;">NULL</span><span style="color: #008000;">&#41;</span>
	  errexit<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;failed to write display info (%s)&quot;</span>,
		  CFStringGetCStringPtr<span style="color: #008000;">&#40;</span>error,
					CFStringGetFastestEncoding<span style="color: #008000;">&#40;</span>error<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
      <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    io_service_t service <span style="color: #000080;">=</span> CGDisplayIOServicePort<span style="color: #008000;">&#40;</span>dspy<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">switch</span> <span style="color: #008000;">&#40;</span>action<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">case</span> ACTION_SET_ONE<span style="color: #008080;">:</span>
      <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>CGDirectDisplayID<span style="color: #008000;">&#41;</span>displayToSet <span style="color: #000040;">!</span><span style="color: #000080;">=</span> dspy <span style="color: #000040;">&amp;&amp;</span> displayToSet <span style="color: #000040;">!</span><span style="color: #000080;">=</span> i<span style="color: #008000;">&#41;</span>
	<span style="color: #0000ff;">continue</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">case</span> ACTION_SET_ALL<span style="color: #008080;">:</span>
      err <span style="color: #000080;">=</span> IODisplaySetFloatParameter<span style="color: #008000;">&#40;</span>service, kNilOptions, kDisplayBrightness,
				       brightness<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
      <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>err <span style="color: #000040;">!</span><span style="color: #000080;">=</span> kIOReturnSuccess<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	<span style="color: #0000dd;">fprintf</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">stderr</span>,
		<span style="color: #FF0000;">&quot;%s: failed to set brightness of display 0x%x (error %d)&quot;</span>,
		APP_NAME, <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span><span style="color: #008000;">&#41;</span>dspy, err<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">continue</span><span style="color: #008080;">;</span>
      <span style="color: #008000;">&#125;</span>
      <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #000040;">!</span>verbose<span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">continue</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">case</span> ACTION_LIST<span style="color: #008080;">:</span>
      err <span style="color: #000080;">=</span> IODisplayGetFloatParameter<span style="color: #008000;">&#40;</span>service, kNilOptions, kDisplayBrightness,
				       <span style="color: #000040;">&amp;</span>brightness<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
      <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>err <span style="color: #000040;">!</span><span style="color: #000080;">=</span> kIOReturnSuccess<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	<span style="color: #0000dd;">fprintf</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">stderr</span>,
		<span style="color: #FF0000;">&quot;%s: failed to get brightness of display 0x%x (error %d)&quot;</span>,
		APP_NAME, <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span><span style="color: #008000;">&#41;</span>dspy, err<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">continue</span><span style="color: #008080;">;</span>
      <span style="color: #008000;">&#125;</span>
      <span style="color: #0000dd;">printf</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;display %d: brightness %f<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>, i, brightness<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>You can compile your own utility by saving this code to a file named brightness.c and doing:</p>
<p><code>gcc -std=c99 -o brightness brightness.c -framework IOKit -framework ApplicationServices</code></p>
<p>You can also download the <a href="http://mattdanger.net/portfolio/utilities/brightness.tar.gz">precompiled binary</a>.</p>
<p>You can create a login hook to automatically increase the brightness by chmoding the downloaded &#8216;brightness&#8217; file to 755 and running the following command as root in Terminal:</p>
<p><code>defaults write com.apple.loginwindow LoginHook "/path/to/brightness 1"</code></p>
]]></content:encoded>
			<wfw:commentRss>http://mattdanger.net/2008/12/adjust-mac-os-x-display-brightness-from-the-terminal/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>A few Mac OS X tweaks you might not have known about</title>
		<link>http://mattdanger.net/2008/12/common-mac-os-x-tweaks/</link>
		<comments>http://mattdanger.net/2008/12/common-mac-os-x-tweaks/#comments</comments>
		<pubDate>Mon, 15 Dec 2008 16:01:12 +0000</pubDate>
		<dc:creator>Matt Danger</dc:creator>
				<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[defaults]]></category>
		<category><![CDATA[login window]]></category>

		<guid isPermaLink="false">http://mattdanger.net/?p=65</guid>
		<description><![CDATA[I&#8217;m a die hard Mac OS X user and also a lab administrator at a college. Over the years I&#8217;ve found several tweaks that help me configure both my personal computer and lab workstations to do different tasks. Force the printer icon to auto quit after a print job completes. Right-click on the icon and select&#8230;]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m a die hard Mac OS X user and also a lab administrator at a college. Over the years I&#8217;ve found several tweaks that help me configure both my personal computer and lab workstations to do different tasks.</p>
<p>Force the printer icon to auto quit after a print job completes. Right-click on the icon and select &#8220;Auto Quit&#8221; or do:<br />
<code>defaults write /Users/yourusername/Library/Preferences/com.apple.print.PrintingPrefs "Quit When Finished" -bool true</code></p>
<p>Disable disk checksum verification<br />
<code>defaults write com.apple.frameworks.diskimages skip-verify true</code></p>
<p>Gradient highlights for Stacks<br />
<code>defaults write com.apple.dock mouse-over-hilte-stack -boolean true</code></p>
<p>Add recent applications as a Stack on Dock<br />
<code>defaults write com.apple.dock persistent-others -array-add '{ "tile-data" = { "list-type" = 1; }; "tile-type" = "recents-tile"; }</code></p>
<p>Make extended print dialog show by default<br />
<code>defaults write -g PMPrintingExpandedStateForPrint -bool true</code></p>
<p>Change the current screenshot format<br />
<code>defaults write com.apple.screencapture type jpg</code></p>
<p>Disable iTunes store arrows<br />
<code>defaults write com.apple.iTunes show-store-arrow-links -bool false</code></p>
<p>Stop Safari &#8220;saved text&#8221; dialogs<br />
<code>defaults write com.apple.Safari DebugConfirmTossingUnsubmittedFormText NO</code></p>
<p>Force Safari to open all links in new tab<br />
<code>defaults write com.apple.Safari TargetedClicksCreateTabs -bool true</code></p>
<p>Disable application crash dialogs<br />
<code>defaults write com.apple.CrashReporter DialogType none</code></p>
<p>Make hidden Dock icons transparent<br />
<code>defaults write com.apple.Dock showhidden -bool true</code></p>
<p>Disable Dashboard<br />
<code>defaults write com.apple.dashboard mcx-disabled -boolean true</code></p>
<p>Stop disk image verification<br />
<code>defaults write com.apple.frameworks.diskimages skip-verify true</code></p>
<p>Enable Data Detectors in 10.5 iChat<br />
<code>defaults write com.apple.iChat EnableDataDetectors true</code></p>
<p>Modify Sheet Animation<br />
<code>defaults write NSGlobalDomain NSWindowResizeTime .001</code></p>
<h3>Login window tweaks</h3>
<p>The text underneath the &#8220;Mac OS X&#8221; title of the login window will change if you click on it. You can configure the login window to display any of these as default. Valid options are HostName, SystemVersion, SystemBuild, SerialNumber, IPAddress, DSStatus, or Time<br />
<code>defaults write /Library/Preferences/com.apple.loginwindow AdminHostInfo Time</code></p>
<p>You can add a message to the login window. This is useful in a lab environment when you need to give instructions to your users.<br />
<code>defaults read /Library/Preferences/com.apple.loginwindow LoginwindowText "Some custom message."</code></p>
]]></content:encoded>
			<wfw:commentRss>http://mattdanger.net/2008/12/common-mac-os-x-tweaks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

