<?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>Rob Allen&#039;s DevNotes &#187; Computing</title>
	<atom:link href="http://akrabat.com/category/computing/feed/" rel="self" type="application/rss+xml" />
	<link>http://akrabat.com</link>
	<description>Developing PHP software in the Real World, by Rob Allen</description>
	<lastBuildDate>Fri, 11 May 2012 12:52:54 +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>Automatic Apache vhosts</title>
		<link>http://akrabat.com/computing/automatic-apache-vhosts/</link>
		<comments>http://akrabat.com/computing/automatic-apache-vhosts/#comments</comments>
		<pubDate>Mon, 26 Mar 2012 07:24:50 +0000</pubDate>
		<dc:creator>Rob...</dc:creator>
				<category><![CDATA[Computing]]></category>

		<guid isPermaLink="false">http://akrabat.com/?p=2158</guid>
		<description><![CDATA[One thing that I've wanted to implement for a while now is automatic vhosts on my dev box. The idea is that I want to drop a folder into a directory and have it automatically turned into a vhost for me accessible at http://foldername.dev. It turns out that this isn't nearly as hard as expected [...]]]></description>
			<content:encoded><![CDATA[<p>One thing that I've wanted to implement for a while now is automatic vhosts on my dev box. The idea is that I want to drop a folder into a directory and have it automatically turned into a vhost for me accessible at <tt>http://<em>foldername</em>.dev</tt>. It turns out that this isn't nearly as hard as expected which is usually the case with things that I've been putting off!</p>
<p>This is how to do it.</p>
<h4>Apache configuration</h4>
<p>The Apache magic is in an extension called <tt><a href="http://httpd.apache.org/docs/2.2/mod/mod_vhost_alias.html">mod_vhost_alias</a></tt> which you may need to enable in your <tt>httpd.conf</tt> file. </p>
<p>You can then set up the <tt>VirtualHost</tt> wherever you keep such things. On a stock OS X, the <tt>extras/httpd-vhosts.conf</tt> file is used. </p>
<p>Add the following to the bottom:</p>
<pre>
&lt;Virtualhost *:80>
    VirtualDocumentRoot &quot;/www/dev/%1/public&quot;
    ServerName vhosts.dev
    ServerAlias *.dev
    UseCanonicalName Off
    LogFormat &quot;%V %h %l %u %t \&quot;%r\&quot; %s %b&quot; vcommon
    ErrorLog &quot;/www/dev/vhosts-error_log&quot;
    &lt;Directory &quot;/www/dev/*&quot;>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
    &lt;/Directory>
&lt;/Virtualhost>
</pre>
<p>In the <tt>VirtualHost</tt> configuration, I have used the <tt>ServerAlias</tt> and <tt>VirtualDocumentRoot</tt> directives to map <tt>http://<em>foldername</em>.dev</tt> to the directory <tt>/www/dev/<em>foldername</em>/public</tt>. Hence, any folder that I place in <tt>/www/dev</tt> will have its own virtual host. Alter these appropriately for your set-up.</p>
<p>Don't forget to restart Apache.</p>
<p>Unfortunately, the computer hasn't a clue how to handle http://foldername.dev and the obvious solution is to run a local DNS server. Another solution is to use a PAC file.</p>
<h4>DNS server configuration</h4>
<p>This is easy enough with <a href="http://www.thekelleys.org.uk/dnsmasq/doc.html">dnsmasq</a>. On OS X, use <a href="http://mxcl.github.com/homebrew/">Homebrew</a> to install like this: <tt>brew install dnsmasq</tt>. On Linux, use your package manager; on Windows, you're own your own!</p>
<p>Note that on OS X, you should set it to start up automatically using launchd as noted in the instructions after installation. You also need to copy the configuration file to <tt>/etc</tt> using: <tt>cp /usr/local/Cellar/dnsmasq/2.57/dnsmasq.conf.example /usr/local/etc/dnsmasq.conf</tt> (or whatever the latest version number is). on Linux, I would guess that your package manager provides a dnsmasq.conf file in <tt>/etc</tt> or <tt>/etc/dnsmasq</tt>.</p>
<p>Next, edit <tt>dnsmasq.conf</tt> file and added the following lines to the bottom:</p>
<pre>
listen-address=127.0.0.1
address=/.dev/127.0.0.1
</pre>
<h4>Add the name server to your network configuration</h4>
<p>On OS X, Go to <em>System Preferences</em> -> <em>Network</em> -> <em>{Wifi or Ethernet}</em> -> <em>Advanced…</em> -> <em>DNS</em> and click on + button at the bottom of the left hand panel and add <strong>127.0.0.1</strong> to the list of DNS servers. Drag 127.0.0.1 at the top of the list.</p>
<p>On Linux, you should use the appropriate GUI tools for your distribution or potentially edit <tt>etc/dhcp/dhclient.conf</tt> and uncomment the <tt>domain-name-servers 127.0.0.1;</tt> on line 20 (on Ubuntu).</p>
<p>Restart dnsmasq and you should now be able to execute <tt>host test.dev</tt> on the command line and see <tt>127.0.0.1</tt> as the resultant address.</p>
<h4>Alternative to DNS server: PAC file</h4>
<p>Since publishing this article, <a href="http://twitter.com/inxilpro">Chris Morell</a> pointed out that you can also use PAC files rather than install a DNS server. Details are on his <a href="http://cmorrell.com/webdev/automatic-virtual-hosts-w-proxy-auto-config-768">blog post</a>.</p>
<h4>Check it works</h4>
<p>Create a directory called <tt>test</tt> in your <tt>dev</tt> directory. Within <tt>test</tt>, create <tt>public/index.php</tt> and within <tt>index.php</tt> add some code to prove it works. e.g. <tt>< ;?php echo "Hello World"; ?>;</tt></p>
<p>If you navigate to http://test.dev, you should see "Hello World" displayed.</p>
<h4>Caveats</h4>
<p>A couple of caveats:</p>
<ul>
<li><tt>DOCUMENT_ROOT</tt> is not /www/dev/test as you'd expect. Instead it is the global document root. See <a href="https://gist.github.com/2208990">this gist</a> for a neat way to solve this using a prepend file.</li>
<li>If you use mod_rewrite, then you'll need a <tt>RewriteBase /</tt> in your <tt>.htaccess</tt> file. Alternatively, you can change the <tt>Directory</tt> section of your vhost to do the rewriting for you if all your projects are alike. Something like this should work:
<pre>
    &lt;Directory &quot;/www/dev/*&quot;>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        Allow from all

        RewriteEngine On
        RewriteBase /
        RewriteCond %{REQUEST_FILENAME} -s [OR]
        RewriteCond %{REQUEST_FILENAME} -l [OR]
        RewriteCond %{REQUEST_FILENAME} -d
        RewriteRule ^.*$ - [NC,L]
        RewriteRule ^.*$ index.php [NC,L]
    &lt;/Directory>
</pre>
</li>
</ul>
<h4>All done</h4>
<p>That's it. You can now create as many projects as you like without having to worry about setting up new virtual hosts or modifying you hosts file!</p>
 <p><a href="http://akrabat.com/?flattrss_redirect&amp;id=2158&amp;md5=07bcda0d15dbd1eac3d0f82a381ad628" title="Flattr" target="_blank"><img src="http://akrabat.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://akrabat.com/computing/automatic-apache-vhosts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="https://flattr.com/submit/auto?user_id=akrabat&amp;popout=1&amp;url=http%3A%2F%2Fakrabat.com%2Fcomputing%2Fautomatic-apache-vhosts%2F&amp;language=en_GB&amp;category=text&amp;title=Automatic+Apache+vhosts&amp;description=One+thing+that+I%27ve+wanted+to+implement+for+a+while+now+is+automatic+vhosts+on+my+dev+box.+The+idea+is+that+I+want+to+drop+a+folder+into+a...&amp;tags=blog" type="text/html" />
	</item>
		<item>
		<title>OS X Tips and Tricks</title>
		<link>http://akrabat.com/computing/os-x-tips-and-tricks/</link>
		<comments>http://akrabat.com/computing/os-x-tips-and-tricks/#comments</comments>
		<pubDate>Tue, 20 Mar 2012 09:50:30 +0000</pubDate>
		<dc:creator>Rob...</dc:creator>
				<category><![CDATA[Computing]]></category>

		<guid isPermaLink="false">http://akrabat.com/?p=2148</guid>
		<description><![CDATA[It's been around 18 months since I wrote up some notes about OS X, so clearly it's time for an updated article. This article is intended to give a quick and easy introduction to some key things that I think you should know when you move to using OS X. Basics There's one menu bar [...]]]></description>
			<content:encoded><![CDATA[<p>It's been around 18 months since I wrote up some notes about OS X, so clearly it's time for an updated article.</p>
<p>This article is intended to give a quick and easy introduction to some key things that I think you should know when you move to using OS X.</p>
<p><strong>Basics</strong></p>
<ul>
<li>There's one menu bar for all application</li>
<li>Closing the last window doesn't exit the application. Use cmd+q or the Quit menu item on the "application name" menu.</li>
<li>System Preferences is available via the Apple (&#xF8FF;) menu.</li>
<li>Finder is the name of the file manager.</li>
<li>Preview is the name of the PDF and image viewer. It's more powerful than it looks.</li>
<li>Turn on View->Show Path Bar in Finder.</li>
<li>Browsing <a href="http://www.apple.com/support/mac101/tour/">Mac 101</a> if you're new to Mac can be helpful.</li>
</ul>
<p><strong>Launchpad</strong><br />
You applications are stored in /Applications. The easiest way to get to them is via Launchpad. If you've used an iPhone then it will look familiar!</p>
<p><strong>App Store</strong><br />
Get your software from the App Store if you can. It's easier than dealing with license keys and will integrate with Mountain Lion's notification centre.</p>
<p><strong>Backup</strong><br />
Get a cheap USB external hard drive and use Time Machine. There are no excuses.</p>
<p><strong>Zoom</strong><br />
The green button at the top left of a window is called Zoom, not Maximise for a reason! It doesn't do the same thing. OS X has "full screen mode" which is accessed by pressing the set diagonal arrows in the top right of a window.</p>
<p><strong>Force quit</strong><br />
It's rare for an app to hang, but it does happen. If you need to force an application to quit, hold down ctrl and the alt key and then click on the app's icon in the Dock. select "Force quit" from the context menu.</p>
<p><strong>FileVault</strong><br />
If your Mac is less than 2 years old, enable FileVault within <em>System Preferences</em> -> <em>Security &amp; Privacy</em> -> <em>FileVault</em>. Also, set your computer up so that a password is required to login on start up and from sleep. It's worth it for the peace of mind if your laptop ever gets stolen.</p>
<p><strong>British English dictionary</strong><br />
<em>System Preferences</em> -> <em>Language &amp; Text</em> -> <em>Language</em>. Click "Edit List…" and find "British English" in the list and select it and press OK. Drag to top of list if not already there.</p>
<p><strong>The &pound; symbol on a UK keyboard</strong><br />
alt+3 gives you a &pound;! Just remember that Americans called the # symbol "pound"… </p>
<p><strong>The file system: HFS+</strong><br />
HFS+ is OS X's filesystem and is case preserving, and <strong>is not case sensitive</strong>. Be aware of this at all times, or create a separate "HFS+ (case-sensitive)" partition using Disk Utility. Note that your main partition should be standard HFS+.</p>
<p><strong>Keyboard access</strong><br />
<em>System Preferences</em> -> <em>Keyboard</em> -> <em>Keyboard shortcuts</em>. At the bottom, select "All controls". You can now use tab to move between buttons in a dialog box and press the space bar to select a tabbed-to button (blue focus outline).</p>
<p><strong>Keyboard shortcuts</strong></p>
<ul>
<li>The cmd (command) key has the symbol &#8984; is used where Windows/Linux use the control key.</li>
<li>Option is another word for the alt key and has the &#8997; symbol</li>
<li>On the UK keyboard layout, the hash (#) character is found via option+3.</li>
<li>Cmd+tab switches applications; Cmd+` (backtick) switches windows within an application.</li>
<li>Cmd+space opens system wide search (called Spotlight)</li>
<li>Shift+Cmd+[ and Shift+Cmd+] usually switch tabs within a window.</li>
<li>Cmd+t will open a new tab in apps that have tabs.</li>
<li>Moving the caret:
<ul>
<li>left/right: move caret one character</li>
<li>alt+left/alt+right: move caret one word</li>
<li>cmd+left/cmd+right: move caret to start/end of the line</li>
<li>cmd+up/cmd+down: move caret to start/end of the document</li>
<li>The &#x2196; and &#x2198; arrows move the screen to the top and bottom of the document, but do not move the caret!</li>
</ul>
</li>
<li>Cmd+g is find next</li>
<li>Cmd+r to refresh a web page as F5 doesn't work in Safari</li>
<li>Finder shortcuts:
<ul>
<li>The return key renames a file, not opens it!</li>
<li>cmd+down to open the selected file</li>
<li>cmd+up to go up a directory</li>
<li>shift+cmd+g to go to any specific directory. Useful to get to /usr/local/. Also works in any open/save dialog within an application.</li>
</ul>
</li>
<li>Within a sheet:
<ul>
<li>Return key to select default option (filled in blue)</li>
<li>Escape key to cancel</li>
<li>cmd+delete to "Don't Save" in a save sheet</li>
</ul>
</li>
<li>You can create (or edit) your own keyboard shortcuts for any application's menu item using System Preferences. This is really really good!</li>
</ul>
<p><strong>iPhoto opening on connection of iPhone</strong></p>
<p>If you need to stop iPhoto opening every time you connect a camera or a phone, open <em>Image Capture</em> and select the camera in the list and then look at the panel in the bottom left.</p>
<p><strong>Screenshots</strong></p>
<li>Shift+cmd+3 for the whole screen.</li>
<li>Shift+cmd+4 and draw a rectangle with the mouse for an arbitrary area of the screen</li>
<li>Shift+cmd+4 then space then click on the window to get an PNG of that window.</li>
<li>Consider <a href="http://tinygrab.com/">TinyGrab</a> or <a href="http://skitch.com/">Skitch</a> if you want to share them</li>
<p><strong>Terminal</strong></p>
<p>This is the command line application for OS X. Underneath, you have BSD, so it's works properly! Most common cli apps that you expect to be here are, such as, <tt>ls</tt>, <tt>du</tt>, <tt>df</tt>, <tt>curl</tt>, <tt>svn</tt>, etc. For anything else, use <a href="http://mxcl.github.com/homebrew/">Homebrew</a>.
</p>
<ul>
<li>"<tt>open .</tt>" will open a finder window in the current directory</li>
<li><a href="http://www.entropy.ch/software/applescript/">Open Terminal Here</a> is a useful script for Finder. Store in ~/bin and drag it onto your Finder toolbar.</li>
<li>My article on <a href="http://akrabat.com/php/osx-terminal-colours/">changing the Terminal's colours</a> is useful.</li>
<li>Cmd+t for tabs in a Terminal window.</li>
<li>Cmd+k to clear the buffer.</li>
</ul>
<p><strong>GCC / development</strong><br />
Install the <a href="https://developer.apple.com/downloads/index.action">Apple Command Line Tools for Xcode</a>. An Apple Id is required, but you don't have to pay for them. If you want to develop Cocoa applications, then get <a href="http://itunes.apple.com/us/app/xcode/id497799835?ls=1&#038;mt=12">Xcode from the App Store</a>.</p>
<p><strong>Unix utilities</strong><br />
Install <a href="http://mxcl.github.com/homebrew/">Homebrew</a>.</p>
<p><strong>PHP</strong><br />
Apple supply PHP 5.3.x with OS X 10.7 so you may as well use it. I wrote it up here: <a href="http://akrabat.com/phposx">http://akrabat.com/phposx</a>. </p>
<p>Alternatively:</p>
<ul>
<li>Liip have provided <a href="http://php-osx.liip.ch/">http://php-osx.liip.ch/</a> which is a one line binary PHP install for OS X.</li>
<li><a href="http://www.zend.com/en/products/server-ce/">ZendServer CE</a> is a simple install and is regularly updated</li>
<li>You could always use home brew.</li>
</ul>
<p><strong>Applications</strong></p>
<p>This is just an unsorted list of useful apps!</p>
<ul>
<li>iWork's <a href="http://itunes.apple.com/gb/app/pages/id409201541?mt=12">Pages</a>, <a href="http://itunes.apple.com/gb/app/numbers/id409203825?mt=12">Numbers</a> and <a href="http://itunes.apple.com/gb/app/keynote/id409183694?mt=12">Keynote</a> are very good. <a href="http://www.amazon.co.uk/gp/product/B003YCOJA8/ref=as_li_ss_tl?ie=UTF8&#038;tag=akrabat-21&#038;linkCode=as2&#038;camp=1634&#038;creative=19450&#038;creativeASIN=B003YCOJA8">Office for Mac</a><img src="http://www.assoc-amazon.co.uk/e/ir?t=akrabat-21&#038;l=as2&#038;o=2&#038;a=B003YCOJA8" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;"/> is also available.</li>
<li><a href="http://www.barebones.com/products/textwrangler/">TextWrangler</a> - it's a good free text editor that handles editing files owned by root really elegantly. Install the command line tools and then you can do <tt>edit /etc/php.ini</tt>.</li>
<li><a href="http://code.google.com/p/macvim/">MacVim</a>, <a href="http://www.sublimetext.com/2">Sublime Text 2</a> &amp; <a href="http://itunes.apple.com/us/app/bbedit/id404009241?mt=12">BBEdit</a> are all great text editors.</li>
<li><a href="http://adium.im/">Adium</a> for IM.</li>
<li>There's an official <a href="http://itunes.apple.com/gb/app/twitter/id409789998?mt=12">Twitter app in the App Store</a>. <a href="http://hibariapp.com/">Hibari</a> or <a href="http://iconfactory.com/software/twitterrific">Twitterrific</a> are good alteratives.</li>
<li><a href="http://cyberduck.ch/">Cyberduck</a> for FTP. Though spending the $34 for <a href="http://itunes.apple.com/us/app/transmit/id403388562?mt=12">Transmit</a> is worth the cash if you do a lot of FTP.</li>
<li><a href="http://itunes.apple.com/gb/app/reeder/id439845554?mt=12">Reeder</a> or <a href="http://netnewswireapp.com/mac/">NetNewsWire</a> for RSS.</li>
<li><a href="http://colloquy.info/">Colloquy</a> for IRC. I like <a href="http://itunes.apple.com/us/app/linkinus/id402390998?mt=12">Linkinus</a> personally.</li>
<li><a href="http://code.google.com/p/macfuse/">MacFUSE</a> to mount SSH and other 3rd parth files systems into OS X's native file handling. See also <a href="http://www.expandrive.com/mac">ExpanDrive</a> also</li>
<li><a href="http://handbrake.fr/">Handbrake</a> for converting DVDs and other video converting requirements.</li>
<li><a href="http://www.omnigroup.com/products/omnidisksweeper/">OnmiDiskSweeper</a> for a pretty version of "du".</li>
<li><a href="http://www.omnigroup.com/products/omnigraffle/">Omni Graffle</a> (worth the money!) is a very good diagramming tool.</li>
<li>If you tend to keep lots of small files with text notes in them, then look at <a href="http://notational.net/">Notational Velocity</a>. It syncs with <a href="http://itunes.apple.com/gb/app/simplenote/id289429962?mt=8">SimpleNote</a> for iOS too.</li>
<li><a href="http://www.vmware.com/products/fusion/">VMWare Fusion</a>, <a href="https://www.virtualbox.org/">VirtualBox</a> or <a href="http://www.parallels.com/products/desktop/">Parallels Desktop</a> if you need Windows/Linux VMs.</li>
<li><a href="http://www.red-sweater.com/marsedit/">MarsEdit</a> to write blog posts.</li>
<li><a href="http://flyingmeat.com/acorn/">Acorn</a> or <a href="http://itunes.apple.com/gb/app/pixelmator/id407963104?mt=12">Pixelmator</a> for image editing if you don't need or want <a href="http://www.adobe.com/products/photoshop/">Photoshop</a>.</li>
<li><a href="http://www.heliumfoot.com/mercurymover/">MercuryMover</a> for keyboard control of window positioning/sizing.</li>
<li><a href="http://itunes.apple.com/gb/app/evernote/id281796108?mt=8">Evernote</a> for general storage of notes, PDFs, etc.</li>
<li><a href="http://www.crashplan.com/">Crashplan</a> or <a href="http://www.backblaze.com/">Backblaze</a> for remote backup.</li>
<li><a href="http://itunes.apple.com/gb/app/sourcetree-git-hg/id411678673?mt=12">SourceTree</a> is a good visual Git &#038; Mercurial client</li>
<li><a href="http://www.sequelpro.com/">Seuqel Pro</a> is a good MySQL client.</li>
</ul>
<p>I hope this is helpful!</p>
 <p><a href="http://akrabat.com/?flattrss_redirect&amp;id=2148&amp;md5=ecf3b1847743bf1dbb405dfd01fe4ba2" title="Flattr" target="_blank"><img src="http://akrabat.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://akrabat.com/computing/os-x-tips-and-tricks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="https://flattr.com/submit/auto?user_id=akrabat&amp;popout=1&amp;url=http%3A%2F%2Fakrabat.com%2Fcomputing%2Fos-x-tips-and-tricks%2F&amp;language=en_GB&amp;category=text&amp;title=OS+X+Tips+and+Tricks&amp;description=It%27s+been+around+18+months+since+I+wrote+up+some+notes+about+OS+X%2C+so+clearly+it%27s+time+for+an+updated+article.+This+article+is+intended+to+give+a+quick...&amp;tags=blog" type="text/html" />
	</item>
		<item>
		<title>OS X Tips and Tricks for Snow Leopard</title>
		<link>http://akrabat.com/computing/osx-tips-and-tricks-for-snow-leopar/</link>
		<comments>http://akrabat.com/computing/osx-tips-and-tricks-for-snow-leopar/#comments</comments>
		<pubDate>Mon, 04 Oct 2010 06:53:42 +0000</pubDate>
		<dc:creator>Rob...</dc:creator>
				<category><![CDATA[Computing]]></category>

		<guid isPermaLink="false">http://akrabat.com/?p=1235</guid>
		<description><![CDATA[Following some discussions with friends who've recently started using OS X, I thought I'd note down some tips and tricks that I've learnt since I moved to Mac. This is in no particular order as it's taken from IRC logs of conversations I've had :) Basics There's one menu bar for all application Closing the [...]]]></description>
			<content:encoded><![CDATA[<p>Following some discussions with friends who've recently started using OS X, I thought I'd note down some tips and tricks that I've learnt since I moved to Mac. This is in no particular order as it's taken from IRC logs of conversations I've had :)</p>
<p><strong>Basics</strong></p>
<ul>
<li>There's one menu bar for all application</li>
<li>Closing the last window doesn't exit the application. Use cmd+q or the Quit menu item on the "application name" menu.</li>
<li>System Preferences is available via the Apple (&#xF8FF;) menu.</li>
<li>Finder is the name of the file manager.</li>
<li>Preview is the name of the PDF and image viewer. It's more powerful than it looks.</li>
<li>Turn on View->Show Path Bar in Finder.</li>
<li>Browsing <a href="http://www.apple.com/support/mac101/tour/">Mac 101</a> if you're new to Mac can be helpful.</li>
</ul>
<p><strong>Backup</strong></p>
<p>Get a cheap USB external hard drive and use Time Machine. There are no excuses.</p>
<p><strong>PHP</strong></p>
<p>Apple supply PHP 5.3.x with OS X 10.6 so you may as well use it. I wrote it up here: <a href="http://akrabat.com/phposx">http://akrabat.com/phposx</a>. Another alternative is <a href="http://www.zend.com/en/products/server-ce/">ZendServer CE</a> which is also regularly updated.
</p>
<p><strong>HFS+</strong></p>
<p>HFS+ is OS X's filesystem and is case preserving, and <strong>is not case sensitive</strong>. Be aware of this at all times, or create an "HFS+ (case-sensitive)" partition using Disk Utility.</p>
<p><strong>Keyboard shortcuts</strong></p>
<ul>
<li>The cmd (command) key has the symbol &#8984; is used where Windows/Linux use the control key.</li>
<li>Option is another word for the alt key and has the &#8997; symbol</li>
<li>On the UK keyboard layout, the hash (#) character is found via option+3.</li>
<li>Cmd+tab switches applications; Cmd+` (backtick) switches windows within an application.</li>
<li>Shift+Cmd+[ and Shift+Cmd+] usually switch tabs within a window.</li>
<li>Moving the caret:
<ul>
<li>left/right: move caret one character</li>
<li>alt+left/alt+right: move caret one word</li>
<li>cmd+left/cmd+right: move caret to start/end of the line</li>
<li>cmd+up/cmd+down: move caret to start/end of the document</li>
<li>The &#x2196; and &#x2198; arrows move the screen to the top and bottom of the document, but do not move the caret!</li>
</ul>
</li>
<li>Cmd+g is find next</li>
<li>Cmd+r to refresh a web page as F5 doesn't work in Safari</li>
<li>Finder shortcuts:
<ul>
<li>The return key renames a file, not opens it!</li>
<li>cmd+down to open the selected file</li>
<li>cmd+up to go up a directory</li>
<li>shift+cmd+g to go to any specific directory. Useful to get to /usr/local/. Also works in any open/save dialog within an application.</li>
</ul>
</li>
<li>You can create (or edit) your own keyboard shortcuts for any application's menu item using System Preferences.</li>
</ul>
<p><strong>Screenshots</strong></p>
<li>Shift+cmd+3 for the whole screen.</li>
<li>Shift+cmd+4 and draw a rectangle with the mouse for an arbitrary area of the screen</li>
<li>Shift+cmd+4 then space then click on the window to get an PNG of that window.</li>
<p><strong>Terminal</strong></p>
<p>This is the command line application for OS X. Underneath, you have BSD, so it's works properly! Most common cli apps that you expect to be here are, such as, <tt>ls</tt>, <tt>du</tt>, <tt>df</tt>, <tt>curl</tt>, <tt>svn</tt>, etc. For anything else, use <a href="http://mxcl.github.com/homebrew/">Homebrew</a>.
</p>
<ul>
<li>"<tt>open .</tt>" will open a finder window in the current directory</li>
<li><a href="http://www.entropy.ch/software/applescript/">Open Terminal Here</a> is a useful script for Finder. Store in ~/bin and drag it onto your Finder toolbar.</li>
<li>My article on <a href="http://akrabat.com/php/osx-terminal-colours/">changing the Terminal's colours</a> is useful.</li>
<li>Cmd+t for tabs in a Terminal window.</li>
<li>Cmd+k to clear the buffer.</li>
</ul>
<p><strong>Applications</strong></p>
<ul>
<li><a href="http://www.barebones.com/products/textwrangler/">TextWrangler</a> - it's a good free text editor that handles editing files owned by root really elegantly. Install the command line tools and then you can do <tt>edit /etc/php.ini</tt>.</li>
<li><a href="http://code.google.com/p/macvim/">MacVim</a>.</li>
<li><a href="http://adium.im/">Adium</a> for IM.</li>
<li><a href="http://hibariapp.com/">Hibari</a> or <a href="http://iconfactory.com/software/twitterrific">Twitterrific</a> for Twitter.</li>
<li><a href="http://cyberduck.ch/">Cyberduck</a> for FTP. Though spending the $34 for <a href="http://www.panic.com/transmit/">Transmit</a> is worth the cash if you do a lot of FTP.</li>
<li><a href="http://netnewswireapp.com/mac/">NetNewsWire</a> for RSS - integrates with Google Reader.</li>
<li><a href="http://colloquy.info/">Colloquy</a> for IRC.</li>
<li><a href="http://code.google.com/p/macfuse/">MacFUSE</a> to mount SSH and other 3rd parth files systems into OS X's native file handling. See also <a href="http://www.expandrive.com/mac">ExpanDrive</a> also</li>
<li><a href="http://handbrake.fr/">Handbrake</a> for converting DVDs and other video converting requirements.</li>
<li><a href="http://www.omnigroup.com/products/omnidisksweeper/">OnmiDiskSweeper</a> for a pretty version of "du".</li>
<li><a href="http://www.omnigroup.com/products/omnigraffle/">Omni Graffle</a> (not cheap!) is a very good diagramming tool.</li>
<li>If you tend to keep lots of small files with text notes in them, then look at <a href="http://notational.net/">Notational Velocity</a>.</li>
<li><a href="http://www.vmware.com/products/fusion/">VMWare Fusion</a> or <a href="http://www.parallels.com/products/desktop/">Parallels Desktop</a> if you need Windows/Linux VMs.</li>
<li><a href="http://www.red-sweater.com/marsedit/">MarsEdit</a> to write blog posts.</li>
<li><a href="http://flyingmeat.com/acorn/">Acorn</a> for image editing if you don't need or want <a href="http://www.adobe.com/products/photoshop/">Photoshop</a>.</li>
<li><a href="http://tinygrab.com/">TinyGrab</a> for screenshot sharing.</li>
<li><a href="http://developer.apple.com/technologies/xcode.html">Xcode</a> for gcc, make, and other dev tools. This also includes File Merge and the cli tool <tt>opendiff</tt>, for viewing diff/patch files.</li>
<li><a href="http://www.heliumfoot.com/mercurymover/">MercuryMover</a> for keyboard control of window positioning/sizing.</li>
</ul>
<p>&nbsp;</p>
<p>That's all that comes to mind. Feel free to add more in the comments and if I come across anything else, I'll update this article :)</p>
<p>&nbsp;</p>
 <p><a href="http://akrabat.com/?flattrss_redirect&amp;id=1235&amp;md5=914ce8325c7eb825789b6b352f4eb094" title="Flattr" target="_blank"><img src="http://akrabat.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://akrabat.com/computing/osx-tips-and-tricks-for-snow-leopar/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		<atom:link rel="payment" href="https://flattr.com/submit/auto?user_id=akrabat&amp;popout=1&amp;url=http%3A%2F%2Fakrabat.com%2Fcomputing%2Fosx-tips-and-tricks-for-snow-leopar%2F&amp;language=en_GB&amp;category=text&amp;title=OS+X+Tips+and+Tricks+for+Snow+Leopard&amp;description=Following+some+discussions+with+friends+who%27ve+recently+started+using+OS+X%2C+I+thought+I%27d+note+down+some+tips+and+tricks+that+I%27ve+learnt+since+I+moved+to+Mac.+This+is...&amp;tags=blog" type="text/html" />
	</item>
		<item>
		<title>Changing OS X Terminal colours when ssh&#039;ing into a server</title>
		<link>http://akrabat.com/computing/osx-terminal-colours/</link>
		<comments>http://akrabat.com/computing/osx-terminal-colours/#comments</comments>
		<pubDate>Fri, 02 Oct 2009 09:40:25 +0000</pubDate>
		<dc:creator>Rob...</dc:creator>
				<category><![CDATA[Computing]]></category>

		<guid isPermaLink="false">http://akrabat.com/?p=779</guid>
		<description><![CDATA[I recently discovered that iTerm has bookmarks so you can set up a bookmark to ssh into a server and change the colours of the window. This makes it easy to remember which terminal window is for which server. Thinking about it, I wondered if you could change the colours of the standard OS X [...]]]></description>
			<content:encoded><![CDATA[<p>I recently discovered that iTerm has bookmarks so you can set up a bookmark to ssh into a server and change the colours of the window. This makes it easy to remember which terminal window is for which server.</p>
<p>Thinking about it, I wondered if you could change the colours of the standard OS X Terminal via AppleScript. Inpired by Red Sweater's <a href="http://www.red-sweater.com/blog/220/random-color-terminal">Random Color Terminal</a> post, I wrote some code to automatically change the Terminal colour whenever I ssh into a known server.</p>
<p>As I know PHP and PHP is installed on OS X, I used that :)</p>
<p>The key to controlling AppleScript via PHP is the <tt>osascript</tt> command line application. The code I need specifically is:<br />
<!-- more --></p>
<pre class="phpcode"><span style="color: #0000BB">
system</span><span style="color: #007700">(</span><span style="color: #DD0000">"osascript&nbsp;-e&nbsp;'tell&nbsp;application&nbsp;\"Terminal\"
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set&nbsp;targetWindow&nbsp;to&nbsp;window&nbsp;1
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set&nbsp;background&nbsp;color&nbsp;of&nbsp;targetWindow&nbsp;to&nbsp;{"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$bgColour&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set&nbsp;cursor&nbsp;color&nbsp;of&nbsp;targetWindow&nbsp;to&nbsp;{"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$fgColour&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set&nbsp;normal&nbsp;text&nbsp;color&nbsp;of&nbsp;targetWindow&nbsp;to&nbsp;{"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$fgColour&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set&nbsp;bold&nbsp;text&nbsp;color&nbsp;of&nbsp;targetWindow&nbsp;to&nbsp;{"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$fgColour&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end&nbsp;tell'&nbsp;"</span><span style="color: #007700">);
</span>
</span></code></pre>
<p>where <tt>$bgColour</tt> and <tt>$fgColour</tt> are comma separated strings containing three numbers between 0 and 65535 as AppleScript colours are 16 bit.</p>
<p>We start by getting a command line solution where we can type:<br />
<tt>    termcolour.php white</tt><br />
or<br />
<tt>    termcolour.php 00ff00</tt><br />
or<br />
<tt>    termcolour.php 255 0 0</tt></p>
<p>and have the background colour of the Terminal change to the colour we have asked for. </p>
<h3>TerminalColour class</h3>
<p>Firstly we need a class that can change the colour of the Terminal window for us and also translate colours from 8bit RGB to 16bit RGB. As it is also useful to be able to specify colours by name, eg. "white", we'll add a lookup system too. I store this in /usr/local/bin.</p>
<p>This class is quite long, so this is a snippet:</p>
<pre class="phpcode">
<span style="color: #0000BB">&lt;?php
</span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">TerminalColour
</span><span style="color: #007700">{
&nbsp;&nbsp;&nbsp;&nbsp;protected&nbsp;</span><span style="color: #0000BB">$_colour&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">'255'</span><span style="color: #007700">,</span><span style="color: #DD0000">'255'</span><span style="color: #007700">,</span><span style="color: #DD0000">'255'</span><span style="color: #007700">);
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/**
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;List&nbsp;of&nbsp;colours
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">protected&nbsp;</span><span style="color: #0000BB">$_colours&nbsp;</span><span style="color: #007700">=&nbsp;array(
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'white'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'ffffff'</span><span style="color: #007700">,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'black'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'000000'</span><span style="color: #007700">,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;etc
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">);
&nbsp;&nbsp;&nbsp;&nbsp;

&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/**
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Set&nbsp;the&nbsp;colour&nbsp;of&nbsp;the&nbsp;topmost&nbsp;Terminal&nbsp;window&nbsp;using&nbsp;AppleScript
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;$bgColour&nbsp;may&nbsp;be&nbsp;either&nbsp;an&nbsp;array&nbsp;of&nbsp;red,&nbsp;green,&nbsp;blue&nbsp;(8&nbsp;bit)&nbsp;or&nbsp;a&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;hex&nbsp;string&nbsp;or&nbsp;a&nbsp;string&nbsp;that&nbsp;matches&nbsp;an&nbsp;entry&nbsp;in&nbsp;the&nbsp;_colours&nbsp;lookup&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;list.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;If&nbsp;$fgColour&nbsp;is&nbsp;null,&nbsp;then&nbsp;automatically&nbsp;use&nbsp;either&nbsp;black&nbsp;or
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;white&nbsp;based&nbsp;on&nbsp;brightness&nbsp;of&nbsp;$bgColour.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;array|string&nbsp;$bgColour
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;array|string&nbsp;$fgColour
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@return&nbsp;array
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">setTerminalColour</span><span style="color: #007700">(</span><span style="color: #0000BB">$bgColour</span><span style="color: #007700">=</span><span style="color: #0000BB">null</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$fgColour</span><span style="color: #007700">=</span><span style="color: #0000BB">null</span><span style="color: #007700">)&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(!</span><span style="color: #0000BB">is_null</span><span style="color: #007700">(</span><span style="color: #0000BB">$bgColour</span><span style="color: #007700">))&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setColour</span><span style="color: #007700">(</span><span style="color: #0000BB">$bgColour</span><span style="color: #007700">);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$bgColour&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getColour</span><span style="color: #007700">();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;convert&nbsp;from&nbsp;8&nbsp;bit&nbsp;colour&nbsp;numbers&nbsp;to&nbsp;16&nbsp;bit&nbsp;ones
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$bgColour&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">convertTo16bit</span><span style="color: #007700">(</span><span style="color: #0000BB">$bgColour</span><span style="color: #007700">);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(</span><span style="color: #0000BB">$fgColour&nbsp;</span><span style="color: #007700">===&nbsp;</span><span style="color: #0000BB">null</span><span style="color: #007700">)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$fgColour&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getFgColour</span><span style="color: #007700">(</span><span style="color: #0000BB">$bgColour</span><span style="color: #007700">);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$bgColour&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">implode</span><span style="color: #007700">(</span><span style="color: #DD0000">','</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$bgColour</span><span style="color: #007700">);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$fgColour&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">implode</span><span style="color: #007700">(</span><span style="color: #DD0000">','</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$fgColour</span><span style="color: #007700">);
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">system</span><span style="color: #007700">(</span><span style="color: #DD0000">"osascript&nbsp;-e&nbsp;'tell&nbsp;application&nbsp;\"Terminal\"
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set&nbsp;targetWindow&nbsp;to&nbsp;window&nbsp;1
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set&nbsp;background&nbsp;color&nbsp;of&nbsp;targetWindow&nbsp;to&nbsp;{"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$bgColour&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set&nbsp;cursor&nbsp;color&nbsp;of&nbsp;targetWindow&nbsp;to&nbsp;{"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$fgColour&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set&nbsp;normal&nbsp;text&nbsp;color&nbsp;of&nbsp;targetWindow&nbsp;to&nbsp;{"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$fgColour&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set&nbsp;bold&nbsp;text&nbsp;color&nbsp;of&nbsp;targetWindow&nbsp;to&nbsp;{"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$fgColour&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end&nbsp;tell'&nbsp;"</span><span style="color: #007700">);
&nbsp;&nbsp;&nbsp;&nbsp;}
}
</span>
</span></code></pre>
<p>As you can see, there's a variety of helper methods that I've not show here. <tt>setColour()</tt> is the where we map from the types of input that the user will provide to an array. Other that that, it's fairly self-explanatory. </p>
<h3>Change colour from the command line</h3>
<p>Now we need a script that uses our class. <tt>termcolours.php</tt>, that I can execute from the command line to change any given Terminal window to a new background colour. </p>
<p><tt>termcolour.php</tt> is stored in /usr/local/bin and has execute permissions set using <tt>chmod a+x termcolour.php</tt> from the command line:</p>
<pre class="phpcode">
#!/usr/bin/php
<span style="color: #0000BB">&lt;?php
</span><span style="color: #007700">include&nbsp;</span><span style="color: #0000BB">dirname</span><span style="color: #007700">(</span><span style="color: #0000BB">__FILE__</span><span style="color: #007700">)&nbsp;.&nbsp;</span><span style="color: #DD0000">'/TerminalColour.php'</span><span style="color: #007700">;

</span><span style="color: #0000BB">process</span><span style="color: #007700">(</span><span style="color: #0000BB">$argc</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$argv</span><span style="color: #007700">);
exit;

function&nbsp;</span><span style="color: #0000BB">process</span><span style="color: #007700">(</span><span style="color: #0000BB">$argc</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$argv</span><span style="color: #007700">)
{
&nbsp;&nbsp;&nbsp;&nbsp;if(</span><span style="color: #0000BB">$argc&nbsp;</span><span style="color: #007700">==&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;&lt;&lt;&lt;EOT
</span><span style="color: #DD0000">TerminalColour:&nbsp;Set&nbsp;the&nbsp;background&nbsp;colour&nbsp;of&nbsp;a&nbsp;Terminal.app&nbsp;window&nbsp;
USAGE:&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;1.&nbsp;termcolour.php&nbsp;{r}&nbsp;{g}&nbsp;{b}&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;({r},&nbsp;{g},&nbsp;{b}&nbsp;are&nbsp;between&nbsp;0&nbsp;and&nbsp;255)
&nbsp;&nbsp;&nbsp;&nbsp;2.&nbsp;termcolour.php&nbsp;{hexvalue}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;({hexvalue}&nbsp;assumed&nbsp;to&nbsp;be&nbsp;from&nbsp;000&nbsp;to&nbsp;fff&nbsp;or&nbsp;00000&nbsp;to&nbsp;ffffff)

</span><span style="color: #007700">EOT;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit;
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$tc&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">TerminalColour</span><span style="color: #007700">();
&nbsp;&nbsp;&nbsp;&nbsp;if(</span><span style="color: #0000BB">$argc&nbsp;</span><span style="color: #007700">==&nbsp;</span><span style="color: #0000BB">4</span><span style="color: #007700">)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;called&nbsp;with&nbsp;three&nbsp;arguments&nbsp;-&nbsp;treat&nbsp;as&nbsp;rgb&nbsp;values&nbsp;(0-255)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">array_shift</span><span style="color: #007700">(</span><span style="color: #0000BB">$argv</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">//&nbsp;remove&nbsp;name&nbsp;of&nbsp;script
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$tc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setTerminalColour</span><span style="color: #007700">(</span><span style="color: #0000BB">$argv</span><span style="color: #007700">);
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;if(</span><span style="color: #0000BB">$argc&nbsp;</span><span style="color: #007700">==&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;called&nbsp;with&nbsp;one&nbsp;argument&nbsp;-&nbsp;either&nbsp;a&nbsp;lookup&nbsp;or&nbsp;a&nbsp;hex&nbsp;value
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$tc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setTerminalColour</span><span style="color: #007700">(</span><span style="color: #0000BB">$argv</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">]);
&nbsp;&nbsp;&nbsp;&nbsp;}
}
</span>
</span></code></pre>
<p>Again, not complicated. we check number of arguments to the script and if there are none, we display a help message. If there are exactly 1 or 3, then we call <tt>TerminalColour::setTerminalColour()</tt> appropriately.</p>
<h3>Hooking into SSH</h3>
<p>Lastly we hook into ssh and change the colour based on the server name.</p>
<p>To do this, I've used a simple shell script and modified termcolours.php to add some additional colour look up entries.</p>
<p><strong>/usr/local/bin/sshcolours.sh:</strong><br />
/usr/local/bin/termcolour.php $@<br />
/usr/bin/ssh $@<br />
/usr/local/bin/termcolour.php white</p>
<p><strong>termcolour.php</strong></p>
<pre class="phpcode"><span style="color: #0000BB">
</span><span style="color: #FF8000">//...
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$tc&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">TerminalColour</span><span style="color: #007700">();

&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;add&nbsp;colours&nbsp;for&nbsp;servers
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$colourLookup&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$tc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getLookupColours</span><span style="color: #007700">();
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$serverColours&nbsp;</span><span style="color: #007700">=&nbsp;array(
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'server1'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">$colourLookup</span><span style="color: #007700">[</span><span style="color: #DD0000">'darkblue'</span><span style="color: #007700">],
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'server2'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">$colourLookup</span><span style="color: #007700">[</span><span style="color: #DD0000">'red'</span><span style="color: #007700">],
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'server3'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'C4DFC3'</span><span style="color: #007700">,
&nbsp;&nbsp;&nbsp;&nbsp;);
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$tc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addToLookupColours</span><span style="color: #007700">(</span><span style="color: #0000BB">$serverColours</span><span style="color: #007700">);

&nbsp;&nbsp;&nbsp;&nbsp;if(</span><span style="color: #0000BB">$argc&nbsp;</span><span style="color: #007700">==&nbsp;</span><span style="color: #0000BB">4</span><span style="color: #007700">)&nbsp;{
</span><span style="color: #FF8000">//...
</span>
</span></code></pre>
<p>(not a large change!)</p>
<p>finally, we add an alias to ~/.bash_profile:</p>
<pre class="phpcode"><span style="color: #0000BB">
alias&nbsp;s</span><span style="color: #007700">=</span><span style="color: #0000BB">sshcolours</span><span style="color: #007700">.</span><span style="color: #0000BB">sh
</span>
</span></code></pre>
<p>That's it! I can now type:</p>
<pre>
	s server1
</pre>
<p>and Terminal's background colour turns blue and I'm ssh'd into server 1. </p>
<p>Sometimes I just type <tt>termcolour.php darkred</tt> to remind myself that this terminal window is doing something long-running and not to accidentally close it...</p>
<p>This is a <a href="/wp-content/uploads/terminal_colours.zip">zip file</a> of the relevant files.</p>
 <p><a href="http://akrabat.com/?flattrss_redirect&amp;id=779&amp;md5=54d2b0b790c7d5bb471bbb7389722375" title="Flattr" target="_blank"><img src="http://akrabat.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://akrabat.com/computing/osx-terminal-colours/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<atom:link rel="payment" href="https://flattr.com/submit/auto?user_id=akrabat&amp;popout=1&amp;url=http%3A%2F%2Fakrabat.com%2Fcomputing%2Fosx-terminal-colours%2F&amp;language=en_GB&amp;category=text&amp;title=Changing+OS+X+Terminal+colours+when+ssh%27ing+into+a+server&amp;description=I+recently+discovered+that+iTerm+has+bookmarks+so+you+can+set+up+a+bookmark+to+ssh+into+a+server+and+change+the+colours+of+the+window.+This+makes+it+easy...&amp;tags=blog" type="text/html" />
	</item>
		<item>
		<title>Uninstalling MySQL on Mac OS X Leopard</title>
		<link>http://akrabat.com/computing/uninstalling-mysql-on-mac-os-x-leopard/</link>
		<comments>http://akrabat.com/computing/uninstalling-mysql-on-mac-os-x-leopard/#comments</comments>
		<pubDate>Thu, 11 Sep 2008 20:48:06 +0000</pubDate>
		<dc:creator>Rob...</dc:creator>
				<category><![CDATA[Computing]]></category>

		<guid isPermaLink="false">http://akrabat.com/?p=258</guid>
		<description><![CDATA[To uninstall MySQL and completely remove it (including all databases) from your Mac do the following: Use mysqldump to backup your databases to text files! Stop the database server sudo rm /usr/local/mysql sudo rm -rf /usr/local/mysql* sudo rm -rf /Library/StartupItems/MySQLCOM sudo rm -rf /Library/PreferencePanes/My* edit /etc/hostconfig and remove the line MYSQLCOM=-YES- rm -rf ~/Library/PreferencePanes/My* sudo [...]]]></description>
			<content:encoded><![CDATA[<p>To uninstall MySQL and completely remove it (including all databases) from your Mac do the following:</p>
<ul>
<li>Use mysqldump to backup your databases to text files!</li>
<li>Stop the database server</li>
<li><tt>sudo rm /usr/local/mysql</tt></li>
<li><tt>sudo rm -rf /usr/local/mysql*</tt></li>
<li><tt>sudo rm -rf /Library/StartupItems/MySQLCOM</tt></li>
<li><tt>sudo rm -rf /Library/PreferencePanes/My*</tt></li>
<li>edit /etc/hostconfig and remove the line MYSQLCOM=-YES-</li>
<li><tt>rm -rf ~/Library/PreferencePanes/My*</tt></li>
<li><tt>sudo rm -rf /Library/Receipts/mysql*</tt></li>
<li><tt>sudo rm -rf /Library/Receipts/MySQL*</tt></li>
<li><tt>sudo rm -rf /private/var/db/receipts/*mysql*</tt></li>
</ul>
<p>The last three lines are particularly important as otherwise, you can't install an older version of MySQL even though you think that you've completely deleted the newer version!</p>
 <p><a href="http://akrabat.com/?flattrss_redirect&amp;id=258&amp;md5=79b886a86f19f98c5a22d9c8f6d6ca86" title="Flattr" target="_blank"><img src="http://akrabat.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://akrabat.com/computing/uninstalling-mysql-on-mac-os-x-leopard/feed/</wfw:commentRss>
		<slash:comments>79</slash:comments>
		<atom:link rel="payment" href="https://flattr.com/submit/auto?user_id=akrabat&amp;popout=1&amp;url=http%3A%2F%2Fakrabat.com%2Fcomputing%2Funinstalling-mysql-on-mac-os-x-leopard%2F&amp;language=en_GB&amp;category=text&amp;title=Uninstalling+MySQL+on+Mac+OS+X+Leopard&amp;description=To+uninstall+MySQL+and+completely+remove+it+%28including+all+databases%29+from+your+Mac+do+the+following%3A+Use+mysqldump+to+backup+your+databases+to+text+files%21+Stop+the+database+server+sudo...&amp;tags=blog" type="text/html" />
	</item>
		<item>
		<title>svn and case-insentive file systems</title>
		<link>http://akrabat.com/computing/svn-and-case-insentive-file-systems/</link>
		<comments>http://akrabat.com/computing/svn-and-case-insentive-file-systems/#comments</comments>
		<pubDate>Sat, 10 Nov 2007 18:56:31 +0000</pubDate>
		<dc:creator>Rob...</dc:creator>
				<category><![CDATA[Computing]]></category>

		<guid isPermaLink="false">http://akrabat.com/2007/11/10/svn-and-case-insentive-file-systems/</guid>
		<description><![CDATA[Another one to chalk up to a doh! moment... I'm checking out my wife's website to my new MacBook and get this error message: svn: In directory 'website/gallery/piccies' svn: Can't move source to dest svn: Can't move 'website/gallery/piccies/.svn/tmp/prop-base/IMG_0013-thumb.jpg.svn-base' to 'website/gallery/piccies/.svn/prop-base/IMG_0013-thumb.jpg.svn-base': No such file or directory I'm pretty sure that there's no problem with the subversion [...]]]></description>
			<content:encoded><![CDATA[<p>Another one to chalk up to a doh! moment...</p>
<p>I'm checking out my wife's website to my new MacBook and get this error message:</p>
<blockquote><p>
svn: In directory 'website/gallery/piccies'<br />
svn: Can't move source to dest<br />
svn: Can't move 'website/gallery/piccies/.svn/tmp/prop-base/IMG_0013-thumb.jpg.svn-base' to 'website/gallery/piccies/.svn/prop-base/IMG_0013-thumb.jpg.svn-base': No such file or directory
</p></blockquote>
<p>I'm pretty sure that there's no problem with the subversion repository as I've been using it for months with no problem so I asked a friend to check it out on his Windows box... which failed with the same error. We thought at first that linux was allowing something illegal to occur which Windows and Macs weren't. Then we thought about the other differences between Linux and Windows/Mac OS X.</p>
<p>After a while. It turns out that there are two files in the directory: IMG_0013.jpg and IMG_0013.JPG. One svn mv command later and the problem is solved.</p>
<p>It would have been nice to have had a better error message though!</p>
 <p><a href="http://akrabat.com/?flattrss_redirect&amp;id=199&amp;md5=fe9dba9e946b378d6728085858294dd6" title="Flattr" target="_blank"><img src="http://akrabat.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://akrabat.com/computing/svn-and-case-insentive-file-systems/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<atom:link rel="payment" href="https://flattr.com/submit/auto?user_id=akrabat&amp;popout=1&amp;url=http%3A%2F%2Fakrabat.com%2Fcomputing%2Fsvn-and-case-insentive-file-systems%2F&amp;language=en_GB&amp;category=text&amp;title=svn+and+case-insentive+file+systems&amp;description=Another+one+to+chalk+up+to+a+doh%21+moment...+I%27m+checking+out+my+wife%27s+website+to+my+new+MacBook+and+get+this+error+message%3A+svn%3A+In+directory+%27website%2Fgallery%2Fpiccies%27+svn%3A+Can%27t...&amp;tags=blog" type="text/html" />
	</item>
		<item>
		<title>The move to Mac</title>
		<link>http://akrabat.com/computing/the-move-to-mac/</link>
		<comments>http://akrabat.com/computing/the-move-to-mac/#comments</comments>
		<pubDate>Fri, 09 Nov 2007 08:17:57 +0000</pubDate>
		<dc:creator>Rob...</dc:creator>
				<category><![CDATA[Computing]]></category>

		<guid isPermaLink="false">http://akrabat.com/2007/11/09/the-move-to-mac/</guid>
		<description><![CDATA[A couple of days after Leopard came out, my wife and I found ourselves in the Apple store in Solihull and came away with an iMac for her and a MacBook Pro for me. The main reasons we have been interested in Macs recently are: Disappointed with Vista on my wife's brand new computer Disappointed [...]]]></description>
			<content:encoded><![CDATA[<p>A couple of days after <a href="http://www.apple.com/uk/macosx/">Leopard</a> came out, my wife and I found ourselves in the Apple store in Solihull and came away with an iMac for her and a MacBook Pro for me.</p>
<p>The main reasons we have been interested in Macs recently are:</p>
<ul>
<li>Disappointed with Vista on my wife's brand new computer</li>
<li>Disappointed with our last two Inspiron laptops</li>
<li>Sleep that works</li>
<li>The hardware looks good!</li>
<li>Unix in the terminal</li>
</ul>
<p>Interestingly, the biggest benefit we've noticed since purchase is how quiet they are. We didn't realise how noisy those PCs under the desk actually were til we got rid of them.</p>
<p>The biggest challenge has been adapting to the keyboard. The @, " and \ keys in particular are in the "wrong" place, and carat navigation is maddeningly inconsistent between applications. I've worked out that Option+left/right move per word and command+left/right is supposed to move to the start/end of the line. Command+up/down usually moves to the top and bottom of the document, but I haven't found page up/down yet but suspect it has something to do with function option and up,down left or right!</p>
<p>We haven't worked out when we need to quit applications vs just closing the window which leaves the app running.</p>
<p>PHP 5.2.4 was installed by Apple and just needed turning on in httpd.conf (it's in /etc... did I mention how nice having Unix underneath is?!) What's odd is that PDO isn't there and so I suspect that I'm going to have to compile my own PHP at some point.</p>
 <p><a href="http://akrabat.com/?flattrss_redirect&amp;id=197&amp;md5=d64050fdfbb2c263764b8cc8053babe1" title="Flattr" target="_blank"><img src="http://akrabat.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://akrabat.com/computing/the-move-to-mac/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		<atom:link rel="payment" href="https://flattr.com/submit/auto?user_id=akrabat&amp;popout=1&amp;url=http%3A%2F%2Fakrabat.com%2Fcomputing%2Fthe-move-to-mac%2F&amp;language=en_GB&amp;category=text&amp;title=The+move+to+Mac&amp;description=A+couple+of+days+after+Leopard+came+out%2C+my+wife+and+I+found+ourselves+in+the+Apple+store+in+Solihull+and+came+away+with+an+iMac+for+her+and+a...&amp;tags=blog" type="text/html" />
	</item>
		<item>
		<title>Do it before goddamned breakfast</title>
		<link>http://akrabat.com/computing/do-it-before-goddamned-breakfast/</link>
		<comments>http://akrabat.com/computing/do-it-before-goddamned-breakfast/#comments</comments>
		<pubDate>Fri, 26 Oct 2007 05:52:28 +0000</pubDate>
		<dc:creator>Rob...</dc:creator>
				<category><![CDATA[Computing]]></category>

		<guid isPermaLink="false">http://akrabat.com/2007/10/26/do-it-before-goddamned-breakfast/</guid>
		<description><![CDATA[jwz on 29th Oct 2007: When (WHEN) your backup drive goes bad, which you will notice because your last backup failed, replace it immediately. This is your number one priority. Don't wait until the weekend when you have time, do it now, before you so much as touch your computer again. Do it before goddamned [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://jwz.livejournal.com/801607.html">jwz</a> on 29th Oct 2007:</p>
<blockquote><p>When (WHEN) your backup drive goes bad, which you will notice because your last backup failed, replace it immediately. This is your number one priority. Don't wait until the weekend when you have time, do it now, before you so much as touch your computer again. Do it before goddamned breakfast. The universe tends toward maximum irony. Don't push it.</p></blockquote>
<p>Some very good advice. I just back up my "cannot afford to lose" data at the moment. If I lose my hard drive, I have a good day or so of reinstalling and re-setting-up to look forward to. It's probably worth the &pound;100 or so for a new hard drive.</p>
 <p><a href="http://akrabat.com/?flattrss_redirect&amp;id=196&amp;md5=1823b08370f9b6745694123b3561d0b3" title="Flattr" target="_blank"><img src="http://akrabat.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://akrabat.com/computing/do-it-before-goddamned-breakfast/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<atom:link rel="payment" href="https://flattr.com/submit/auto?user_id=akrabat&amp;popout=1&amp;url=http%3A%2F%2Fakrabat.com%2Fcomputing%2Fdo-it-before-goddamned-breakfast%2F&amp;language=en_GB&amp;category=text&amp;title=Do+it+before+goddamned+breakfast&amp;description=jwz+on+29th+Oct+2007%3A+When+%28WHEN%29+your+backup+drive+goes+bad%2C+which+you+will+notice+because+your+last+backup+failed%2C+replace+it+immediately.+This+is+your+number+one+priority....&amp;tags=blog" type="text/html" />
	</item>
	</channel>
</rss>

