Category Archives: Mac OS X

Introduction to Bash Scripting

Here’s a great tutorial for bash scripting: http://www.linuxconfig.org/Bash_scripting_Tutorial

Linux and OS X: Harness the Power of Bash
Linux and OS X: Harness the Power of Bash

If you’re doing any work with Linux or OS X computers, knowing even a little bit of bash can save you a whole lot of work. You can write automated backup scripts, you can scan for faulty permissions… the list is endless. You’ll end up building a toolbox of common scripts that you will use in multiple places.

Only one thing wasn’t given much attention on that page, so I thought I’d point it out:

for next Loop

Usually, your programming syntax is cleaner if you avoid the for next construct and stick to the for each construct instead, however, with bash scripting you often need to work with that crazy little numerical iterator for changing things like file names (e.g. backup1, backup2, …). So you should get familiar with the seq command. It creates an array, going either forwards or backwards, and then bash’s for next loop iterates over that array.

Here’s the seq syntax:

seq [OPTION]... FIRST LAST
seq [OPTION]... FIRST INCREMENT LAST

And here’s how you might iterate backwards over an array:

LIST=`seq $NUMBER_OF_ROLLBACK_FILES_TO_PRESERVE -1 1`;
for I in $LIST; do
echo "I is $I";
done

Now get over to http://www.linuxconfig.org/Bash_scripting_Tutorial and start learning.

µTorrent Mac Beta Finally Released

I just received this e-mail from the μTorrent Mac Team:

Psst…

You asked us to tell you about µTorrent Mac developments.

The beta is out. It’s Leopard and Intel only right now, but we’re working
to expand support soon.

Get it here: mac.utorrent.com/beta

Remember it’s beta software, so there may be bugs and annoyances. Please
help us make it better by contributing to the conversation in the forums
(forum.utorrent.com).

- The µTorrent Mac Team

This is great news. µTorrent is an excellent torrent client on Windows, and I’m excited to give it a try on Mac OS X. Yes, it’s still a beta, but I look forward to seeing how it compares to my reigning favorite client – Transmission.

0.9.0 is the current version.

Here’s the main screen:

And some Bandwidth preferences:

So far, I’d say it looks and acts a lot like the Windows version, just a lot more slick, glassy, and Mac-like.

Your thoughts? Will you be switching your Mac torrent client?

Keep Your Address Book in Sync with Dropbox (Mac OS X)

Disclaimer: some users have reported that this method does not work properly. Rest assured that it works, but I only recommend it for people comfortable with the Terminal. There’s a lot of room for error.

Please back up your Address Book before attempting this method. I am not responsible for lost data. Please see the comments below for further commentary.

Here is a little tip for you Mac users out there. We have written about the awesome, cross-platform Dropbox service before (here and here), and while it’s great for keeping ordinary files and folders in sync across the Internet, there are a few more clever uses for it.

With a tiny bit of command-line magic, you can easily keep your Mac OS X Address Book backed up online and synced to other Macs. Here’s how:

Preliminary Steps

First of all, download and install Dropbox on any OS X machines that you wish to sync. Finished? Excellent!

Next, go ahead and make a backup of your Address Book (optional, but strongly recommended). Just go to File → Export → Address Book Archive….

Keep that export handy in case things go wrong.

Link Address Book to Dropbox

Here’s the fun part. To make this process work, Address Book needs to be able to save data to your Dropbox folder. At present, Dropbox can only sync ONE folder (and everything in it). So, you see the problem? Address Book keeps all its data inside ~/Library/Application Support/AddressBook, and we need to trick Address Book into saving to your Dropbox folder.

Symbolic Links to the rescue! We can easily fool Address Book by creating a symlink.

Step 1 – First, we’re going to move the Address Book data files to your Dropbox folder. Make sure Address Book is closed. Launch Terminal (in your Utilities folder), and assuming your Dropbox folder is inside your Home directory, issue this command:

mv ~/Library/Application\ Support/AddressBook ~/Dropbox/

Step 2 – Now, create the symbolic link. The format is ln -s [destination] [name of file or folder]. The syntax does not change as to whether the link is to a file or a folder. Still in Terminal, type:

ln -s ~/Dropbox/AddressBook/ ~/Library/Application\ Support/AddressBook

That’s it. You’re done. Try launching Address Book and make sure your contacts are still there. Now when you add a new contact and it, you should see Dropbox update as well. Notice the tiny, green Dropbox check marks on my AddressBook linked folder:

Adding Other Macs

To add another OS X machine to the mix, just repeat these steps (except for the first mv command). In short, just install Dropbox, make sure Address Book is closed, and then:

  1. Delete the AddressBook folder from ~/Library/Application Support
  2. Create the symlink (ln -s ~/Dropbox/AddressBook/ ~/Library/Application\ Support/AddressBook)

