tag:ryankinderman.net,2005:/tag/mackinderman.net : Tag mac, everything about maccode code code2007-11-12T18:23:35-08:00Typotag:ryankinderman.net,2005:Article/1032007-11-11T22:21:32-08:002007-11-12T18:23:35-08:00ryanAppleScript: Reverse screen colors on a Mac and keep a black background in Terminal<p>Sometimes, it's such a hassle to get up and turn on a light when I'm in the middle of coding. Other times, I don't have control over the lighting, like in a dim pub or cafe. In dim lighting, it's a strain on my eyes to be looking at black text on a white background. I've tried dimming the brightness, but that decreases the contrast, which is also a strain on my eyes. Then, I discovered Control+Option+Command+8, which is a keyboard shortcut to the "Reverse black and white" Universal Access feature. Contrary to it's name, it does more than reverse black and white, it reverses all of the colors on the screen. This, however, is acceptable and requires only a slight mental adjustment for me. Now I use a nice black-on-white color scheme in TextMate for coding, and when I'm in dim lighting, I simply reverse the colors and it's white-on-black, still full-contrast. I'm happy, except for one thing.</p>
<p>I often have a number of Terminal windows open when I'm working, and I open and close them frequently. Although I'm happy with a black-on-white color scheme for TextMate, I can't tolerate anything but white-on-black for my normal Terminal windows. So, what happens when I throw the screen colors in reverse is that all of my lovely white-on-black Terminal windows go to black-on-white. Unacceptable! Thus began my first foray into AppleScript.</p>
<p>After referencing <a href="http://lists.apple.com/archives/Cocoa-dev/2006/Jun/msg01433.html">here</a>, <a href="http://www.oreilly.com/catalog/aplscptian/chapter/ch07.html">here</a>, and <a href="http://developer.apple.com/applescript/">here</a>, along with the Terminal "dictionary", I came up with this:</p>
<pre><code>tell application "System Events"
tell application processes
key code 28 using {command down, option down, control down}
end tell
end tell
tell application "Terminal"
if default settings is equal to settings set "White on Black" then
set settingsSet to "Black on White"
else if default settings is equal to settings set "Black on White" then
set settingsSet to "White on Black"
end if
set default settings to settings set settingsSet
repeat with w in every window
set current settings of w to settings set settingsSet
end repeat
end tell
</code></pre>
<p>This script first invokes the Control+Option+Command+8 keyboard shortcut to reverse the screen colors. It then toggles the default "settings set" for Terminal to one of two pre-defined sets I've created: "White on Black" and "Black on White". Hopefully the names are self-explanatory. Then, the script iterates over all currently-open Terminal windows and changes their current "settings set" to whatever the new default is.</p>
<p>Pretty simple. I named the script "Reverse Screen Colors" and dropped it in /Users/[user account]/Library/Scripts. I invoke it via the keyboard with <a href="http://www.blacktree.com/">QuickSilver</a>.</p>tag:ryankinderman.net,2005:Article/872007-09-03T12:41:38-07:002007-09-22T08:43:50-07:00ryanHOWTO: Clean the distribution files for all installed MacPorts packages<p>I've been using a MacBook Pro for a while now. I got it when I started getting deep into the Ruby/Rails stuff. Being a developer, I use a lot of unix-y command-line tools, server software, and so on. The best way to install these types of things is to use some sort of package manager, such as <a href="http://finkproject.org/">Fink</a> or <a href="http://www.macports.org/">MacPorts</a>, the latter being the one I've chosen to use. With MacPorts, I can install, upgrade, or uninstall most of the open source apps that I love in Linux. However, there's a catch to MacPorts' ease of use: it doesn't clean up the packages that it downloads when you install/upgrade/uninstall an app unless you tell it to.</p>
<p>An example of an app that I installed recently that would be a pain to compile/install using a traditional build script is Tomcat 5. Tomcat 5 has 20+ library dependencies, some of which have their dependencies of their own. When I ran <code>sudo port install tomcat5</code>, it took about 20 minutes or so to download and compile everything. However, I never had to do anything else. I literally walked away and checked back periodically until it was done.</p>
<p>Today I decided that, since I was only using Tomcat for occasional development, I'd rather have it, and its plethora of dependencies, installed on a Linux VM instead of my real machine, so it didn't sit there eating up resources all the time. So, I went through and uninstalled everything. But I noticed a while ago that there was a 'clean' command for MacPorts that removed the downloaded packages from an install of an app, and I was curious about whether or not my uninstalling of Tomcat and it's dependencies resulted in these packages being auto-cleaned. So, I took a look in <code>/opt/local/var/macports/distfiles</code> and was surprised to find that the install packages for most of the apps I've ever installed/upgraded/uninstalled were still there!</p>
<p>Now, since these packages mainly consist of compressed source code, it's not going to eat up a lot of hard drive space. But, I had quite a few built up, and would rather not have them sitting there for no reason. Rather than go through and 'clean' each one individually, I created a bash script to do this for me for all packages represented in the <code>distfiles</code> directory. Since I know a few people who use MacPorts that aren't exactly savvy with *nix command-line tools, I thought I'd share it:</p>
<p>File: clean_ports</p>
<pre><code>#!/bin/bash
ls -1 /opt/local/var/macports/distfiles | \
awk '{
if ($1 !~ /^\./) {
system("port clean --all " $1)
}
}'
</code></pre>
<p>Just throw this into a file and then run <code>chmod +x clean_ports</code> to make it executable. Now you can just periodically run <code>clean_ports</code> to avoid unnecessary build-up of the remnants of MacPorts installs.</p>
<p><em>Addendum</em>: Aaron Schaefer mentioned in the comments that this same thing can be done using MacPorts pseudo-portnames. So, the simpler solution is to do: <code>sudo port clean --all installed</code></p>