Mac OS X Hacks
|
| Price: |
Product Description
This volume presents a unique opportunity for combining traditional Unix hacking and Mac OS know-how. Mac OS X Hacks goes beyond the peculiar mix of man pages and not-particularly-helpful Help Centre, pulling the best tips, tricks, and tools from the Mac power users and Unix hackers themselves. The collection reflects the real-world know how and experience of those well steeped in Unix history and expertise, sharing their no-nonsense, sometimes quick-and-dirty solutions to administering and taking full advantage of everything a Unix desktop has to offer: Web, Mail, and FTP serving, security services, SSH, Perl and shell scripting, compiling, configuring, scheduling, networking, and hacking. Add to that the experience of die-hard Macintosh users, customizing and modifying their hardware and software to meet their needs: System Preferences, GUI mods and tweaks, hardware tips, vital shareware and freeware, AppleScript, AppleTalk and equivalents, keyboard modifiers, and general Macintosh-style tomfoolery. Each Hack can be read easily in a few minutes, saving countless hours of searching for the right answer. Mac OS X Hacks provides direct, hands-on solutions that can be applied to the challenges the first time and long-time users delving into Mac OS X and its Unix underpinnings. Mac OS X Hacks is the third in O'Reilly's new Hacks Serier which aims to begin reclaiming the term "hacking" for the good guys. In recent years, the term has come to be associated with those nefarious black hats who break into computers to snoop, steal information or disrupt Internet traffic. But the term originally had a more benign meaning, and you'll still hear it used this way whenever developers get together. Our new Hacks books are written in the spirit of the true hackers - the people who drive innovation.
Product Details
- Amazon Sales Rank: #1052304 in Books
- Published on: 2003-04-01
- Original language: English
- Number of items: 1
- Binding: Paperback
- 304 pages
Editorial Reviews
About the Author
Rael Dornfest is a Researcher at the O'Reilly & Associates focusing on technologies just beyond the pale. He assesses, experiments, programs, and writes for the O'Reilly network and O'Reilly publications. Dornfest is Program Chair of the O'Reilly Emerging Technology Conference, Chair of the RSS-DEV Working Group, and developer of Meerkat: An Open Wire Service. In his copious free time, he develops bits and bobs of Open Source software and maintains his raelity bytes Weblog. Kevin Hemenway, better known as Morbus Iff, is the creator of disobey.com, which bills itself as "content for the discontented." Publisher and developer of more home cooking than you could ever imagine, he'd love to give you a Fry Pan of Intellect upside the head. Politely, of course. And with love.
Excerpted from Mac OS X Hacks by Rael Dornfest, Kevin Hemenway. Copyright © 2003. Reprinted by permission. All rights reserved.
Hack #45
Speakable Web Services
Explore Mac OS X’s speech recognition and its suitability for building useful, voice-driven commands that invoke external as well as local web services.
When Scotty tried to talk to a Macintosh through its mouse in Star Trek IV (1986), the joke was on Apple.Why couldn ’t this famously easy-to-use computer accept the most natural form of input? Over the years, I dabbled now and then with voice command systems,but they never seemed worth the trouble —until now.I ’ve been exploring the speech technologies in Mac OS X on an 800MHz TiBook,and I’m really impressed. Apple has done a marvelous job with the recognition and control systems,and now that you can script the Internet so easily in OS X,it’s straightforward to build useful voice-driven commands that invoke external as well as local services.Consider this dialog:
Me:"Temperature "
Computer:"36 degrees "
There are,of course,a million ways to look up the temperature on the Web. Most of them start with the browser.You fire it up and go to a bookmark. There are at least two problems with this scenario. First,you have to translate the request into an application context (the browser)and a procedure (go to bookmarks, select Local Weather). Second, you destroy your original context.For example, I’m typing these words in the Emacs Terminal-based text editor.I ’d like to keep on typing,and reading what I am writing,even as I ask for and receive the temperature.Speaking the request and hearing the response is an ideal solution. Here are a few ways to implement it.
->getTemp('03431')."degrees";
`osascript -e 'say "$temp"'`;
Here, we’re using Perl ’s backtick evaluation to run a command-line tool, osascript, which runs AppleScript code —in this case, to speak the result of the SOAP call. Use of the text-to-speech engine introduces some fascinating subtleties.For example,if you omit the leading space in degrees,the answer will sound like:
three six period zero dee eee gee are eee eee ess
It would be handy if you could just save this as a file called Temperature in the Speakable Items folder (for example,/Users/john/Library/Speech/SpeakableItems )and launch it by speaking the name "temperature."But so far as I ’ve been able to determine,scripted speakable items (as opposed to those that invoke key-driven commands)have to be written in AppleScript and,further,saved from the script editor as type application (not text or compiled script ).Fortunately,AppleScript can invoke the Unix shell,which can invoke the Perl script.
->getTemp('03431');
Isaved that script as /Users/jon/Temperature and then saved the following
AppleScript application as /Users/jon/Library/Speech/SpeakableItems/
Temperature :
set theResult to do shell script "/Users/jon/Temperature"
say theResult &"degrees"as string
Now,the textual result of the Temperature script is spoken by AppleScript.
set theResult to call soap {method name:"getTemp",\
parameters:{zipcode:"03431"},method namespace \
uri:"urn:xmethods-Temperature",SOAPAction:"/TemperatureService"}
end tell
say theResult &"degrees"as string
This is easier in one way,harder in another.It ’s easier if you ’re not a Perl programmer or if you haven ’t added SOAP::Lite and its required substrate (expat ,XML::Parser)to the Perl kit that comes with Mac OS X. But when a web service is described by a Web Services Description Language (WSDL) file,it ’s easier to use SOAP::Lite than AppleScript, since the former can use the WSDL file to simplify access.
It ’s ideal when there ’s a web service that will give you the answer you ’re looking for,but when that ’s not the case,there ’s always good old HTML screen-scraping.In that case,a language like Perl or Python will run rings around AppleScript.
$res =~m#(.+)Jon ’s Radio(†+) #;
my $preface =$1;
my $count =$2;
$preface =~m#">(†+)ÿ #;
my $rank =$1;
'osascript -e 'say "Rank $rank,count $count"'';
In this case,it ’s more trouble than it ’s worth to return raw results from Perl and format them for speech output in AppleScript.
Ihave to confess I ’m still tempted to dismiss this speech stuff as an amusing parlor trick.But it may finally be reaching a tipping point.Look,Dad ’s talking to the computer, my kids snickered.When Ishowed my son he could play GnuChess using voice commands, though,he was riveted.It ’s a case-by-case thing,but when an application has a limited control vocabulary ("pawn a2 to a4 "),the Mac ’s speaker-independent speech recognition can give you hands-free control that ’s accurate and more effective than mouse control. Well,to be honest,mostly accurate.I ’m having a little trouble getting GnuChess to distinguish between "d "and "e "— a problem that could be solved by also supporting "delta " and "echo."
Not many of the XMethods services are likely candidates for voice treatment.Complex inputs and outputs don ’t make much sense.You can build IVR-style (interactive voice response)menus,like so:
tell application "SpeechRecognitionServer"
local choices
set choices to {"Temperature""BlogStats"}
set thePrompt to "What do you need to know?"
try
set theResult to listen for choices with prompt thePrompt giving .
up after 10
say (do shell script "/Users/Jon/"&theResult)
end try
end tell
Unless you really want to inflict voice trees on yourself,though,you ’ll probably soon tire of this approach,once the novelty wears off.Complex output is a nonstarter as well.It ’s faster to read than to hear more than a word or short phrase,the Mac ’s synthesized voices work best on short snippets,and there ’s no way for the computer to usefully speak structured output.Namespace Management