There you go. Address Book will stay syncronized and backed up online.

Home & End: Key Bindings in OS X

One thing has bothered me about Macs: the key bindings. Specifically, I was annoyed that the home, end, page up, and page down keys don’t work like they “normally” do on a Windows machine. I found myself having to use the awkward “Apple + arrow” combinations to advance to the front or end of a line (home and end normally send the cursor to the beginning or end of the document, not the line). This is awkward at best, and it was made even more awkward when you consider the layout of my Kinesis keyboard (trippy, I know).

Even if you don’t have a tripped out keyboard, it makes a lot of sense to have “normal” functionality for your home and end keys AND have the ctrl key functionality within reach when you’re working in the Terminal; a lot of Unix/Linux/Bash stuff is mapped to the ctrl key (e.g. ctrl + c to exit a bash program).

OS X has full flexibility on how you handle your key bindings (woot). All you have to do is create a file that remaps the desired keys. This is best done on a per-user basis, so you create a new file in the user’s Library. Create the directory and file (if necessary), and add the following:


/* This adds "normal" home, end, page up, page down functionality */
/* ~/Library/KeyBindings/DefaultKeyBinding.dict */
{
"\UF729" = "moveToBeginningOfLine:";
"^\UF729" = "moveToBeginningOfDocument:";
"$\UF729" = "moveToBeginningOfLineAndModifySelection:";
"^$\UF729" = "moveToBeginningOfDocumentAndModifySelection:";
"\UF72B" = "moveToEndOfLine:";
"^\UF72B" = "moveToEndOfDocument:";
"$\UF72B" = "moveToEndOfLineAndModifySelection:";
}

Once you’ve made the changes, log out your user and log back in (you don’t need to reboot). Try opening up a text editor and navigate around a document using the home and end keys. It’s great.

For full details on other key bindings and how to find and map more keys, check out this great post:
http://www.lsmason.com/articles/macosxkeybindings.html

Because of my keyboard layout, I also want to move my command key (i.e. Apple key) functionality over to the ctrl key — this doesn’t make much sense on a standard keyboard (where your pinky reflex starts going carpal tunnel), but it makes a lot of sense on a Kinesis keyboard where the ctrl key is directly next to your thumb but the Apple key is a bit of a reach. That article is a godsend.

Secure Memory on Mac OS X

Nothing cheeses me off more than lazy Mac OS X users who don’t lift a finger to secure their OS. Yeah, Macs are currently not the most common target for hacks and viruses (viri?), but that hardly means that they’re invulnerable.

You can read more about some OS X security stuff, but here’s the quickie way to turn on your secure virtual memory:

  1. Open System Preferences.
  2. Double-click the Security icon from within the Personal section.
  3. Press on the padlock to enable changes.
  4. Supply a username and permission possessing administrator rights.
  5. Check the box for Use Secure Virtual Memory.

Even if this makes no sense to you, you should do it. If you don’t, talented hackers can read your swap files and gain access to all kinds of sensitive information… verily, they could read ANYTHING that gets stored in memory. Passwords, your web site logins, your porn…

A swap file is simply a temporary file that’s used while you edit a file. If you’ve ever used the OS X terminal, you may have edited files using one of the command line editors, like vi. You may have noticed that when you edit some_document.txt, there will be a file created some_document.txt.swp while you are editing the file… that file persists until you’re all done editing the file and you’ve closed the editor. Virtual memory works similarly… it writes the contents of the RAM to a temporary file. Enabling “Secure” virtual memory encrypts this temporary file while it’s on disk… so even if someone has access to your disk, they won’t be able to see the contents of your memory.

Basic OS X Hardening

apple-logo.jpgBasic computer setup and security compiled for Mac OS X 10.3 (Panther), 10.4 (Tiger), and 10.5 (Leopard)

I spend a lot of time with computers… it’s my job. Most of the time, people worry about patching up their Windows machines — and for good reason! Similar to our (slightly dated) Windows Security Guide, the purpose of this page here is to list the steps for securing a Mac OS X computer, including commands for lab managers and network admins who have to manage a large number of these computers. In the last week, there have been 3 security exploits / viruses for OS X. No OS is completely secure! So it begins…

4 simple things you can do to protect your computer

1. For everyday use, run as a limited user!

I don’t care if you rigged an election, aggressively invaded a foreign country, or slept with an intern — you simply don’t need to run as the Admin of your computer, no matter what OS you use! If you just bought your Apple computer, don’t let their glitzy setup fool you! It’ll ask for your name and and password, but this is to setup the Admin account, and it should be treated accordingly. After you’ve set up the Admin account, you can always go back to System Preferences and add a standard account for everyday use.

