<<

. 28
( 69 .)



>>

command:
language, www.apple.com/applescript for Apple™s Web site.
osascript script-file
osascript -e ˜one line of script™

RUN APPLESCRIPT FROM THE SHELL




‹ Type a line of Applescript ‹ Type a phrase, a double
RUN A SINGLE LINE MAKE YOUR UNIX SHELL TALK
OF APPLESCRIPT within single quotation quotation mark, and a single
„ Type osascript -e, a space,
„ Type osascript and a marks, and press Return. quotation mark, and press
and a single quotation mark.
Return.
space. – The osascript ¤ Type tell current – The osascript
¤ Type -e and a space. command executes the
Application to say, a space,
Applescript line. command tells the current
and a double quotation mark.
application to speak the text.
130
9
COMBINE UNIX AND AQUA


You can use osascript to announce the new directory each time you
use the cd command. It uses the special tcsh shell script cwdcmd, a
command executed each time you change the current working directory.
„ Create a directory for storing scripts, such as ˜/Library/OSAscript.
¤ Create a shell script in the directory named say-dir.sh, containing the
following: osascript -e 'tell current Application to say
"New Dir: '$cwd'"'
‹ Add an alias command to your .tcshrc file that sets the cwdcmd alias:
alias cwdcmd 'source ˜/Library/OSAscript/say-dir.sh'
– You can type source .tcshrc to run your .tcshrc file and add this alias, or
you can type the alias command (in step 3) to set the alias for your
current Terminal window.
When you change to a new directory, the cwdcmd alias executes. The
source command reads in the shell script and runs it, calling the
osascript command. The value of the current working directory is
stored in the shell variable $cwd, and the new directory is announced
because the value is used in the Applescript say command.
There is one hitch to using this script: You will change directories slowly
because the cd command will not end until the full path is spoken.




– The osascript
¤ Type osascript and a
RUN AN APPLESCRIPT FILE
space. command executes the
„ Create a text file Applescript file.
‹ Type the name of the
containing your Applescript,
using a text editor. script file and press Return.


131
UNIX FOR MAC




CREATE CLICKABLE SHELL SCRIPTS
#!/bin/csh

Y
ou can make shell scripts that you can run by double-
# top.command:
clicking their icons in the Mac OS X Finder. A script is
# This script will start the top command
clickable if the name of the script file ends with the
with the options
suffix .command.
# you prefer. It can be run by double-
clicking the file
Ordinary shell scripts are not clickable. Double-clicking a
# icon in the Finder.
shell script™s icon opens it in a text editor instead of running
it. To make it clickable, you can make the script executable
top -u -s5 # sort by CPU, update every 5
by using the chmod command and giving it a name ending
seconds
in .command.
If you save this file as top.command and set it as executable,
When you double-click the icon of a .command file, the
you can double-click the icon to start the top command. You
Terminal program opens a new window and executes the
can also add a new icon using the Mac OS X Finder. You can
command in that window. For example, if you want to run
make other types of executable programs clickable by
the top program in a shell window, you can write a shell
renaming them to .command filenames as well.
script like this:

CREATE CLICKABLE SHELL SCRIPTS




– The Terminal program
„ Create a shell script and ¤ Type chmod a+x, a space, ‹ Locate the file in the
give it a name ending in and then the filename, and Mac OS X Finder and opens and executes the shell
.command. press Return. double-click it. script.




132
9
COMBINE UNIX AND AQUA



DRAG PATHNAMES TO THE
TERMINAL WINDOW
release the mouse button, the file is not moved, as it usually

Y
ou can use any file found in the Mac OS X Finder by
would be if you dragged the icon to a new folder. Instead,
dragging the icon onto the Terminal window. The
the file™s full pathname is pasted onto your Terminal window:
pathname of the file appears in the shell as if you had
typed it. This capability is useful if you are deep within
[ferro:˜] user% ls -l
folders in the Finder and you want to use a shell command
/Users/user/Pictures/kitty/olorin1.jpg
on a file you have found. You can save typing in this way
and make it much less likely that you will mistype a You can then press the Return key and execute the command.
pathname. For example, to get a long directory listing of a This action works with any file, including folders, to paste the
file, type a partial command and a space: directory path of a dragged folder into the Terminal window.
[ferro:˜] user% ls -l You can drag multiple files to the Terminal if you are typing
a command that takes several arguments, such as the diff
Then switch to Finder and locate the file. Click and hold the
shell command. You need to remember to type spaces
mouse button on the file™s icon and then drag it to whatever
between each file, or the pathnames will not be separated
part of your Terminal window is visible. You do not need to
and will be read as one long pathname.
be able to see the full window, only a portion of it. When you


