Chapter 6. Advanced Scripting
In the past three chapters, you've learned how to work with Terminal, use basic shell commands, organize some commands into simple scripts, work with files, and manipulate text.
In this chapter, you're going to learn how to create some more advanced shell scripts. You'll also learn the basics of AppleScripting. Finally, you'll be introduced to the open command, a powerful tool that enables you to open files, Finder windows, and applications such as iTunes and Word straight from the command line. The goal of this chapter is to make you more proficient in automating certain administrative functions. Think of this chapter as a summary of what you've already learned, and a necessary step toward success in more advanced topics, which we'll cover from this chapter through Chapter 14.
Shell Scripting on Mac OS X
You got a taste in Chapter 3 of what shell scripts are about. At its most basic, a shell script is nothing more than a series of commands that have been saved into an executable file.
For example, if you are monitoring the server load on a particular machine, you might use the uptime command, like so:
uptime
14:28 up 2 days, 40 mins, 2 users, load averages: 0.08 0.51 0.45The response is fairly expected—current time, how long the machine has been up, how many users are connected to it, and load averages over the past 1, 5, and 15 minutes.
What if this output is too much for ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access