Park (2001) Mac OS

1/3, September 2001 2 Porting R to Darwin/X11 and Mac OS X by Jan de Leeuw Mac OS X Earlier this year Apple officially released OS X, its new operating system. OS X now comes pre-installed on all Macs, although by default you still boot into MacOS 9.x. But soon OS X will be the de-fault. OS X is not an incremental upgrade, it is a com. We Mac users have long been proud that we don’t have to type in commands to use our machines to their fullest. That’s still true, but now that Mac OS X has opened up the Unix command line, we. Learning to live with Mac OS X Mac OS X's Finder: love it or loathe it, the two points that unite almost everyone who has used Apple's next-generation operating system are that it's not up to scratch and that Apple's reason to write it using OS X's Carbon API is the chief reason why.

  1. Park (2001) Mac Os Catalina
  2. Park (2001) Mac Os X
  3. Park (2001) Mac Os Download
  4. Park (2001) Mac Os Update

We Mac users have long been proud that we don’t have to type in commands to use our machines to their fullest. That’s still true, but now that Mac OS X has opened up the Unix command line, we have all the tools necessary to take advantage of some powerful programming and scripting capabilities, so our Macs can do more of our odious work. And after all, isn’t that the whole point of a computer?

Programming is a lot like cooking–a category of activities that spans a broad spectrum, from the complexity of Iron Chef to the culinary travesty of microwaving a hot dog. Programming and cooking both can be done at many different skill levels, but even amateur chefs can make tasty food, just as beginning programmers can create useful scripts. And like learning to cook, learning to write scripts may appear daunting at first.

In this column, the first of a series examining OS X’s geekier innards, you’ll learn how to use the popular scripting language Perl, which is built into OS X. We’ll show you how to build a script that converts a Mac text file’s line endings to line endings that Unix can interpret. (This will enable the use of Unix-based text-processing tools on the file’s contents.) Although developing the script may seem like quite a bit of effort, the results will come in very handy if you ever need to convert multiple text files. (To learn more about specifying multiple files on the command line, see ” Take Command of Mac OS X,” How-to .) We hope that this example will serve as an appetizing taste of OS X’s rich flavors.

How to Write a Perl Script

First, you need to fire up a text editor such as OS X’s TextEdit, BBEdit, or if you’re already familiar with the command-line realm, one of the traditional Unix text editors such as pico or vi. Then jump right in by typing the following line:

#!/usr/bin/perl -w

This first line announces to the operating system that it’s dealing with a Perl script. The -w at the end of the line tells Perl that it should be particularly stringent about its interpretation of the script and display warnings if it encounters code that it considers suspect. Get yourself in the habit of adding -w to your scripts: doing so will often help you discover and fix scripting problems before they become a pain in the neck.

# linebreak characters: x0d – Mac, x0a – Unix

In this line, # indicates a comment for use by the author of the script or someone else reading it, so Perl will ignore the rest of the line. This comment explains the codes for the Mac and Unix line-break characters. Later, outside of the comment, the x notation will tell Perl that we’re using hexadecimal numbers to represent line endings.

