Mac OS X – Moving Windows Quick Tip

If your Mac won’t let you move a window because of a dialog or something, but you really want to move the window, just open Spaces and move the window from there! This seems to work every time. Its made working with some poorly developed applications a little easier.

Now if I could just make some dialogs stay in front of the actual application window I would be completely happy!

Mini MP3 Searching Shell – Skreemr

So its way to hard to download an mp3 in Safari. Right click the link and download? Pff, I want to ⌃S and be done with it. Well, this time I decided to avoid the problem all together. I use Skreemr to search for a particular song when it interests me.

In the past I wrote a little bash script, that makes use of curl, to download an mp3 to my desktop unique named so it wouldn’t have conflicts. This shell essentially wraps and drastically improves that to allow for searching, pagination, history, downloading, and opening mp3s off of Skreemr. It gives me just what I need. The functionality that I want without having to use torrents etc. I’m thinking of turning this into a gem.


This script requires the popular “escape.rb” script that gives some nice and safe shell escaping functions. You can download both from my GitHub scripts project.

Of course its available on my ~/bin and there will be another article later on that goes over a few aspects of this simple little script.


Instant Web Sharing on Your Mac

I came across a few articles recently that point out how to instantly share a folder on your computer. They basically ride on top of this elegant python script:

python -m SimpleHTTPServer

It works great but I wanted to improve on it in a number of ways:

  • Automatically copy a URI into my clipboard so I can easily paste it to others.

  • Make that URI nicer then just an IP address.

  • Use a non-standard port, for security.

  • Open in a new tab so I can keep working in the directory and yet still monitor the HTTP requests being made.

Here was what I produced. (Its up in my ~/bin.)

# Start Date: Sunday February 8, 2009
# Current Version: 0.9
# Author: Joseph Pecoraro
# Contact:
# Decription:  Immediately Share the current directory
#   in a new tab so you can monitor the requests made
#   have your original tab to continue working in that
#   directory.  Meant for Mac OS X.
#   1. Echos the URI
#   2. Puts the URI into your Clipboard
#   3. Opens a new tab in the terminal
#   4. Changes Directory to the other tabs directory
#   5. Echos the URI
#   6. Runs the Web Server
#   7. Optionally Opens in Safari
# Sources that Helped:
#   New Tab Here:
#   HTTPServer:
#   Paul Berens:

# -----------------
#   Host and Port
# -----------------