Trust me. You don’t want the computer booting automatically into an account with full Admin privileges. If nothing else, it’s far, far easier to find and backup all your files if you’re running as a limited user; all your files will all be in your home directory. If you’re Admin… who knows where you could have stashed them… good luck finding them all. What if you already set up your account, and whoops! It’s an admin account? What do you do? In Mac OS X, changing this is really easy. I appreciate the ease of it because this same thing is a holy pain in the arse on Windows.

I’m assuming you’ve got one account on your computer and it’s an admin account. Go to the Apple Menu → System Preferences, and open up the Accounts panel. Click the (+) to add an account, and check the box to let that user “Administer this computer.” You are temporarily creating a second admin account. Be sure you give it a good password and that you remember it! It’s the ultimate in rookie computing to forget your admin password.

Now, log out. Don’t just do a fast user switch. Log out completely, then log into the new admin account you just created. Go back to System Preferences → Accounts, and find your original user. Uncheck the box for that account that allows it to administer the computer. Poof. You’ve now changed your regular account into a limited user account and you’ve created a new admin account that you’ll hardly ever use. That’s the point: only use the admin account when you absolutely need to.

2. Turn ON your Firewall!

It’s under System Preferences → Sharing. Microsoft got ridiculed for shipping Windows with this turned off, and Apple should be next in line for a kick to the groin. If you need to open a port for some service, that’s always possible later, but TURN IT ON AND LEAVE IT ON.

3. Turn ON Automatic updates!

If you are the only person using your computer, and you are its administrator, you should turn this feature on by going to the Apple Menu, System Prefs, and find the Software Update panel. Check the box so this runs, preferably DAILY, if your internet connection can handle it.

4. Turn OFF “Open ‘Safe’ Files After Downloading”

The most recent security hole (as of this writing) exploits the fact that many people leave this checked. Go to the Safari menu → Preferences, and on the General tab, uncheck this box. That will prevent any nasty code from auto-executing.

This particular hole is not so much a problem if you are running as a limited user because the malicious code executes with the privileges of the current logged-in user. A limited user can’t do that much damage, but your computer can be completely hosed if you were dumb enough to be logged in as an admin.

Oh, and one more thing – Block Pop-ups in Safari! Again, why the @#$& this isn’t turned on by default, I don’t know, but there’s no reason to let those maggot-sucking, pop-up-producing advertisers ruin your browsing.

10 Must-Have Free Applications for Mac OS X

01.19.05

The following is a list of free applications that greatly enhance Mac OS X at zero cost to the end user. I compiled this list with a few key points in mind.

  • The application has to be free. No shareware allowed. It IS ok if a free application also has a paid version if the paid version has added functionality, similar to AVG Free versus the paid versions in Windows.
  • The application should be relatively easy to use.
  • The application should do a good job at providing some specific functionality.
  • The application gets added points for beauty and elegance. After all, this is OS X.

I want to acknowledge that limiting myself to ten applications was difficult. Therefore, I decided to list a few runners-up at the bottom. I also want to emphasize that the items listed are in random order! All of these applications provide a different functionality, and ordering them by rank is futile and pointless. Finally, this is a subjective list; others will certainly disagree with my choices. I am fine with that. That said, here we go. This is *my* list of ten “must-have” applications for OS X.

—- (In random order) —-

1. Mozilla Firefoxhttp://getfirefox.com

-About:
Firefox is a terrific open-source browser that blocks pop-ups and features tabbed browsing. While Safari is also a great browser, Firefox adds a more functional search box, and the availability of themes and extensions greatly enhance its looks and functionality. Want to control iTunes from within Firefox? Done. Want to completely block advertisements (including flash ads)? Done. Firefox also has a slick, “find-as-you-type” search feature.

2. Cyberduckhttp://icu.unizh.ch/~dkocher/cyberduck

-About:
Cyberduck is a free, open-source FTP client that is also capable of handling sFTP. The “bookmarks” are a nice touch, and it even interfaces smoothly with TextWrangler (see below)!

3. TextWranglerhttp://www.barebones.com/products/textwrangler/index.shtml

-About:
Once a commercial application, TextWrangler is now free. TextWrangler is a “high-performance” text editor whose sole purpose is to produce and change content, and it excels at manipulating generic text files and source code. Not only does it include FTP and sFTP support, it also interfaces seamlessly with Cyberduck and Applescript.

4. NeoOffice/Jhttp://www.planamesa.com/neojava/en/index.php

-About:
NeoOffice/J is an aqua port of OpenOffice.org, which includes a word processor, a spreadsheet program, a presentation program, an HTML editor, and more. Because it runs natively in aqua, it uses the same fonts as other OS X applications. While it will not yet suit the needs of those who rely heavily of Macros and scripting, NeoOffice/J will suit the needs of 95% of users. (Aside: I have had a handful of crashes on startup with NeoOffice/J, but it is still impressive enough to make the top ten. This is still “beta” software, and will improve over time at no charge to you, the user.)