{

Perl uses braces (sometimes called “curly brackets”) to group pieces of code. This outermost set of braces in this script is an optional visual indicator of where the script’s main part begins and ends.

foreach $inFileName (@ARGV) {

The script uses this foreach loop to work through all the names of files that the script will convert to Unix-readable text. Each individual file name is stored in a separate element of an array–a collection of variables–called @ARGV, which Perl creates.

This line translates to “Take a file name from the @ARGV array, put it in the variable called $inFileName, and run the code enclosed in the following set of braces; continue doing this until you run out of file names in @ARGV.” In Perl, all variables begin with the $ character except arrays (which are preceded by @, like @ARGV ) and hashes.

open (INTEXTFILE, $inFileName);

This line tells Perl to open the file, whose name it has plucked from @ARGV, and create a reference to it, which we’ve named INTEXTFILE. We’ll use this reference any time we have to read from this file; Perl wouldn’t know which file we were referring to if we didn’t name it explicitly.

open (OUTTEXTFILE, “>”. $inFileName . “.converted”);

This line creates the new file that will contain our converted text, and a reference called OUTTEXTFILE. The rest of the line contains the file’s name; the > character is shorthand for “create the file” and doesn’t actually affect the file’s name. The variable $inFileName contains the name of the original file, and the script will add .converted to the end of its name (so the original is not overwritten). The periods between the elements of the file name tell Perl to combine them into a single string of text.

$textFile = ;

This statement tells Perl to read the entire text file from INTEXTFILE and put it into the variable $textFile. Make sure the file isn’t too big (larger than about 100K); even though OS X has Unix-style virtual memory, you can’t assume that exorbitant amounts of memory are available.

Now for the Heavy Lifting

This line does all the real work in the script and is consequently rather dense:

$textFile =~ s/x0d/x0a/;

Perl has a built in search-and-replace function, represented by s. When invoking this function, you specify what it should search for and replace with; these two strings are bounded by / characters. We want to replace Mac line-ending characters with the Unix ones, so those are the two strings we’ve used in the search and replace fields. Using =~ tells Perl to perform the search and replace on the contents of $textFile and then put the result back into $textFile.

print OUTTEXTFILE $textFile;

Once the conversion’s done, use the print function to write the contents of $textFile to your output file.

These final statements close the input and output files, to keep things tidy. Add two closing braces to end your bracketed chunks of code, and that’s it.

When you’re done, save this script into a file named “lineconvert.pl”–making sure to give this file Unix line endings. Then use the command line’s chmod command to set the script’s attributes, so the operating system knows it’s an executable script. To do this, type chmod 744 lineconvert.pl into the command line. (To learn more about the chmod command, enter man chmod at the command-line prompt.)

Using Your Perl Script

Say you have a Mac text file named “mac.txt” and you want its contents to have Unix line endings. You invoke your script by typing ./lineconvert.pl mac.txt in the command line, and it performs the conversion. You end up with a file called “mac.txt.converted,” with contents that have Unix line endings. Ta-da! Now you can modify the script to create a Unix-to-Mac version, for example.

One of the many features you can add to your script is improved error handling. This is particularly important because errors outside of your control do occur, and you don’t want them to destroy your data.

Onward

Our example introduces a few of the ingredients in the large and well-stocked kitchen that is Perl programming. And Perl has countless uses beyond changing text files: it can fill the gaps between databases and Web servers to help you create dynamic Web sites. You can even use it to catalog your MP3 archive.

To explore Perl further, browse CPAN, the Comprehensive Perl Archive Network ( www.cpan.org ). If you find packages that seem useful, you may want to get your hands on Learning Perl , second edition, by Randal L. Schwartz and Tom Christiansen (O’Reilly & Associates, 1997). Using it as your beginner’s cookbook, you’ll soon be concocting Perl scripts that save you time and drudgery.

A longtime MacPerl user, Contributing Editor STEPHAN SOMOGYI is no longer afraid of regular expressions.

Perls of Wisdom: Writing a Perl script in OS X’s command line can be easier than it looks if you follow our instructions.

What is Mac OS X 10.0?

Mac OS X is Apple's new operating system. I've said it before and I'll say it again: the 'X' is pronounced 'ten', like the roman number, not 'ex' like the letter. Don't make me come over there.

Park (2001) Mac Os Catalina

Mac OS X was released on March 24th, 2001, with a suggested retail price of $129 and a version number of 10.0. Don't let the version number confuse you; this is the first official release of Apple's new OS. It was preceded by many developer releases and one public beta release.

To say that Mac OS X has been eagerly awaited by Mac users is an understatement. Apple has been trying to produce a successor to the classic Mac OS operating system for almost 15 years. It's a tragicomic litany of code names: Pink, Taligent, Copland, Rhapsody. In the early days (the Pink project was launched in 1987), Mac users paid little attention to these efforts, confident that their current OS was the most advanced in the personal computer market. But as the years passed and competing operating systems evolved, both by adopting Mac-like GUIs and by advancing their core OS features, Mac users--as well as Apple itself--became skittish.

By 1995, Windows had confined Apple's OS to a small corner of the market. Perhaps Windows 95 wasn't 'insanely great', but the market had declared that it was 'good enough.' Meanwhile, Microsoft quietly continued its own long-running project to radically revise its core operating system technologies: Windows NT (which eventually gave birth to Windows 2000, and soon, Windows XP).

By the time Apple's penultimate next generation OS project, Copland, was mercifully killed in 1996, the situation was dire. Mac users had suffered too many broken promises, and Apple had stumbled down too many blind alleys. By all rights, Copland should have been Apple's last chance. But the acquisition of NeXT and the second coming of Steve Jobs gave Apple one final window of opportunity.

Advertisement

Park (2001) Mac Os X

Despite the (comparatively) minor market requirements hiccup of the Rhapsody strategy, the Mac OS X project proceeded with what can only be described as single-minded determination, from its official announcement in May of 1998 to its first release in March of 2001. Dates were missed, features were added and removed, but unlike all earlier efforts, this one produced a shipping product.

Park (2001) Mac Os Download

Park (2001) Mac OS

And yet the success of Mac OS X is still an open question. Unlike the relatively controlled public image of the Copland project, Mac OS X has endured the increased scrutiny of the Internet age. While Mac users from 1994 to 1996 were treated to optimistic articles and future-world mock-ups in enthusiast publications like Macworld and MacUser magazine, Mac OS X has been analyzed by amuchwideraudience.

Park (2001) Mac Os Update

Here at Ars Technica, we've been following Mac OS X since its second developer release. It may seem strange to have seven articles dedicated to a product before the first official release, but the journey of Mac OS X has certainly been an interesting one.

This article will cover Mac OS X 10.0, but it will build on everything that was discussed in the earlier articles. If you haven't already read them (or similar articles elsewhere), you may have some difficulty following along. The list of earlier OS X articles appears below in reverse-chronological order. The most relevant are the two most recent: the Public Beta article and the relevant section of my recent Macworld San Francisco coverage.

  • MWSF: Mac OS X Post-Beta 1/17/2001
  • Mac OS X Public Beta 10/03/2000
  • Mac OS X Q & A 6/20/2000
  • Mac OS X DP4 5/24/2000
  • Mac OS X DP3: Trial by Water 2/28/2000
  • Mac OS X Update: Quartz & Aqua 1/17/2000
  • Mac OS X DP2: A Preview 12/14/1999

Let's begin...