Posts tagged "mac-os-x"

iTunes: Surprisingly useful when learning a foreign language

I recently began learning Danish. I'm taking a weekly class, and the first week's homework involved listening to the conversations we covered during the lesson. I began by playing the audio files, following along in the Danish transcripts. I found myself wanting to listen to the difficult parts over and over, but scrubbing through a timeline is rather awkward.

It occurred to me that I could use iTunes to solve this problem. Normally, iTunes will play a track from beginning to end. It's possible, though, to specify a certain portion of the track to be played instead. By adding an audio file to a playlist many times and specifying consecutive portions (e.g. 0:00–0:02, 0:02–0:04.8, …), a track can be broken into manageable clips for more convenient navigation.

Here's the end result:

iTunes playlist for Danish dialogue

Customizing your bash prompt for pleasure and profit

Mac OS X's default bash prompt is dull and uninformative.

Mac OS X's default bash prompt
Mac OS X's default bash prompt

Since only the current directory name is visible, I find myself running pwd more often than is healthy. Also, I find the uneven prompt length jarring.

Faster Terminal navigation via aliases

Workmates will be quick to confirm that I'm not exactly leet on the command line. Efforts to advance beyond cd and ls have been hampered by the fact that many posts and discussion threads assume a level of competency which as yet I lack.

When I sit down to write a post, oftentimes I write the post I wish I'd read an hour earlier. As I unravel the mysteries of ack and bash and Emacs and the like, I'll publish tips and explanations so that others can benefit from my discoveries (or, as will likely be the case, so that you people can further enlighten me).

Safari keyboard shortcut to open current page in Google Chrome

I followed John Gruber's suggestion and removed Flash Player from my Mac. Like John, I've come to rely upon Google Chrome for viewing the occasional Flash movie. As a result I've become proficient at the keyboard dance required to open in Chrome the page I'm currently viewing in Safari:

  1. ⌘L (File > Open Location…)
  2. ⌘C (Edit > Copy)
  3. ⌘Space (invoke Quicksilver/Spotlight)
  4. C-H-R-↩ (open Google Chrome)
  5. ⌘L (File > Open Location…)
  6. ⌘V (Edit > Paste)
  7. (go, go, go!)

Well, I've performed this dance for the last time. I now do this instead:

  1. ⌥⌘G

Credit for this simple but brilliant idea goes to Rob McBroom. Rob's post on opening pages in Google Chrome lists the (very easy) steps required to enable this shortcut.

Update —

Chris points out that John himself mentioned this trick in his aforelinked post.

Composing Mercurial commit messages in TextMate

Using the -m flag can be a timesaver, but for several reasons I prefer to write my commit messages in a text editor:

  • Spell-checking
  • Familiar keyboard navigation
  • No need to escape quotation marks

TextMate is particularly well suited to my needs due to its built-in Markdown highlighting and previewing – yes, I write commit messages in Markdown!

To set TextMate as Mercurial's editor, add editor = mate -w to the [ui] section of your ~/.hgrc file.

Vince Cima explains:

Next time you do hg commit TextMate will open a temporary file you write your commit message into. Type your message, save the file and then close the window to finish the commit. The -w flag on the mate command tells TextMate not to return control to the command line until the editor window has been closed.

Update —

To use TextMate as your git editor, run the following command:

git config --global core.editor "mate -w"

This adds editor = mate -w to the [core] section of your ~/.gitconfig file.

Customizing file and folder icons in Mac OS X

Customizing the appearance of files and folders in OS X is a cinch. ⌘C, ⌘I, ⌘V, punctuated by a few mouse clicks.

Actually, that's total bullshit.

Sure, in the simplest of cases the copy and paste approach gets the job done, assuming one knows to copy from Preview.app if copying from the original source fails. As soon as one decides to do something a bit more advanced, such as providing versions for display at different sizes, one's shit outta luck.

DigitalColor Meter

DigitalColor Meter

I thought this recent post on the Minimal Mac blog well worth sharing:

When was the last time you checked out your Utilities folder? Well, if your answer was “What’s that?” then let me explain. Inside of your Applications folder is another folder called Utilities that is filled with all sorts of wondrous things that most people either don’t know or completely forget are there. Even veteran Mac users are guilty of this. I know I am.

DigitalColor Meter is one example of this. The other day, I wanted to find out the web safe color of a particular item on the screen of my Mac for a web design project I was working on. My first step was to go searching the Internet for such a tool (preferably free). Then, in the midst of said search, I was reminded that this little tool was not only already on my Mac, did exactly what I wanted, but also did it better than any of the tools I was able to find.

