<?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; Uncategorized</title>
	<atom:link href="http://mattdanger.net/category/uncategorized/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>Facebook-Status-2.2.pl released</title>
		<link>http://mattdanger.net/2011/09/facebook-status-2-2-released/</link>
		<comments>http://mattdanger.net/2011/09/facebook-status-2-2-released/#comments</comments>
		<pubDate>Thu, 08 Sep 2011 04:35:22 +0000</pubDate>
		<dc:creator>Matt Danger</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mattdanger.net/?p=350</guid>
		<description><![CDATA[I have updated my Facebook status script to version 2.2. Download it from here or view the source here. Facebook made a few changes the broke the previous version. Thanks to Cary Lewis for letting me know the previous version no longer worked!]]></description>
			<content:encoded><![CDATA[<p>I have updated my Facebook status script to version 2.2. Download it from <a href="http://mattdanger.net/portfolio/facebook-status/facebook-status-2.2.pl">here</a> or view the source <a href="http://mattdanger.net/2008/11/update-your-facebook-status-from-the-command-line/">here</a>. Facebook made a few changes the broke the previous version.</p>
<p>Thanks to Cary Lewis for letting me know the previous version no longer worked!</p>
]]></content:encoded>
			<wfw:commentRss>http://mattdanger.net/2011/09/facebook-status-2-2-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setup Syslog on Drupal 6.x and 7.x</title>
		<link>http://mattdanger.net/2011/02/setup-syslog-on-drupal-6-x-and-7-x/</link>
		<comments>http://mattdanger.net/2011/02/setup-syslog-on-drupal-6-x-and-7-x/#comments</comments>
		<pubDate>Thu, 24 Feb 2011 21:13:07 +0000</pubDate>
		<dc:creator>Matt Danger</dc:creator>
				<category><![CDATA[Drupal]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[multisite]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[syslog]]></category>

		<guid isPermaLink="false">http://mattdanger.net/?p=309</guid>
		<description><![CDATA[By design Drupal 6.x sites will log all activity to the database using a core feature called watchdog. Not having to require users to configure permissions for a log file on the server reduces install instructions (and possible errors) and creates a more seamless experience for Drupal users and administrators. Unfortunately, this makes monitoring a&#8230;]]></description>
			<content:encoded><![CDATA[<p>By design Drupal 6.x sites will log all activity to the database using a core feature called watchdog. Not having to require users to configure permissions for a log file on the server reduces install instructions (and possible errors) and creates a more seamless experience for Drupal users and administrators. Unfortunately, this makes monitoring a large multisite installs more laborious.</p>
<p>Enter Syslog.</p>
<p>Syslog is a local and network logging service that has been around since the 1980s. Most *nix systems come preloaded with Syslog and fortunately for us Drupal has a Syslog module included with the 6.x and 7.x cores. Here&#8217;s how to set it up:</p>
<p><strong>1) Install &amp; configure the Syslog module</strong></p>
<p>Go to your module install page, <code>/admin/build/modules</code> and install the Syslog module. Then go to the Syslog settings page, <code>/admin/settings/logging/syslog</code>, and select which Syslog level to attach to the log messages. Choose one that is not in use by Syslog</p>
<p><strong>2) Configure Syslog</strong></p>
<p>Edit <code>/etc/syslog.conf</code> and add:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">local0.<span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>drupal.log</pre></div></div>

<p>Then, restart Syslog</p>
<p><strong>3) Disable Watchdog database logging</strong></p>
<p>This will require us to edit the Drupal core (oh noes)<br />
Edit drupal/modules/dblog/dblog.module and comment out the contents of dblog_watchdog() (Around line 132)</p>
<p>Original:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> dblog_watchdog<span style="color: #009900;">&#40;</span><span style="color: #000088;">$log</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$current_db</span> <span style="color: #339933;">=</span> db_set_active<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  db_query<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;INSERT INTO {watchdog}
    (uid, type, message, variables, severity, link, location, referer, hostname, timestamp)
    VALUES
    (<span style="color: #009933; font-weight: bold;">%d</span>, '<span style="color: #009933; font-weight: bold;">%s</span>', '<span style="color: #009933; font-weight: bold;">%s</span>', '<span style="color: #009933; font-weight: bold;">%s</span>', <span style="color: #009933; font-weight: bold;">%d</span>, '<span style="color: #009933; font-weight: bold;">%s</span>', '<span style="color: #009933; font-weight: bold;">%s</span>', '<span style="color: #009933; font-weight: bold;">%s</span>', '<span style="color: #009933; font-weight: bold;">%s</span>', <span style="color: #009933; font-weight: bold;">%d</span>)&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #000088;">$log</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'user'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">uid</span><span style="color: #339933;">,</span>
    <span style="color: #000088;">$log</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'type'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    <span style="color: #000088;">$log</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'message'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    <span style="color: #990000;">serialize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$log</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'variables'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #000088;">$log</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'severity'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    <span style="color: #000088;">$log</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'link'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    <span style="color: #000088;">$log</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'request_uri'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    <span style="color: #000088;">$log</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'referer'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    <span style="color: #000088;">$log</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ip'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    <span style="color: #000088;">$log</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'timestamp'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$current_db</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    db_set_active<span style="color: #009900;">&#40;</span><span style="color: #000088;">$current_db</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Change to:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> dblog_watchdog<span style="color: #009900;">&#40;</span><span style="color: #000088;">$log</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">/*
  $current_db = db_set_active();
  db_query(&quot;INSERT INTO {watchdog}
    (uid, type, message, variables, severity, link, location, referer, hostname, timestamp)
    VALUES
    (%d, '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', %d)&quot;,
    $log['user']-&gt;uid,
    $log['type'],
    $log['message'],
    serialize($log['variables']),
    $log['severity'],
    $log['link'],
    $log['request_uri'],
    $log['referer'],
    $log['ip'],
    $log['timestamp']);
&nbsp;
  if ($current_db) {
    db_set_active($current_db);
  }
*/</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>And you&#8217;re done.</p>
]]></content:encoded>
			<wfw:commentRss>http://mattdanger.net/2011/02/setup-syslog-on-drupal-6-x-and-7-x/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Facebook-Status-2.1 released</title>
		<link>http://mattdanger.net/2010/05/facebook-status-2-1-released/</link>
		<comments>http://mattdanger.net/2010/05/facebook-status-2-1-released/#comments</comments>
		<pubDate>Thu, 06 May 2010 20:37:51 +0000</pubDate>
		<dc:creator>Matt Danger</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mattdanger.net/?p=282</guid>
		<description><![CDATA[I have updated my original Facebook status script to version 2.1. Grab it from here. The major change for this version is a switch to Facebook&#8217;s mobile pages for easier parsing. You can include this script into all sorts of wacky things. Usage example: perl facebook-status-2.1.pl Facebook login name: some.user@example.com Password: ****** Your status (Facebook&#8230;]]></description>
			<content:encoded><![CDATA[<p>I have updated my original Facebook status script to version 2.1. Grab it from <a href="http://mattdanger.net/2008/11/update-your-facebook-status-from-the-command-line/">here</a>.</p>
<p>The major change for this version is a switch to Facebook&#8217;s mobile pages for easier parsing. You can include this script into all sorts of wacky things. </p>
<p>Usage example:<br />
<code>perl facebook-status-2.1.pl</p>
<p>Facebook login name: some.user@example.com<br />
Password: ******<br />
Your status (Facebook appears to have a 232 character limit): I'm setting my status removely!!</p>
<p>Sending... Done!</code></p>
]]></content:encoded>
			<wfw:commentRss>http://mattdanger.net/2010/05/facebook-status-2-1-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New RocDubs Forum Theme</title>
		<link>http://mattdanger.net/2010/03/new-rocdubs-forum-theme/</link>
		<comments>http://mattdanger.net/2010/03/new-rocdubs-forum-theme/#comments</comments>
		<pubDate>Thu, 18 Mar 2010 16:15:25 +0000</pubDate>
		<dc:creator>Matt Danger</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mattdanger.net/?p=273</guid>
		<description><![CDATA[Every once in while I like to flex my design muscles. When I moved to Rochester last November I joined up with the local european car group RocDubs. These kids have been a lot of fun to hang out with. Like most car groups we have a forum (vBulletin) and we needed a personalized flavor&#8230;]]></description>
			<content:encoded><![CDATA[<p>Every once in while I like to flex my design muscles. When I moved to Rochester last November I joined up with the local european car group RocDubs. These kids have been a lot of fun to hang out with. Like most car groups we have a forum (vBulletin) and we needed a personalized flavor so I took on the task of making a theme. Today I launched it.</p>
<p><a href="http://rocdubs.com"><img src="http://img299.imageshack.us/img299/1334/picture1copy.png" alt="" border="0"/></a></p>
]]></content:encoded>
			<wfw:commentRss>http://mattdanger.net/2010/03/new-rocdubs-forum-theme/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making database changes to Drupal multi-sites</title>
		<link>http://mattdanger.net/2009/12/making-database-changes-to-drupal-multi-sites/</link>
		<comments>http://mattdanger.net/2009/12/making-database-changes-to-drupal-multi-sites/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 03:29:22 +0000</pubDate>
		<dc:creator>Matt Danger</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Drupal]]></category>
		<category><![CDATA[multi-site]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[terminal]]></category>

		<guid isPermaLink="false">http://mattdanger.net/?p=258</guid>
		<description><![CDATA[The company I work for hosts over 150 Drupal sites in a multi-site configuration and every so often I need to publish a change to the code that requires a database change. The large number of sites we host means that performing manual changes would require too much time and carries a chance of error.&#8230;]]></description>
			<content:encoded><![CDATA[<p>The company I work for hosts over 150 Drupal sites in a multi-site configuration and every so often I need to publish a change to the code that requires a database change. The large number of sites we host means that performing manual changes would require too much time and carries a chance of error. I&#8217;ve come up with a simple solution.</p>
<p>I first create a PHP script that bootstraps Drupal. Here is an example of a script that will rebuild the menu router tables.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Bootstrap</span>
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'includes/bootstrap.inc'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'includes/common.inc'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
drupal_bootstrap<span style="color: #009900;">&#40;</span>DRUPAL_BOOTSTRAP_FULL<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Rebuild menus</span>
menu_rebuild<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">print</span> <span style="color: #0000ff;">'Menu rebuild complete\n'</span><span style="color: #339933;">;</span></pre></div></div>

<p>I name this script <code>rebuild_menus.php</code> and upload it to my Drupal directory. Then, I create a text file on my desktop that contains a list of all the Drupal websites. This is an abbreviated example:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//example1.com</span>
http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//example2.com</span>
http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//example3.com</span>
http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//example4.com</span></pre></div></div>

<p>Finally, I execute the script on all the sites by running the following command:</p>
<p><code>for url in `cat list.txt`; do echo "Running script on $url"; curl $url/rebuild_menus.php; echo; done</code></p>
]]></content:encoded>
			<wfw:commentRss>http://mattdanger.net/2009/12/making-database-changes-to-drupal-multi-sites/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Control Adium from the Terminal</title>
		<link>http://mattdanger.net/2009/05/control-adium-from-the-terminal/</link>
		<comments>http://mattdanger.net/2009/05/control-adium-from-the-terminal/#comments</comments>
		<pubDate>Thu, 28 May 2009 00:19:37 +0000</pubDate>
		<dc:creator>Matt Danger</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mattdanger.net/?p=241</guid>
		<description><![CDATA[I heart Adium with its beautiful interface, extensive plugins, and scriptability. I use the app so much that I often forget to sign out when I leave home or work. This creates OTR private key conflicts when someone messages me. AIM (and maybe the other networks) will alert you if you&#8217;re signed on from multiple&#8230;]]></description>
			<content:encoded><![CDATA[<p>I heart <a href="http://adiumx.com">Adium</a> with its beautiful interface, extensive plugins, and scriptability. I use the app so much that I often forget to sign out when I leave home or work. This creates <a href="http://en.wikipedia.org/wiki/Off-the-Record_Messaging">OTR</a> private key conflicts when someone messages me. AIM (and maybe the other networks) will alert you if you&#8217;re signed on from multiple locations and will even let you kill the other sessions. I want to be able to remotely sign on and off from Adium and also want the ability to remotely change my account status message.</p>
<p>Fortunately, Adium has good <a href="http://trac.adium.im/wiki/AppleScript_Support_1.2">Applescript support</a> that can be extended via a shell script. I wrote this bash script that does exactly that. It is command line driven so I can SSH into my home or work computer and execute it.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Copyright Matt West  5/23/2009</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Usage</span>
<span style="color: #666666; font-style: italic;">#</span>
usage<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Usage $0  [command]
&nbsp;
Options
    -a account
        Account screen name
    -l
        Display the current account status and away message
    -m message
        Set account as away with a message
    -t type
        Status type: available, away, invisible, offline
&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Grab our environment</span>
<span style="color: #666666; font-style: italic;">#</span>
. <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>profile
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Define</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #007800;">APP</span>=<span style="color: #ff0000;">&quot;Adium&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Get opts</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">getopts</span> <span style="color: #ff0000;">&quot;a:lm:t:&quot;</span> OPTIONS; <span style="color: #000000; font-weight: bold;">do</span>
  <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #007800;">$OPTIONS</span> <span style="color: #000000; font-weight: bold;">in</span>
    a<span style="color: #7a0874; font-weight: bold;">&#41;</span>  <span style="color: #007800;">ACCOUNT</span>=<span style="color: #007800;">$OPTARG</span>
        <span style="color: #007800;">ID</span>=<span style="color: #000000; font-weight: bold;">`</span>osascript <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'tell application &quot;'</span><span style="color: #007800;">$APP</span><span style="color: #ff0000;">'&quot; to get id of accounts whose name is &quot;'</span><span style="color: #007800;">$ACCOUNT</span><span style="color: #ff0000;">'&quot;'</span><span style="color: #000000; font-weight: bold;">`</span>
        <span style="color: #000000; font-weight: bold;">;;</span>
&nbsp;
    l<span style="color: #7a0874; font-weight: bold;">&#41;</span>  <span style="color: #666666; font-style: italic;"># Display the current account status</span>
        <span style="color: #007800;">STATUS</span>=<span style="color: #000000; font-weight: bold;">`</span>osascript <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'tell application &quot;'</span><span style="color: #007800;">$APP</span><span style="color: #ff0000;">'&quot; to get status type of account '</span><span style="color: #007800;">$ID</span><span style="color: #000000; font-weight: bold;">`</span>
        <span style="color: #007800;">MESSAGE</span>=<span style="color: #000000; font-weight: bold;">`</span>osascript <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'tell application &quot;'</span><span style="color: #007800;">$APP</span><span style="color: #ff0000;">'&quot; to get status message of account '</span><span style="color: #007800;">$ID</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$STATUS</span> == <span style="color: #ff0000;">'away'</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
            <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$ACCOUNT</span> is currently away with the message <span style="color: #000000; font-weight: bold;">\&quot;</span><span style="color: #007800;">$MESSAGE</span><span style="color: #000000; font-weight: bold;">\&quot;</span> <span style="color: #666666; font-style: italic;">#&quot;</span>
        <span style="color: #000000; font-weight: bold;">else</span>
            <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$ACCOUNT</span> is currently <span style="color: #007800;">$STATUS</span>
        <span style="color: #000000; font-weight: bold;">fi</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span>
        <span style="color: #000000; font-weight: bold;">;;</span>
&nbsp;
    m<span style="color: #7a0874; font-weight: bold;">&#41;</span>  <span style="color: #007800;">MESSAGE</span>=<span style="color: #007800;">$OPTARG</span><span style="color: #000000; font-weight: bold;">;;</span>
&nbsp;
    t<span style="color: #7a0874; font-weight: bold;">&#41;</span>  <span style="color: #007800;">STATUS</span>=<span style="color: #007800;">$OPTARG</span><span style="color: #000000; font-weight: bold;">;;</span>
  <span style="color: #000000; font-weight: bold;">esac</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># An account is required</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #007800;">$ACCOUNT</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    usage
<span style="color: #000000; font-weight: bold;">else</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #007800;">$ID</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Error: Couldn't find the account <span style="color: #007800;">$ACCOUNT</span>&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Set the status type</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-n</span> <span style="color: #007800;">$STATUS</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    osascript <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'tell application &quot;'</span><span style="color: #007800;">$APP</span><span style="color: #ff0000;">'&quot; to set status type of account '</span><span style="color: #007800;">$ID</span><span style="color: #ff0000;">' to '</span><span style="color: #007800;">$STATUS</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Update the away message</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-n</span> <span style="color: #007800;">$MESSAGE</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    osascript <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'tell application &quot;'</span><span style="color: #007800;">$APP</span><span style="color: #ff0000;">'&quot; to set status type of account '</span><span style="color: #007800;">$ID</span><span style="color: #ff0000;">' to away'</span>
    osascript <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'tell application &quot;'</span><span style="color: #007800;">$APP</span><span style="color: #ff0000;">'&quot; to set status message of account '</span><span style="color: #007800;">$ID</span><span style="color: #ff0000;">' to &quot;'</span><span style="color: #ff0000;">&quot;<span style="color: #007800;">$MESSAGE</span>&quot;</span><span style="color: #ff0000;">'&quot;'</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>

<p>To use, copy and paste this code into an empty text file and name it <code>adiumcontrol</code> (or whatever you&#8217;d like). Then make the file executable:</p>
<p><code>chmod +x adiumcontrol</code></p>
<p>Then try it out. You control each IM account independently. In this example &#8216;habitcky&#8217; is my AIM screen name:</p>
<p><code>./adiumcontrol -a habitcky -l<br />
habitcky is currently available</code></p>
<p>Set your away message:</p>
<p><code>./adiumcontrol -a habitcky -m "I am currently unavailable"</code></p>
<p>Sign yourself offline:</p>
<p><code>./adiumcontrol -a habitcky -t offline</code></p>
<p>Sign yourself back online:</p>
<p><code>./adiumcontrol -a habitcky -t available</code></p>
]]></content:encoded>
			<wfw:commentRss>http://mattdanger.net/2009/05/control-adium-from-the-terminal/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tips For Your Summer of Code Application</title>
		<link>http://mattdanger.net/2009/03/tips-for-your-summer-of-code-application/</link>
		<comments>http://mattdanger.net/2009/03/tips-for-your-summer-of-code-application/#comments</comments>
		<pubDate>Thu, 26 Mar 2009 13:18:13 +0000</pubDate>
		<dc:creator>Matt Danger</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mattdanger.net/?p=235</guid>
		<description><![CDATA[Google began accepting applications for the Summer of Code yesterday and we&#8217;ve been busy on the Geeklog IRC channel answering student questions and reading proposals. Here are some things to remember when writing a proposal for the Summer of Code: Understand the organization you&#8217;re applying to work with Before you spend any time writing a&#8230;]]></description>
			<content:encoded><![CDATA[<p>Google began accepting applications for the <a href="http://socghop.appspot.com/">Summer of Code</a> yesterday and we&#8217;ve been busy on the <a href="http://geeklog.net">Geeklog</a> <a href="#geeklog @ irc.freenode.net">IRC channel</a> answering student questions and reading proposals. </p>
<p>Here are some things to remember when writing a proposal for the Summer of Code:</p>
<p><strong>Understand the organization you&#8217;re applying to work with</strong><br />
Before you spend any time writing a proposal you need to understand the organization, software, and problem you&#8217;re working on. Download the latest version of the code and read through some of it. Install and use it. Look at the documentation. See what the software can and can&#8217;t do and how it applies to your project.</p>
<p><strong>Write a good proposal!</strong><br />
After you&#8217;ve looked through the code and feel you have a good understanding of the problem then you can sit down and start writing. Your proposal should include all the points of the problem, why they&#8217;re a problem, how you&#8217;re going to address the problem, and how your solution to the problem will benefit the organization.</p>
<p><strong>Only write a few proposals</strong><br />
A good proposal takes a long time to write. You need to fully understand the problem and the organization before writing a good proposal. You may think that writing a bunch of proposals for many different organizations will increase your odds of being selected, but instead you&#8217;re just decreasing the quality of your proposals and reducing your chances of being selected.</p>
<p><strong>Ask questions</strong><br />
Mentors are hanging out on IRC all day waiting for you to ask them questions. We&#8217;re excited to do it because we get to see the interest in our organization. We&#8217;d also be glad to look over your proposal and provide feedback before you submit it to the SoC.</p>
<p>To give students an example of what a proposal should look like I&#8217;m going to post my proposal from last year. Unfortunately, I can&#8217;t find the one from 2007 that I think is a little better.</p>
<blockquote><p>
Abstract</p>
<p>The Geeklog installation wizard makes setting up a new, or upgrading an<br />
existing, Geeklog site a quick and painless process. However, there are<br />
two situations where a website administrator must still perform tasks<br />
manually: managing plugins and migrating from a backup. My proposal is<br />
to add a plugin management utility that will be rolled into the<br />
installation process and will allow direct control of plugins as well as<br />
a migration utility that will give the user the ability to restore<br />
Geeklog from a backup seamlessly.</p>
<p>PROJECT DETAILS &#8211; PLUGIN FEATURE</p>
<p>The plugin installation process will be made steamless for the user. An<br />
&#8220;Advanced Installation Options&#8221; link will appear underneath what is<br />
currently the install configuration options form on page 2 of the<br />
installation and when clicked will take the user to a separate page to<br />
manage plugins (and migration, which will be discussed in the next<br />
section). The list of plugins will be populated by listing the contents<br />
of Geeklog&#8217;s plugins directory. A file upload form will give the user a<br />
simpler method of uploading the plugin, which will require the plugins<br />
directory be write-able by the web server. By default all of the plugins<br />
inside the plugins directory will be installed, unless the user chooses<br />
to not install them. The plugins that are selected for install will be<br />
sent with the rest of the form data from step 2 to step 3 of the<br />
installation wizzard where each plugin&#8217;s installation script is executed.</p>
<p>The plugin installation during the upgrade process will be similar to<br />
the new installation process described in the previous paragraph. If a<br />
newer version of an installed plugin exists the plugin will be<br />
automatically upgraded. The user will still be given the ability to<br />
install new plugins during the upgrade in the same way as a fresh install.</p>
<p>In addition to the installation wizard, the plugin management panel<br />
inside the administration area will be modified to add the ability to<br />
upload a plugin which will make adding new plugins quicker.</p>
<p>For users who wish to create a custom Geeklog distribution with their<br />
own favorite plugins a simple stand alone utility will be developed.<br />
This will consist of a single PHP shell script that downloads and<br />
decompresses the Geeklog tarball and lists the contents in the plugins<br />
directory. The user will be have the ability to deselect and remove any<br />
of the listed plugins and also given the ability to add additional<br />
plugins by either copying a plugin tarball, or directory, from another<br />
directory on the local machine or specifying a URL to the plugin tarball<br />
on a remote server. After the user makes selects the plugins they want<br />
the entire geeklog directory will be recompressed with the new plugins.<br />
All the plugins in the plugins directory will be installed by default,<br />
unless unselected by the user, during install.</p>
<p>PROJECT DETAILS &#8211; MIGRATION ASSISTANT FEATURE</p>
<p>Geeklog currently has a backup feature which creates a SQL table scheme<br />
and data file. This file will be used as a restore point for the<br />
migration feature.</p>
<p>The option to migrate from backup will be added to the &#8220;Advanced<br />
installation options&#8221; area proposed above for plugin installation. In<br />
this area a checkbox to &#8220;Import from backup&#8221; will appear with the option<br />
to select an existing backup from the backups/ directory or to upload a<br />
backup file. A message will be displayed to users to warn them about<br />
possible timeout issues when uploading large files and that they may<br />
want to upload their file via FTP to the backups directory instead.</p>
<p>Once a backup file is selected the migration process will import the<br />
database table schema and data from the backed up SQL file. Some<br />
additional analysis will need to be taken during this step so that large<br />
database imports do not exceed the web server&#8217;s maximum script runtime.<br />
A possible solution would be to perform a staggered import, where the<br />
import process is broken into smaller pieces. Dirk has suggested a<br />
utility called BigDump which does this for MySQL. We might be able to<br />
simply implement that utility with a modification to allow it to also<br />
work with MS SQL.</p>
<p>After the database has been imported the script will query the<br />
&#8216;conf_values&#8217; table to ensure the stored paths match the new system<br />
paths. If they do not they will be updated based on the data from the<br />
installation form or the user will be prompted to define the path. This<br />
is similar to a fresh installation where all paths must be set. The last<br />
step will be any remaining checks to ensure all necessary database<br />
information exists, that required plugins exist (if they don&#8217;t they will<br />
be disabled in the database until the user installs them) and the<br />
correct system files are in place.</p>
<p>Finally, the Geeklog upgrade documentation makes a strong recommendation<br />
that the user backup their database before attempting to upgrade, so why<br />
don&#8217;t we offer to do this for them? An option will be added during the<br />
upgrade process to ask the user if they&#8217;d like us to backup their<br />
existing installation. This will not be selected by default because of<br />
the time it would add to an upgrade. If selected a backup of the<br />
database will be saved to the backups directory before updates are performed.</p>
<p>BENEFITS</p>
<p>- Plugin installation steps will be reduced and will require no command<br />
line access of file editing resulting in fewer sources of user error.<br />
- Migration feature would give users the ability to easily and reliabily<br />
restore from backups without remote shell access.<br />
- Automatic backup option before performing an upgrade will create a<br />
quick and simple restore option for users that experience a problem in<br />
the upgrade process.</p>
<p>TIMELINE</p>
<p>Week 1: Checkout latest GL package and start evaluating the code base<br />
Week 2: Final plugin installation and migration assistant format design<br />
Week 3-4: Code furiously, develop unhealthy caffeine and energy drink<br />
dependence<br />
Week 5: Rough working plugin installation feature<br />
Week 7: Rough working migration assistant feature<br />
Week 8: Midterm, submit code for evaluation<br />
Week 9: Make revisions based on any mentor suggestions<br />
Week 11: Major work complete on plugin installation feature, submit to CVS<br />
Week 12: Major work complete on migration assistant feature, submit to CVS<br />
Week 13: Begin to complete documentation and testing<br />
Week 14: Iron out final bugs<br />
Week 15: Submit all deliverables for evaluation</p>
<p>DELIVERABLES</p>
<p>- Plugin installation/management added into installation script<br />
- Plugin installation/management added to administration panel<br />
- Stand alone command line utility to create custom Geeklog distributions<br />
- Migration feature added into installation script<br />
- Additional English localization entries<br />
- Additional install documentation</p>
<p>ABOUT ME</p>
<p>I am a 23 year old graduate student at D&#8217;Youville College in Buffalo,<br />
NY, USA. I enjoy programming for the web but more importantly I love<br />
creating a rich experience for those who use my software. I have<br />
previously worked with Geeklog in the 2007 Summer of Code program and<br />
the experience was invaluable. I had an incredible time and hope to be a<br />
participant again this year! I believe I am the best applicant for this<br />
project because I wrote and am deeply familiar the current installation<br />
wizard script.
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://mattdanger.net/2009/03/tips-for-your-summer-of-code-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My Growing Duck Army</title>
		<link>http://mattdanger.net/2009/03/my-growing-duck-army/</link>
		<comments>http://mattdanger.net/2009/03/my-growing-duck-army/#comments</comments>
		<pubDate>Thu, 12 Mar 2009 15:04:58 +0000</pubDate>
		<dc:creator>Matt Danger</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Duckies]]></category>

		<guid isPermaLink="false">http://mattdanger.net/?p=214</guid>
		<description><![CDATA[It&#8217;s getting a little out of control..]]></description>
			<content:encoded><![CDATA[<p><img src='http://farm4.static.flickr.com/3024/3348582281_f8605f0ee5.jpg?v=0' border='0'/></p>
<p>It&#8217;s getting a little out of control..</p>
<p><img src='http://farm4.static.flickr.com/3613/3349417572_26f0fa36da.jpg?v=0' border='0'/></p>
]]></content:encoded>
			<wfw:commentRss>http://mattdanger.net/2009/03/my-growing-duck-army/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>
	</channel>
</rss>

