Home > Articles

  • Print
  • + Share This
This chapter is from the book

Internet Services

Sherlock, one of the Apple applications included in Mac OS X, is a wonderful tool for searching the Internet and combining information from a variety of sources in a variety of formats. Movie searches, for example, can show you listings for theaters near a given location and even display QuickTime trailers for the movies.

Sherlock works by taking advantage of a very important new feature of the Web: Web services. You are used to using the Web interactively: You click on a link and a new page opens. Often, these are pages written in Hypertext Markup Language (HTML) using text editors or applications such as DreamWeaver or GoLive. However, many pages are built dynamically by applications located on the Web site you are visiting. Such applications are called application servers and go by names such as WebSphere (IBM), WebObjects (Apple), and WebLogic (BEA). Even FileMaker can function as an application server. An application server can take a request from a user running a browser and generate an HTML page that is transmitted to the user and displayed by the browser. The actual request is handled with HyperText Transfer Protocol (HTTP)—and you specify it at the beginning of a URL for a Web page as in http://www.apple.com.

When the request contains variable information—such as a word or phrase to search for in a search engine—a database is consulted by the application server to provide the information to be returned. The application server merges the information with prepared formatting information, and the HTML is created to be sent to your browser.

Web services take the HTML out of the picture. Instead of sending a request for an HTML page to be returned, an HTTP request is made to return the information. A common way of doing this is to use Simple Object Access Protocol (SOAP), which is an industry-standard for this type of access. It is based on another very important industry standard, extended Markup Language (XML), which is gradually supplanting HTML in many ways.

There is another protocol that is sometimes used, XML Remote Procedure Call (XML-RPC). AppleScript supports both. (Yet another implementation of this type of function is provided by Microsoft in its .Net software, which is still evolving.)

This is a very important advance for Internet processing, and it's a major leap forward for AppleScript. You can sit at your computer and use an online banking Web site to check your balance. If a recent deposit has cleared, you can then decide to pay a bill.

In the United States, most online banking sites update their information after they close the official books of the bank sometime during the evening of each business day. You might not want to wait around for that to happen. You can write a script to check your balance by going to an online banking Web site, but if that script runs automatically in the middle of the night, how will it know whether or not to pay the bill?

With SOAP or XML-RPC, instead of requesting the page with your bank balance, you can request the actual balance itself: a number, not an HTML page. It is very simple for a script to then check if that number is sufficient to cover a payment, and it can then submit the payment—also as a SOAP or XML-RPC request. There is no need for pointing or clicking or for you to read the information displayed on a Web page.

This is a very powerful technology, and it promises many changes in the ways in which Web sites work. For people using AppleScript, it offers an opportunity to retrieve data from the Web and then to pass it on to other applications or back to the Web. This can be done overnight or during the day but without human intervention.

SOAP and XML-RPC work because they are industry standards and because they, like HTML and HTTP, are basically very simple. However, widespread adoption of Web services may take many years—some people have estimated a decade or more. That is because converting many of these systems in banks, corporations, and other large organizations will take time.

If you want to get started with SOAP and XML-RPC, visit http://www.xmethods.net/. There you will find a listing of many Web services to which you can link from AppleScript (or any other language that supports the protocols). Looking at the list, you will see various types of services. Some demonstrate random retrieval of information from databases (Joke of the Day, Biblical Quote of the Day, and so forth). Others provide simple verifications of data—you can find one to return whether or not an address in the Netherlands is valid. Still others provide information such as stock quotes or temperatures, and there are yet more services that provide various translation and transfer features (such as those from IBM that convert images from one format to another).

The list of SOAP and XML-RPC services grows daily. Look at the list and you'll get ideas for services that you can use and even for services you might write.

You can look at the two Internet Services scripts to see how this is done: Later, in Hour 22, "Using AppleScript Across a Network," you'll find detailed instructions. But looking at these two scripts will not only give you an overview of how it's done, but will demonstrate a very important feature of AppleScript.

Fully half of each script is identical to the corresponding half of the other one. As you'll see throughout this book, large sections of AppleScript code can be used and reused with minor modifications.

  • + Share This
  • 🔖 Save To Your Account