The point is that, even the tools we think we know can always reveal a little something we don’t. The Mac is an incredibly deep and rich OS and there are few that know it all. I’m going to spend some time every day for the next little while spending some time getting to know some more of these built in tools I largely have ignored and see if I have any practical applications for using them. You will likely see more posts like this in the coming days.

Reblogged by ¡ɜɿoɾɪɹℲ with this extremely nifty addition:

To take your Digital Color Metering to the next level, you can drag the color off of the well on the right (next to the R G B labels) into any standard color picker to bring it over. Sometimes, you can even drop it straight into an object in another app!

Give it a try: sample a color, press cmd-shift-h to hold it, then drag and drop from the swatch an object in Pages or Keynote.

I'm going to find this incredibly useful. No more grabbing a portion of the screen, switching to Photoshop, creating a new document, hitting ⌘V, switching to the eyedropper tool, double-clicking the foreground colour swatch to invoke the Color Picker, and then clicking on the appropriate pixel to find its colour value.

I don't think I'll miss this process, somehow, although my flatmate'll miss the camera shutter sound that accompanies screen captures on OS X (he really likes it, for some reason).

Testing Django apps using localhost subdomains

This turned out to be quite a bit easier than I'd imagined. Here are the things I did:

  1. I saved Dave Fowler's subdomain middleware as middleware.py in my project directory:

    class SubdomainMiddleware:
        def process_request(self, request):
            '''Parse out the subdomain from the request'''
            request.subdomain = None
            host = request.META.get('HTTP_HOST', '')
            host_s = host.replace('www.', '').split('.')
            if len(host_s) > 2:
                request.subdomain = ''.join(host_s[:-2])
    
  2. I added this to my project's MIDDLEWARE_CLASSES:

    MIDDLEWARE_CLASSES = (
        ...,
        'middleware.SubdomainMiddleware',
    )
    
  3. I edited my /etc/hosts file as per Dave's suggestion:

    127.0.0.1 test.com
    127.0.0.1 blog.test.com
    127.0.0.1 search.test.com
    

    Initially I replaced test.com with the site's domain name, but I decided that it's useful to be able to access both the live site and the test site without editing the /etc/hosts file.

    At this point I expected everything to work as advertised. Instead, I got this:

    It works!

    That would depend on one's definition of "works". I wanted my Django site to appear, which required a very simple tweak…

  4. I added the port number to the address:

    http://test.com:8000/
    

    This actually worked. :)

Application-specific volume control in Mac OS X?

It's not uncommon to start watching a video online and discover that its audio is quite quiet. This is not a problem in and of itself, as one can simply crank up the output volume. What is a problem, however, is a message then arriving in one's inbox and waking the neighbours!

This situation could be avoided if it were possible adjust the browser's output volume without affecting the rest of the system. As it is, though, one is forced to increase the volume of everything. Not ideal.

System Preferences > Sound > Application Volumes

Possible interface for application-specific volume settings in Mac OS X

Wouldn't this be nice? Many months ago I did some Googling to find out whether it's possible to control volume on an application-by-application basis in OS X. The closest thing to a solution was an X11 (read: ugly) app that kinda worked.

Apple, I don't bug you often, but here I will. Please build this into the OS and keep the neighbours happy. It'd be particularly sexy if applications such as iTunes which do currently grant the user control of the application's volume synchronized their volume settings with the ones in System Preferences. That is, adjusting the volume in iTunes would adjust the iTunes volume setting in System Preferences, and vice versa.

Fascinating insight into the mind of a Windows user

The following conversation took place a couple of days ago in my apartment. Matt's my flatmate, Doug's one of Matt's friends. I was in the room at the time.

  1. Matt: So, Doug, do you think you could go the way of Mac?
  2. Doug: I already have, really, but I'd never buy one.
  3. Matt: Why's that?
  4. Doug: Well — no offense, David — if I were to buy one I'd be getting something a retard could use, and I'm not a retard.

I found this exchange both entertaining and enlightening. Never had I considered the possibility that certain individuals use Windows because it's poorly designed and difficult to use!

There's certainly some sound reasoning behind Doug's stance: Doug is proficient in Windows; gaining proficiency in Windows requires a certain level of intelligence; Doug's proficiency in Windows is therefore indicative of his intelligence.

Why, then, does Doug say that he's switched camps? He's using one of these at school:

27-inch iMac
27-inch iMac

Talk about having one's cake and eating it, too.

Gorgeous CSS3 buttons inspired by Aqua

Modern browsers can display exciting visual effects such as drop shadows (without the use of background images). CSS3 makes it possible to turn submit inputs and even links into rich, Aqua-like buttons in these browsers (alternative style rules can be provided for older browsers).

Accessing MySQL shell via Terminal