# This gets your ip address and converts it to a nice string
es_host=$(curl --silent
es_host=$(nslookup $es_host | awk '/name =/{print substr($4,1,length($4)-1)}')

# -----------------
#   Script Below
# -----------------

echo "http://$es_host:$es_port"
echo -n "http://$es_host:$es_port" | pbcopy
osascript -e "
Tell application \"Terminal\"
  tell application \"System Events\" to tell process \"Terminal\" to keystroke \"t\" using command down
  do script with command \"cd '$(pwd)'\" in selected tab of the front window
  do script with command \"clear; echo '$es_host:$es_port/'\" in selected tab of the front window
  do script with command \"python -m SimpleHTTPServer $es_port\" in selected tab of the front window
end tell" &> /dev/null

# Optional: Open Safari, Just Uncomment the next line
# open "http://$es_host:$es_port"

# Cleanup
unset es_host
unset es_port

Now that should work on any Mac. And it should give a nicer URL then an ugly IP address. You should see something like this:


As soon as it starts you can paste the URL to anyone you’re chatting with. It couldn’t be simpler!

If you’re experienced enough with DNS servers and you’ve given your computer a Dynamic Name you can customize the script. Paul Berens gave me a great suggestion to determine if I’m on my local network at home. I can check the MAC address of my default gateway (my wireless router). That is a quick check to see if I’m at home. If I’m at home I use my URI automatically! Otherwise it defaults to generating the dynamic address generation. Check it out:

# -----------------
#   Host and Port
# -----------------

# Mac Address of my Router At Home
if [ -n "$(arp -a | grep 0:1e:2a:76:17:98)" ]; then
# Otherwise Dynamically Determine
  es_host=$(curl --silent
  es_host=$(nslookup $es_host | awk '/name =/{print substr($4,1,length($4)-1)}')

So now when I run easy_share at my house it always throws out URIs. Much nicer on the eyes and easy to remember. I’ll write about dynamic names like this another time!

Dynamic Web URLs with ExpanDrive

Often when I work with ExpanDrive the files I am working on correspond to some website that I own. When I’m mounted with ExpanDrive each file is accessible via “my hard drive” in the mounted volume and, more importantly, from a web URL! I found myself repeatedly opening up my browser and manually typing the URL for files that I just uploaded or edited. This was error prone, especially if some of the characters needed encoding. So, I spent some time to write up a Ruby script that can read ExpanDrive’s preferences, build the file’s “web URL,” and open it in your default browser.

expanurl usage

Simple to Use

I followed along with ExpanDrive’s previous command line tool named expan and named my script expanurl. Given no arguments it will open the current directory via its web URL, or you can give a list of files and each will be opened at their web URLs. Its usage is pretty straightforward but there is a single catch: the server setting in an ExpanDrive Drive may not be a true one-to-one mapping with the web server’s address.

For example: I provide as the server value for one of my personal ExpanDrive drives. However, when I view files on that server (inside the public_html directory) they have a much different looking URL: The result? The script simply keeps its own mapping of ExpanDrive server values to their associated web page prefixes. When you use expanurl on a Drive you have never used it on before the script will prompt you for that mapping, store the value, and never ask again.

Here it is in action. I have removed all stored mappings so I can demonstrate what it would be like using expanurl for the first time. Here I use it on my BogoJoker ExpanDrive drive:

expanurl first usage

Notice that in the prompt it tells you:

  • the server that the ExpanDrive volume is linked to and the one you will be providing a web url prefix for
  • an example of a web url prefix (useful)
  • where the mappings are stored in case you need to edit them later

The script is available on GitHub, so feel free to contribute and improve. Here is a link to the always current version, and here is a snapshot of the current version at the time of writing:


#!/usr/bin/env ruby
# Author: Joseph Pecoraro
# Date: Saturday December 13, 2008
# Description: When I'm using ExpanDrive and I'm
# remotely logged into a server, I can use this
# script to "open filename" and it will open using
# the server's associated URL.

# For URL Escaping and Stored Mappings
require 'uri'
require 'yaml'

# Exit with a msg
def err(msg)
  puts msg
  exit 1

# Simple Class to handle the mappings
class UrlMap
  MAP_PATH = File.expand_path('~/.expanurl')
  def initialize
    @hash = load
  def load
    if File.exists?(MAP_PATH)
      YAML::load_file( File.expand_path(MAP_PATH) )
  def add_mapping(server, mapto)
    @hash[server] = mapto, 'w') do |file|
  def is_mapping?(server)
  def get_mapping(server)
  def path

# Local Variables
mapping =
url_prefix = nil
server = nil
volume = nil

# Check the if the current directory is an
# ExpanDrive Volume and a public_html folder
pwd = `pwd`
match = pwd.match(/^\/Volumes\/([^\/]+)/)
if match.nil?
  err("Not inside an ExpanDrive Volume")
elsif !pwd.match(/\/public_html\/?/)
  err("Not inside a public_html directory.")
  volume = match[1]
  defaults = `defaults read com.magnetk.ExpanDrive Drives`
  defaults.gsub!(/\n/, '')
  props = defaults.match(/\{[^\}]+driveName\s+=\s+#{volume}[^\}]+server\s+=\s+"([^"]+)"[^\}]+\}/)
  if props
    server = props[1]
    err("This Volume (#{volume}) is not an ExpanDrive Volume")

# Check if a mapping exists
# Otherwise create and store one
if mapping.is_mapping?(server)
  url_prefix = mapping.get_mapping(server)
  # Prompt
  puts "This is the first time you've used expanurl for #{volume}"
  puts "Please Provide us with a mapping for #{server}"
  puts "Mappings are stored in #{mapping.path}"
  puts "Example:"
  print ">> "
  # Store user input and proceed
  url_prefix = gets.chomp
  url_prefix += '/' unless url_prefix.match(/\/$/)
  mapping.add_mapping(server, url_prefix)
  # Terminal Output
  puts "Server: #{server}"
  puts "Maps to: #{url_prefix}"


# Build the URL
subpath = pwd.match(/public_html\/?(.*)/)[1]
subpath += '/' unless || subpath.match(/\/$/)
url_prefix += subpath

# If No Files, open the directory
# Otherwise,   open each provided file
if ARGV.size == 0
  `open #{url_prefix}`
  ARGV.each do |filename|
    `open #{url_prefix}#{URI.escape(filename)}`


How it Works

The Ruby Script grabs the current working directory using `pwd` and checks to make sure you’re in an ExpanDrive volume. ExpanDrive volume’s are dynamically generated by parsing the ExpanDrive preferences thanks to their foresight to make them accessible via the `defaults` command. So if you’re in an ExpanDrive volume and inside a public_html directory expanurl will then use its mapping to open a uri encoded web url in your default browser with the `open` command.

The mappings are stored in a hidden YAML file in your home directory (~/.expanurl). This style of storing preferences is just like dozens of other command line applications and scripts. YAML is just a lightweight textual data format popular with Ruby, similar to JSON and XML. Its so simple that you could edit the file yourself if you wanted/needed to. For instance here is what is in mine, just two simple key/value pairs:

~/.expanurl yaml mapping

The Future

Its just that simple. Being a Ruby Script you can call this from GUI applications, anything with built-in shell access, etc. It should play friendly with your usual Unix tools. I will likely make this script more and more robust if others find it useful, so I’d be happy to hear some feedback.


Spaces, Exposé, Hot Corners, Dashboard Broken?

I ferociously make use of Spaces and Exposé. To utilize them I use QuickSilver, Cmd+Tab, the Dock, special Mouse Buttons, but most of all I use the Hot Corners! Occasionally, when I wake my Mac Book Pro these features won’t work. No reason given, just when I try I get the usual chime meaning “this can’t be done.” At the time the only sure solution was to reboot the computer. Not anymore. Just open up your terminal and run:

killall Dock

Since those major features (Spaces, Exposé, and the Dashboard) are tied to the Dock, this command will restart the Dock and, like magic, those features will work again. Killing the Dock and even Finder with `killall` are special cases. Those two will automatically restart on their own. However, for other programs, it will just quit. For instance if Firefox hangs you could type `killall Firefox` and Firefox would be force quit but would not reopen. Check the man page for more information.

My MacBook Pro

This post is just letting some steam out, so there is a lot of text and a lot of links, all because I recently made a very worthwhile purchase. I bought a brand new MacBook Pro laptop and I am more then happy. I didn’t really know what to expect, I was really looking forward to it… however it has exceeded all of my expectations.

The quick specs are that its a Silver MBP with a 15.4in glossy widescreen display with the newest LED back-lightning. It houses a 2GB of RAM and an Intel Core 2 Duo that knock the socks of my previous 512/1.6 laptop. The software takes a larger explanation.

I had originally planned on holding out on buying a Mac until Leopard was released. My plans were pushing forward when I won a bundle of applications valued at more then $500 from MacUpdate and MacHeist. However I had been looking at software to download for weeks before my purchase and the list of free, high quality software is nearly endless. Still, there are always programs you have to splurge on.

I splurged on TextMate, a programming editor that translates into about $55. Its the single tool that I have heard the most about from web developers all around the world. I have to agree with the masses, its a fantastic editor that is grows more and more useful as I get acquainted with the Mac.

On the free end of things I have to mention QuickSilver. I might argue that every Mac user has at least heard of QS as its popularity is nearly as high as that of TextMate. I really appreciate this little app as it really does just make my life easier. It took a few minutes to setup these global triggers for iTunes: ?P to pause/play and ??? to go to the next song. That means from nearly anywhere those key combinations will trigger iTunes. I’m learning more as I go but QS is useful in more ways than one.

For Instant Messaging I thought I would like iChat. I thought it was okay, it certainly was easy to setup and worked great, however it just wasn’t up to my standards. I had heard about a Adium and decided to give it a try. That is an amazing IM program. There are plenty of great themes and almost everything is customizable. Its and incredible chat client that easily synced with my Google Talk account (the only Windows chat client I am willing to use).

However my favorite application so far has been Linkinus. That program has completely revolutionized IRC for me. Chatting in Linkinus is just fun. Its a work in progress and I plan to help out with the development. I am working on scripts, which require me to learn AppleScript, but it is worth it.

A worthy app to mention is Growl. You don’t realize how useful a standard messaging system is until you have used one. Almost every application I have can interface into Growl and therefore I have awesome standard notifications. Just typing this I got a notification that someone logged on Adium!! brb.

Looking for a really nice free RSS reader? Check out NetNewsWire Lite! RSS is fundamental when you are as busy as I am (which I expect you are). Have your news come to you, and link yourself back if you deem the article worthy of a visit. Most of the time I read it all in the RSS reader to save even more time. I sift through about 100 RSS articles each day, some are duplicates and many are short but I’d say that there are at least 5 full articles that I will read. They come from blogs and news sources alike, I currently subscribe to over 70 different feeds.

Common apps like iTunes and Firefox are obvious must haves. Although I will admit that I am interested in safari and I will likely give it a try for just common browsing (as it lacks many of the web development plugins that I have in Firefox). Photo Booth makes excellent use of the built in web cam aptly named the iSight that comes equipped on every MacBook Pro laptop. My recently engaged sister and said counter-part were kind enough to sit in front of my Mac for some pictures in Photo Booth. Half an hour later I was able to find a few serious pictures and I sifted thru another 30 or so pictures with various effects to get a group of pictures to put on my family website.

Now the beta apps. I am excited to try out Flow and I was able to sign up for the private beta, however I have not gotten any response yet. I did meet a nice contact chatting on Linkinus and got ahold of a the Skitch beta. Now Skitch is a really cool tool. I can take a picture of a section on my screen, add some quick features like (text, arrows, etc.) in seconds. That is impressive coming from the mspaint.exe experience, however it is not nearly Skitch’s coolest point. There is a drag and drop portion on the bottom of the app to allow you to quickly make a file in the most common picture formats (png, jpg, gif…). To top things off when you sign up for a Skitch account you are given a profile online. A single button on Skitch uploads the image to your Skitch site storage. That same button can then take you directly to the online image, some more single click buttons will copy the image location or xhtml compatible code and allow you to share the image with anyone in the world. You will be able to do all of this just by watching the 3 minute video included with the download. Skitch is a fantastic app! I’ve got some invites if anyone is really interested I might give one away.

Being a web developer its useful to have a local web server to test your work on. Although I manually installed everything I need to do Ruby on Rails development (ruby, rubygems, mysql, mongrel, and svn) I also downloaded a nice app to make things easy for myself. MAMP stands for Macintosh, Apache, Mysql and PHP and it is just plain simple. MAMP (like Easy PHP for Windows) is a completely isolated webserver with php and mysql. You can be sure that nothing else on your computer will be affected, for instance if you have another mysql database running. A great dashboard that even has phpMyAdmin. I made a few modifications to the default pages to add a quicklink to quickly accesses my web directories, but MAMP’s ease of use is much appreciated. A simple click to turn on/off… what more would I want?

SRS iWoW is an iTunes plugin that adds Three-Dimensional sound. I got it with the plugin but it a very cool plugin. Its enhancements to iTunes’ sound are immediately noticeable and gratifying. Simple to setup and customize you can have some real high quality sound. To be honest you won’t notice the difference until you try it, but once you do you will gasp at the difference.

I have a bunch more that I can write but I am going to finish now and hopefully finish working on my other website so that I can launch it! Goodbye for now.