DRAG PATHNAMES TO THE TERMINAL WINDOW




„ Type a command that ¤ Locate the file's icon in › Release the mouse button.
takes a filename argument. the Mac OS X Finder.
– The full path to the file is
‹ Click and drag the icon inserted at the cursor.
onto the Terminal window.




133
UNIX FOR MAC



CONNECT TO THE INTERNET
If your Macintosh is a home-based system, you will

T
he Internet is a loose connection of systems and
probably hook up to the network using a dial-up or DSL
networks that spans the globe. This supernetwork
connection. If your Macintosh is on your desk at work, you
makes it possible for people in New Jersey to send
will probably hook up to network wiring that is installed
e-mail to people in Ethiopia, for teens in California to read
throughout your building. After you are connected, you can
their Pennsylvania grandmother's recipes on the Web, and
use all the services of the Internet from the classics, such as
for people to chat and form meaningful relationships with
telnet and ftp, to Web surfing and more.
people they may never meet face to face.
Home-based systems almost always rely on technology that
Connecting a Mac OS X system to the Internet is relatively
automatically assigns an address to the system and directs it
easy. You can establish dial-up, digital subscriber line (DSL),
to a name server and router that allows it to reach other
and local area network (LAN) connections, depending on
systems. Although these topics are not covered in depth in
your resources and circumstances.
this chapter, you should know the names of these services.
Dynamic Host Configuration Protocol (DHCP) dynamically
Unix systems were built to be networked. In fact, the first
assigns IP addresses to its client systems. Domain Name
Unix systems and the first efforts to connect systems from
System (DNS) allows you to look up domain names, such as
different locations on the first internetworks started as
www.apple.com, and retrieve their IP addresses.
contemporaries. Mac OS X is no exception. Mac OS X
systems run the Internet networking protocols ” a
collection of protocols called Transmission Control
Protocol/Internet Protocol (TCP/IP) ” natively.

CONNECT TO THE INTERNET




System Preferences...




– The System Preferences – Your dial-up connection is
EXAMINE YOUR NETWORK
CONNECTION window opens. established.
„ Click Apple OSX ➪ ¤ Select Network under
System Preferences. Internet & Network.




134
10
WORK WITH INTERNET COMMANDS




Connecting to the Internet allows you to take advantage of a
wealth of information and services. Understanding the basics of
how this connection works will make it easier for you to report on
and resolve problems when they occur.
For dial-up accounts, you generally do not need to be concerned
about the IP address, subnet mask, DNS server, or default router that
your system will use. Although this information is critical to your
network connection, your Internet service provider (ISP) assigns it
when you connect. If your Macintosh is attached to a local area
network, you might use a static IP address ” one that is permanently
assigned to your system ” or one that a DHCP server assigns when
you boot your system.
Regardless of how this information is assigned, your system requires
a unique IP address to identify it as a member of a network, a
subnet mask to allow the system to determine the extent of the
local network, a default router to direct remote connections, and a
DNS server to allow you to locate systems by name.




– You will be prompted to – You will be prompted to
SET UP A NETWORK SET UP A DIAL-UP CONNECTION
CONNECTION save the information upon save the information upon
„ Click the PPPoE tab.
„ Enter your IP Address and closing the form. closing the form.
¤ Type the information
Subnet Mask on the TCP/IP – Check with your system provided to you by your ISP.
tab. administrator if you are
¤ Enter your DNS Servers unsure about these settings.
and domains.
135
UNIX FOR MAC



LOOK UP AN INTERNET ADDRESS
house number. A subnet mask allows a system to determine

Y

<<

. 28
( 69 .)



>>