Certain things are extremely well documented on the Web; certain other things, however, seem to appear only deep in the comments of obscure blog entries.

The problem I encountered a few minutes ago fell squarely in the latter category. I simply wanted to know how to access the MySQL shell from the OS X Terminal. I expected my Google search for MySQL console Terminal "OS X" to return several useful results, but this was not the case.

I managed to find the solution in a thread with subject error 1044 and 1045:

mysql -u root -p mysql

Multisession CD burning in Snow Leopard

The days of the compact disc are surely numbered. The MacBook Air is the first computer from Apple to jettison the optical drive; others will undoubtedly follow, eventually.

Since the vast majority of Mac OS X users currently possess the means to read and burn CDs, however, I thought this information — lifted straight from Disk Utility Help — worth sharing. These instructions apply to Snow Leopard, although I would guess that the process is identical for older versions of OS X (the more recent ones, at any rate).

Recording on a recordable CD more than once

Normally, you can burn items to a recordable CD, such as a CD-R or CD-RW disc, only one time. However, if you use Disk Utility to burn the disc, you can burn items to a disk in more than one session as long as space is available. This is also called "multisession burning."

To burn a disc, you need an optical drive in your computer or connected directly to your computer. You can’t burn a disc using a remote optical drive.

To burn to a recordable CD so you can burn to it again:

  1. In Disk Utility, create a disk image that contains the files you want to burn to the disc.

    The files must be from a partition with a Mac OS Extended disk format. To check a partition’s format, select the disk in Disk Utility, and look at the information at the bottom of the Disk Utility window.

  2. Select the disk image in the list at the left, and then choose Images > Burn.

  3. Select the "Leave disc appendable" checkbox. If you don’t see this option, click the triangle in the upper-right corner.

  4. Insert a blank recordable CD in the optical drive and click Burn.

To add more files to the disc later, follow the steps above. You can continue this process until all available space on the disc is used.

Photoshop "save for web" JavaScript

This is a JavaScript function for Photoshop which saves the active document as a 24-bit PNG file. It is equivalent to manually selecting File > Save for Web & Devices… which means that the file size of the resulting PNG will be smaller than would be the case using PNGSaveOptions().

function saveForWebPNG(outputFolderStr, filename)
{
    var opts, file;
    opts = new ExportOptionsSaveForWeb();
    opts.format = SaveDocumentType.PNG;
    opts.PNG8 = false;
    opts.quality = 100;
    if (filename.length > 27) {
        file = new File(outputFolderStr + "/temp.png");
        activeDocument.exportDocument(file, ExportType.SAVEFORWEB, opts);
        file.rename(filename + ".png");
    }
    else {
        file = new File(outputFolderStr + "/" + filename + ".png");
        activeDocument.exportDocument(file, ExportType.SAVEFORWEB, opts);
    }
}

Photoshop on Mac limits the length of a File object's file name to 31 characters. Credit for the rename workaround should go to Mark Walsh who posted the solution on the Adobe forums in a thread titled Save for web filename problems.

AppleScript syntax highlighting

I've been using Alex Gorbatchev's SyntaxHighlighter to syntactically display code of various languages for several months now. When I decided to post an AppleScript snippet, however, I realised that I was out of luck. SyntaxHighlighter does not include an AppleScript "brush", and a quick flick through the SyntaxHighlighter forums did not bring me any joy.

How hard could it be to write a brush for AppleScript?, I wondered. The handy guide to developing a custom brush got me started, and I was soon busy trying to encapsulate AppleScript's syntax — along with its keywords and countless words and phrases with special meanings — into a handful of regular expressions.

Django syntax highlighting for Coda

I love Coda. It's just so… sexy, somehow. I've just discovered Django, with which I'm fast falling in love as well. Naturally, when I came to write my first Django template I opened Coda.app and started coding.

It soon became apparent, however, that Coda does not apply syntax highlighting to Django. The solution? Juan Pablo Claude's Django and Django-template bundles for Coda.

Django syntax highlighting in Coda
Django syntax highlighting in Coda

Update —

I've since discovered an alternative mode which is actively maintained over on GitHub. I now use jbergantine's Django-Template.

Changing keyboard shortcuts in Mac OS X

I've been using OS X almost exclusively for the last three or four years, but it was only recently that I discovered the system-wide method for changing keyboard shortcuts. I think the reason that this feature eluded me for so long is that so many of the hours I've spent on OS X have involved the use of the Adobe applications Photoshop, Illustrator, and InDesign, which provide their own means of changing keyboard shortcuts. I assumed that since application developers sometimes provide their own interfaces for changing keyboard shortcuts, the operating system must lack this functionality. I was wrong.