5. RsyncXhttp://archive.macosxlabs.org/rsyncx/rsyncx.html

-About:
RsyncX is a implementation of rsync (a Unix tool for intelligently backing up files) that has support for HFS+ file systems and also utilizes a GUI. Use this powerful tool to make backups of selected files to another place on your machine or over a network. You can even use RsyncX to “push” a copy of your booted volume to a networked computer, bless it for either OS 9 or OS X, and then reboot the remote machine.

6. VLChttp://www.videolan.org/vlc/

-About: VLC (VideoLAN Client) is an open-source, highly-portable multimedia player for various audio and video formats, as well as DVDs, VCDs, and various streaming protocols. It functions well as a stand-alone media player, but you can also use it as a server to stream in unicast or multicast.

7. Audacityhttp://audacity.sourceforge.net/

-About:
Audacity is a free, open-source audio editor. While not yet in the same league as the larger commercial applications, Audacity will easily fit the needs of someone who requires a simple, easy-to-use multi-track waveform editor. Be sure to grab the extra packages, such as Lame (for mp3 exporting), the VST-plugin enabler, and the manual.

8. WhatSizehttp://www.id-design.com/software/whatsize/index.php

-About:
WhatSize is a neat utility that allows you to quickly calculate the size of a given folder, its subfolders, and all files contained within. While it is calculating, you can open subfolders to browse their contents as well. WhatSize also reports information about hidden files and cache files. (Aside: This is one of those slick little applications that you do not realize how much you need until you try it.)

9. BitTorrenthttp://bittorrent.com/

-About:
BitTorrent is a tool used for distributed file sharing. It works by “seeding” files and tapping into the unused upload bandwidth of any computer running it. To use it, you have to upload while you download; no “leeching” allowed. While BitTorrent can certainly be used for “illegal” file distribution, there are many perfectly legal uses as well, such as downloading various Linux distributions. Use wisely.

10. Handbrakehttp://handbrake.m0k.org/

-About:
Handbrake is an easy-to-use, open-source DVD to MPEG-4 (or AVI) converter. It can encode directly from DVDs or from VIDEO_TS folders. It also supports 2-pass encoding, picture deinterlacing, cropping, and scaling. It encodes audio in either AAC, MP3, or OGG formats.

Runners-up:

GIMP – http://gimp.org/macintosh/

-About:
The GIMP (GNU Image Manipulation Program) is a powerful image editor. Though not quite on the level of Photoshop, the GIMP is a “creme- of-the-crop” open-source application that will easily suit the needs of all but professional graphic artists. The only reason that GIMP did not make the top ten is that it has to run in X11 as there is not (to my knowledge) a native aqua port, and this may cause confusion for people who do not have X11 installed.

Adium X – http://www.adiumx.com/

-About:
Adium X is an open-souce, multi-protocol instant messaging client that is based on GAIM. It looks similar to iChat, but allows you to connect to different IM services from within one application. It is a “must-have” for those who like to chat. (Aside: I did not include this in the top ten because I do not really like to chat. Yes, it is personal. After all, this is an opinion piece.)

SoundFlower – http://www.cycling74.com/products/soundflower.html

-About:
SoundFlower is an open-source audio system extension that allows you to “pipe” audio from one application to another easily. Once installed, SoundFlower simply shows up as another audio device. One example of a use for SoundFlower is to record streaming audio from iTunes into Audacity. I did not include this package in the top ten simply because most people would not have much of a use for it. Also be sure to check out “soundflowerbed.”

Blender – http://blender3d.org/

-About:
Blender is an open-source 3D graphics creation suite that includes modeling, animation, rendering, post-production, realtime interactive 3D, and game creation, all in one package! You have really got to see it to believe it. While extremely impressive, this package did not make it to the top ten because of the rather steep learning curve. There are lots of great tutorials available on the web site though.

3ivx D4 – http://www.3ivx.com/

-About:
While 3ivx is more of a codec toolkit than an application per se, it is important enough to include on OS X. Not only does 3ivx allow you to decode most MPEG-4 files, it allows you to encode video MPEG-4 at a higher quality and with higher compression than Apple MPEG-4. 3ivx is completely compatible with Quicktime and Quicktime- compatible encoding applications. The only problem is that it may have some issues playing certain AVI files. Though you can download a separate application from them to fix this playback issue, it is enough to keep it from the top ten.

MacTheRipper – http://www.ripdifferent.com/~mtr/

-About:
This is an open-source DVD ripper that has the ability to remove CSS encryption. That said, it is intended for use on DVDs that you actually own. It works perfectly well, but due to speed issues it did not make the top ten, though perhaps that is not fair. Ripping the same DVD on my “less-beefy” PC only took one-third the time, and this may be an optimization issue with OS X or with my Superdrive, and not necessarily with MacTheRipper.

—- Brian Bondari —-
Copyright 2005