Baby Steps in Data Journalism

Starting from zero, this Tumblr provides tools, links and how-to information for people just beginning to explore data journalism.
Posts tagged "Mac OS"

Get Info panel - Mac OS

This is simple, and it will save you time.

First, TextWrangler is a free text editor for Macs, and it makes writing code easier. Download it from this page.

Then you should make TextWrangler the default program for all .txt and .py files. Do that with each file type. Here’s how:

  1. Select one file with that file type (.txt or .py).
  2. Press Command-I (or right-click and select Get Info).
  3. At the widget labeled “Open with,” open the menu and select TextWrangler. (NOTE: TextWrangler must be installed already!)
  4. Click the Change All button. And you’re done.

Repeat for each file type.

"The easiest way to share your code with GitHub."

Where am I when I open Terminal?

That’s where. Look at the image. See the little house? That’s you.

Of course, you’re not mmcadams. That’s me!

SEE ALSO: Baby Steps in Unix/Linux Part 2: Change Directories

When you’re using Terminal, you can open plain-text files using the nano command:

nano [path/filename]

nano is a small, free and friendly editor which aims to replace Pico, the default editor included in the non-free Pine package. Rather than just copying Pico’s look and feel, nano also implements some missing (or disabled by default) features in Pico, such as ‘search and replace’ and ‘go to line and column number’” (from the manual).

SEE ALSO: The GNU nano homepage

How to edit your .bash_profile file

When I first opened Terminal on my Mac, the prompt was really long. It contained the full name of my Mac, which for some reason I had allowed to be insanely … not great. So I wanted to change the way my prompt looked.

To do this, I edited my user profile on the system.

That profile is controlled by a user’s .bash_profile file. I found a helpful article titled How to Customize your Terminal Prompt and followed the instructions. The article shows you many options.

You start with this (at the command prompt):

nano .bash_profile

You could use nano to open any other text file (just use the filename and path, if necessary, after the word nano).

Anyway, you press Return and thereby go into a simple text editor. If there’s nothing in your .bash_profile file yet, you’ll see your cursor blinking at the top left corner of a blank area. Above that is a bar that says GNU nano and the version number. At the bottom of the screen are some commands, but you might not realize that WriteOut actually means Save (duh).

DO NOT DELETE anything that is already in your .bash_profile file. Move the cursor down below that stuff, on a new line. This is how I changed my command prompt:

export PS1=”\u \W $ “        [NOTE: This is case sensitive.]

So this is my crib sheet for nano on Mac OS:

Save a file: Control-o        [press Return to accept the filename given*]

Exit the file and program: Control-x

That’s all, just two commands.

*After you save, it asks if you want to save that file. I guess it wants you to make sure you’re editing the file that you intended. Press Return at that point, or your file will not be saved.

I downloaded: ActiveTcl 8.5.11 (April 2012) because the documentation for my Python download recommended it:

“Before using IDLE or other programs using the tkinter graphical user interface toolkit, visit http://www.python.org/download/mac/tcltk/ for current information about supported and recommended versions of Tcl/Tk for this version of Python and Mac OS X.”

This download was a DMG* file that must be installed after downloading. That was easy enough. But then there’s this:

ActiveTcl executables (wish, tclsh and tkcon) are installed in /usr/local/bin. If this directory is not in the user’s PATH environment variable, it can be added manually to the .profile or .bash_ profile file in the user’s home directory. For example:

     PATH=/usr/local/bin:$PATH
     export PATH

Read More

Baby Steps in Unix/Linux Part 3: Your Home Directory

What if you get lost after you have changed to different directories too many times?

There’s no place like home — here’s how to click your heels and get back.

Type the following and then press Return (or Enter):

cd

That’s it, just cd by itself. That will take you back you your own home directory on the system. However, if you want to go outside that directory, to the root of the system, type the following and then press Return (or Enter):

cd /

That is cd, and one space, and a slash.

Baby Steps in Unix/Linux Part 2: Change Directories

One of the common tasks you’ll be doing in Terminal is changing directories. What Unix calls “directories” are the same as what most of us call “folders” on our computers.

Experiment with the cd (“change directory”) command to find out how it works.

Use the ls (“list”) command to see the names of directories that are inside the current one. You will probably see one named Desktop, so let’s peek inside that one. Type the following and then press Return (or Enter):

cd Desktop

Remember that Unix is case sensitive, so pay attention to that uppercase letter “D” in Desktop.

To see what’s inside Desktop (“list” the contents), type the following and then press Return (or Enter):

ls

You should see the names of all the stuff that’s on your Mac Desktop.

To go back “up” to the parent directory (the one you started in, in this case, and which contains the folder named Desktop), type the following and then press Return (or Enter):

cd ..

FOLDERS THAT ARE DEEPLY BURIED

Finally, what if you want to change to a folder that’s easy to locate in the Finder, but you don’t want to type all the many folder names leading down, down, down to where it is buried? Easy peasy: Just find the folder the normal way, using the Mac Finder — then click it once (don’t open it) and then press Command-c to copy the “path.”

Return to your Terminal window. Type cd and one space, and then paste (Command-v). Press Return, and bingo! You’re in that directory, no matter how deep down it is.

Each of these steps is illustrated in one of the images above (CLICK for a slideshow of larger images).

Baby Steps in Unix/Linux Part 1: Listing

When you’re staring at that bare command prompt in Terminal, of course you don’t know what to do. A command-line interface expects you to type something. But not just anything. It’s not a person, after all. It can’t understand natural language.

So first, try out some useful commands that will show you information about directories (folders) and files that are inside the current directory. Each one is illustrated in one of the images above (CLICK for a slideshow of larger images).

  1. Type ls (for “list”) and press Return (Enter).
  2. Result: The contents of the current directory are listed, in columns.
  3. Type ls -a (“list all”) and press Return (Enter). Result: Now the list includes “hidden” system files, which have names that start with a dot.
  4. Type ls -l (“list long”) and press Return (Enter). Result: Now you see a lot of details about the directory contents, including read/write (rw) permissions.

NOTE: Unix is case sensitive, so pay attention to upper- and lowercase letters.

First you’ll want to download the current production version of Python.

This is the one I installed (Mac users: Look for “Mac OS” on the list on the download page):

Mac OS X 32-bit i386/PPC Installer (2.7.2) for Mac OS X 10.3 through 10.6 [2] (sig)

There might be a different one by the time you read this. Of course, Windows users will install a Windows version.

Read More

If you have no clue how to work within Terminal (a Unix shell environment is what we call it, I think), this is a good guide. Short! Clear!

Also good:

Terminal - MacRumors: Guides

How to Open Terminal and Change Its Appearance

Many Mac users have never used Terminal. You will be using this when you work with Python. It will be nicer for you if you change Terminal to look better, according to your preferences for color and so on.

OPEN TERMINAL (Mac OS only):

Open Spotlight and type:  terminal

Open Terminal by clicking it in the Spotlight menu.

To change settings, Terminal menu > Preferences.

Click the Settings tab (see image above).

  1. Select a color scheme from the left column.
  2. Select a bigger font size so you don’t go blind.
  3. Click the Default button at lower left.
  4. Close Preferences.
  5. Quit Terminal, and then re-open Terminal.

Your new colors and fonts will be in effect.

NOTE: Do not change the font to a proportional font. Use a monospace font, such as Andale Mono (the default).