278 59 10MB
English Pages 504 Year 2003
[ Team LiB ]
•
Table of Cont ent s
•
I ndex
•
Reviews
•
Reader Reviews
•
Errat a
Mac OS X Hacks By Rael Dornfest , Kevin Hem enway
Publisher
: O'Reilly
Pub Dat e
: March 2003
I SBN
: 0- 596- 00460- 5
Pages
: 430
Mac OS X Hacks reflect s t he real- world know how and experience of t hose well st eeped in Unix hist ory and expert ise, sharing t heir no- nonsense, som et im es quick- and- dirt y solut ions t o adm inist ering and t aking full advant age of everyt hing a Unix deskt op has t o offer: Web, Mail, and FTP serving, securit y services, SSH, Perl and shell script ing, com piling, configuring, scheduling, net working, and hacking. Add t o t hat t he experience of diehard Macint osh users, cust om izing and m odifying t heir hardware and soft ware t o m eet t heir needs: Syst em Preferences, GUI m ods and t weaks, hardware t ips, vit al shareware and freeware, AppleScript , AppleTalk and equivalent s, keyboard m odifiers, and general Macint osh- st yle t om foolery.
[ Team LiB ]
[ Team LiB ]
•
Table of Cont ent s
•
I ndex
•
Reviews
•
Reader Reviews
•
Errat a
Mac OS X Hacks By Rael Dornfest , Kevin Hem enway
Publisher
: O'Reilly
Pub Dat e
: March 2003
I SBN
: 0- 596- 00460- 5
Pages
: 430
Copyright Credit s About t he Aut hors Cont ribut ors Acknowledgm ent s
Foreword Preface How t o Use This Book How This Book I s Organized Convent ions Used in This Book How t o Cont act Us
Chapt er 1. Files
Sect ion 1.1. Hacks # 1- 12 Hack 1. Underst anding and Hacking Your User Account Hack 2. Taking t he Bit e Out of Backup Hack 3. Backing Up on t he Go Hack 4. Dealing wit h Archives of Many Colors: .im g, .sit , .t ar, .gz Hack 5. A Line Break I s a Line Break Hack 6. Fiddling wit h Type/ Creat or Codes and File Ext ensions Hack 7. Locking and Unlocking Files Hack 8. St ubborn Trash, St uck I m ages, and Jam m ed CDs Hack 9. Aliases, Sym links, and Hard Links Hack 10. Recent Filenam es Hack 11. I nspect ing t he Cont ent s of an .app Package Hack 12. Opening Microsoft Word Docum ent s Wit hout Microsoft Word
Chapt er 2. St art up Sect ion 2.1. Hacks # 13- 17 Hack 13. Get t ing a Glim pse of t he Boot Process Hack 14. Boot ing from Anot her Device Hack 15. Turning Your Mac int o a Hard Drive Hack 16. Using Open Firm ware Password Prot ect ion Hack 17. OS X for This Old Mac
Chapt er 3. Mult im edia and t he iApps Sect ion 3.1. Hacks # 18- 32 Hack 18. Top iChat Tips Hack 19. AI M Alt ernat ives Hack 20. Print ing t o PDF or Bit m apped I m age Hack 21. I m age Conversion in a Pinch Hack 22. Top 10 iPhot o Tips Hack 23. Make Your Own Docum ent ary Hack 24. From Slideshow t o Video Present at ion Hack 25. Hij acking Audio from Mac Apps Hack 26. Running Your Own Web Radio St at ion Hack 27. Sharing Your List ening Preferences Hack 28. Cont rolling iTunes wit h Perl Hack 29. iCal Calling iTunes Hack 30. Publishing and Subscribing t o iCal Calendars Hack 31. Using Bluet oot h for SMS and Phone- Call Handling
Hack 32. iSync via Bluet oot h
Chapt er 4. The User I nt erface Sect ion 4.1. Hacks # 33- 47 Hack 33. Finding Your Way Back t o t he Deskt op Hack 34. Alt - Tab Alt - Ternat ives Hack 35. Put t ing Things in t he Apple Menu Hack 36. Keeping Your Snippet s Organized Hack 37. LaunchBar, a Dock Alt ernat ive Hack 38. DockSwap, Anot her Dock Alt ernat ive Hack 39. Tinkering wit h Your User I nt erface Hack 40. Ext ending Your Screen Real Est at e wit h Virt ual Deskt ops Hack 41. Top Screenshot Tips Hack 42. Checking Your Mac's Pulse Hack 43. Screensaver as Deskt op Hack 44. Dipping Your Pen int o I nkwell Hack 45. Speakable Web Services Hack 46. Using AppleScript in Cont ext ual Menus Hack 47. Prying t he Chrom e Off Cocoa Applicat ions
Chapt er 5. Unix and t he Term inal Sect ion 5.1. Hacks # 48- 65 Hack 48. I nt roducing t he Term inal Hack 49. More Term inal Tricks and Tips Hack 50. Becom ing an Adm inist rat or for a Mom ent Hack 51. Edit ing Special Unix Files Hack 52. Set t ing Shell Environm ent Variables Hack 53. Scheduling wit h Syst em Tasks and Ot her Event s Hack 54. Opening Things from t he Com m and Line Hack 55. I nt roducing and I nst alling t he Mac OS X Developer Tools Hack 56. Top 10 Mac OS X Tips for Unix Geeks Hack 57. Turning a Com m and- Line Script int o an Applicat ion Hack 58. I nst alling Unix Applicat ions wit h Fink Hack 59. Mirroring Files and Direct ories wit h rsync Hack 60. Using CVS t o Manage Dat a on Mult iple Machines Hack 61. Downloading Files from t he Com m and Line Hack 62. Soft ware Updat e on t he Com m and Line Hack 63. I nt eract ing wit h t he Unix Shell from AppleScript
Hack 64. Running AppleScript s on a Regular Basis Aut om at ically Hack 65. Running Linux on an iBook
Chapt er 6. Net working Sect ion 6.1. Hacks # 66- 78 Hack 66. Anat om y of an I nt ernet Short cut Hack 67. Renewing Your DHCP- Assigned I P address Hack 68. Sharing an I nt ernet Connect ion Hack 69. Creat ing a One- Wire Net work Hack 70. Secure Tunneling wit h VPN or SSH Hack 71. Rem ot ely Log I n t o Anot her Machine via SSH Hack 72. Running Windows on and from a Mac Hack 73. Sharing Files Bet ween Mac and Windows PCs Hack 74. Mount ing a WebDAV Share Hack 75. Mount ing a Rem ot e FTP Direct ory Hack 76. Exchanging a File via Bluet oot h Hack 77. Using Your Cell Phone as a Bluet oot h Modem Hack 78. Set t ing Up Dom ain Nam e Service
Chapt er 7. Em ail Sect ion 7.1. Hacks # 79- 84 Hack 79. Tam ing t he Ent ourage Dat abase Hack 80. Using I MAP wit h Apple's Mail Applicat ion Hack 81. Set t ing Up I MAP and POP Mail Servers Hack 82. Get t ing sendm ail Up and Running Hack 83. Downloading POP Mail wit h fet chm ail Hack 84. Creat ing Mail Aliases
Chapt er 8. The Web Sect ion 8.1. Hacks # 85- 98 Hack 85. Searching t he I nt ernet from Your Deskt op Hack 86. Saving Web Pages for Offline Reading Hack 87. Reading Syndicat ed Online Cont ent Hack 88. Serving Up a Web Sit e wit h t he Built - I n Apache Server Hack 89. Edit ing t he Apache Web Server's Configurat ion Hack 90. Build Your Own Apache Server wit h m od_perl Hack 91. AppleScript CGI wit h ACGI Dispat cher Hack 92. Turning on CGI Hack 93. Turning on PHP
Hack 94. Turning on Server- Side I ncludes ( SSI ) Hack 95. Turning on WebDAV Hack 96. Cont rolling Web- Server Access by Host nam e or I P Address Hack 97. Cont rolling Web- Server Access by Usernam e and Group Hack 98. Direct ory Aliasing, I ndexing, and Aut oindexing
Chapt er 9. Dat abases Sect ion 9.1. Hacks # 99- 100 Hack 99. I nst alling t he MySQL Dat abase Hack 100. I nst alling t he Post greSQL Dat abase
Colophon I ndex
[ Team LiB ]
[ Team LiB ] Copyright © 2003 O'Reilly & Associat es, I nc. Print ed in t he Unit ed St at es of Am erica. Published by O'Reilly & Associat es, I nc., 1005 Gravenst ein Highway Nort h, Sebast opol, CA 95472. O'Reilly & Associat es books m ay be purchased for educat ional, business, or sales prom ot ional use. Online edit ions are also available for m ost t it les ( ht t p: / / safari.oreilly.com ) . For m ore inform at ion, cont act our corporat e/ inst it ut ional sales depart m ent : ( 800) 998- 9938 or corporat [email protected] . Nut shell Handbook, t he Nut shell Handbook logo, and t he O'Reilly logo are regist ered t radem arks of O'Reilly & Associat es, I nc. Many of t he designat ions used by m anufact urers and sellers t o dist inguish t heir product s are claim ed as t radem arks. Where t hose designat ions appear in t his book, and O'Reilly & Associat es, I nc. was aware of a t radem ark claim , t he designat ions have been print ed in caps or init ial caps. The associat ion bet ween t he im age of a wrench and t he t opic of Mac OS X is a t radem ark of O'Reilly & Associat es, I nc. The t radem arks " Hacks Books" and " The Hacks Series," and relat ed t rade dress, are owned by O'Reilly & Associat es, I nc., in t he Unit ed St at es and ot her count ries, and m ay not be used wit hout writ t en perm ission. All ot her t radem arks are propert y of t heir respect ive owners. While every precaut ion has been t aken in t he preparat ion of t his book, t he publisher and aut hors assum e no responsibilit y for errors or om issions, or for dam ages result ing from t he use of t he inform at ion cont ained herein.
[ Team LiB ]
[ Team LiB ] Credits
About t he Aut hors Cont ribut ors Acknowledgm ent s
[ Team LiB ]
[ Team LiB ] About the Authors Rael Dornfest is a m aven at O'Reilly & Associat es, I nc., focusing on t echnologies j ust beyond t he pale. He assesses, experim ent s, program s, and writ es for t he O'Reilly Net work and O'Reilly publicat ions. Rael has edit ed, coaut hored, and cont ribut ed t o various O'Reilly books. He is program chair for t he O'Reilly Em erging Technology Conference and O'Reilly Mac OS X Conference, chair of t he RSS- DEV Working Group, and developer of Meerkat : An Open Wire Service ( m eerkat .oreillynet .com ) . I n his copious free t im e, Rael develops bit s and bobs of freeware and m aint ains his raelit y byt es weblog ( ht t p: / / www.raelit y.org) . Kevin Hem enway, bet t er known as Morbus I ff, is t he creat or of disobey.com , which bills it self as " cont ent for t he discont ent ed." Publisher, developer, and writ er of m ore hom e cooking t han you could ever im agine ( like t he popular open source syndicat ed reader Am phet aDesk, t he best - kept gam ing secret Gam egrene.com , t he popular Ghost Sit es and Nonsense Net work, t he giggle- inducing art icles at t he O'Reilly Net work, a few pieces at Apple's I nt ernet Developer sit e, et c.) he's an ardent support er of cloning, m erely so he can get m ore work done. He cooks wit h a Fry Pan of I nt ellect + 2 and lives in Concord, NH. You can cont act him at m [email protected] .
[ Team LiB ]
[ Team LiB ] Contributors The following people cont ribut ed t o t his book: ●
●
●
●
●
●
●
●
●
Michael Brewer ( ht t p: / / m brewer.dyndns.org/ m acosxhacks/ ) is a developer based near Charlot t e, Nort h Carolina. He has writ t en several OS X- relat ed art icles for O'Reilly Mac DevCent er. His int erest s include web developm ent of various flavors ( prim arily Java) and dat abase design. When t he weekend rolls around, t hose t end t o disappear and he focuses on m ount ain biking. Jam es Duncan Davidson ( ht t p: / / www.x180.net / ) is a freelance aut hor, speaker, and soft ware consult ant focusing on Mac OS X, Java, and XML t echnologies. He regularly present s at conferences all over t he world on t opics ranging from open source t o program m ing Java effect ively. He was t he original aut hor of Apache Tom cat and Apache Ant and was inst rum ent al in t heir donat ion t o t he Apache Soft ware Foundat ion by Sun Microsyst em s. While working at Sun, he aut hored t wo versions of t he Java Servlet API specificat ion, as well as t he Java API for XML Processing specificat ion. He current ly resides in San Francisco, California. Edd Dum bill is Managing Edit or of XML.com . He also writ es free soft ware, and packages Bluet oot h- relat ed soft ware for t he Debian GNU/ Linux dist ribut ion. Edd is t he creat or of XMLhack ( ht t p: / / xm lhack.com / ) and Writ eTheWeb ( ht t p: / / writ et heweb.com / ) . Rob Flickenger was born t he son of a pig farm er in Bucharest . This young ne'er- do- well had few am bit ions above m ucking out t he slop st all before dinner. But t hat was j ust at t he dawn of t he digit al age. Who would have t hought t hat five years lat er t he sam e boy who t hought cow t ipping shouldn't go above 10% would go on t o invent t he I nt ernet and event ually becom e t he first living hum an wit h an ADSL line surgically at t ached t o his spinal colum n. Now, in t hese increasingly unt et hered t im es, he has eschewed his form er 6Mbit neural I / O port for an 11Mbit , encrypt ed, wireless version. I t cert ainly m akes it easier t o leave t he house wit hout t he need for m iles of ext ension cord. I n his spare t im e, he also writ es; Rob is t he aut hor of Building Wireless Com m unit y Net works and Linux Server Hacks. brian d foy ( ht t p: / / www.panix.com / ~ com dog/ ) has been a dedicat ed Mac user since a Quadra 650, which he st ill uses. Seven Macs lat er, m ost of t hem st ill in use, he deals alm ost exclusively wit h Mac OS X for his Perl developm ent work, even if he has t o use Virt ual PC t o cheat . He is also a Perl developer and t rainer who m aint ains several Perl m odules on CPAN and publishes The Perl Review, all from his PoweBbook. Alan Graham 's ( ht t p: / / hom epage.m ac.com / agraham 999/ ) m ission, using wit sharp as an elect ric razor and a m odicum of gram m at ical skill, is enabling users t o explore what 's possible wit h st raight t alk and as lit t le t echno- babble as possible. He has worked in prepress, digit al video and film , int eract ive, soft ware developm ent , and web developm ent for a wide spect rum of client s t hat include Apple Com put er, Sausage Soft ware, Mat t el, Bet t er Hom es & Gardens, OpenMarket , PresenceWorks.com , Param ount , and Excit e@hom e t o nam e a few. When he's not writ ing for O'Reilly, you can find him doing R&D for Mac OS X: The Missing Manual, running errands for his pregnant wife Dana, and working on t he great Am erican novel. You can find m ore of Alan's writ ing via his blog, Trial and Eror ( ht t p: / / hom epage.m ac.com / agraham 999/ iblog/ ) . Brian Jepson ( ht t p: / / www.j epst one.net / ) m aint ains a keen focus on t he sparks t hat fly where t wo cut t ing edges m eet . Som e of his favorit e int ersect ions are Mac OS X ( where a solid Unix core m eet s t he pioneering Apple user int erface) , Mono and Port able.NET ( where Open Source m eet s Windows) , and Rot or ( where Microsoft shares a bunch of code wit h y'all) . Brian is also an O'Reilly edit or and coaut hor of Mac OS X for Unix Geeks and Learning Unix for Mac OS X. Wei- Meng Lee ( ht t p: / / www.oreillynet .com / pub/ au/ 944) t eaches at t he School of I nform at ion and Com m unicat ions Technology, NgeeAnn Polyt echnic, Singapore. He is an experienced aut hor, t rainer, and developer specializing in Mac OS X and Microsoft .NET t echnologies. Wei- Meng is also a writ er for t he O'Reilly Net work and a cont ribut ing aut hor t o SQL Server Magazine and DevX.com . Jason McI nt osh ( ht t p: / / www.j m ac.org/ ) lives and works in and around Bost on. He has coaut hored t wo
●
●
●
●
●
●
●
O'Reilly books, Mac OS X in a Nut shell and Perl & XML, and writ es occasional colum ns and weblog ent ries for t he O'Reilly Net work. Bruce W. Perry is an independent soft ware developer and writ er. Since 1996, he has developed web applicat ions and dat abases for various nonprofit s, design and m arket ing firm s, ad agencies, and digit alm usic specialist s. Before working in t he web field, Perry rem ained t et hered t o his port able and deskt op Macs while writ ing environm ent al law books and newslet t ers. When not hacking or writ ing, he loves cycling and clim bing m ount ains in t he U.S. and Swit zerland. He lives in t he Newburyport , Massachuset t s area wit h his wife St acy LeBaron and daught er Rachel. Erik T. Ray has worked for O'Reilly as a soft ware developer and XML specialist since 1995. He helped t o est ablish a com plet e publishing solut ion using DocBook- XML and Perl t o produce books in print , on CDROM, and for t he new Safari web library of books. As t he aut hor of t he O'Reilly best seller Learning XML and num erous art icles in t echnical j ournals, Erik is known for his clear and ent ert aining writ ing st yle. When not ham m ering out code, he enj oys playing card gam es, reading about hem orrhagic fevers, pract icing Buddhist m edit at ion, and collect ing t oys. He lives in Saugus, MA wit h his wife Jeannine and seven parrot s. Mat t hew Sparby ( ht t p: / / www.obzorg.org/ ) is a t echnology consult ant and Macint osh hobbyist from Orlando, Florida. He publishes t he Mac- cent ric web sit e Obzorg.org and cont ribut es m at erial t o ot her t echnology publicat ions and user groups Chris St one is a Senior Syst em s Adm inist rat or ( t he Mac guy) at O'Reilly and coaut hor of Mac OS X in a Nut shell. He's writ t en several Mac OS X- relat ed art icles for t he O'Reilly MacDevCent er ( ht t p: / / www. m acdevcent er.com ) and cont ribut ed t o Mac OS X: The Missing Manual. Chris lives in Pet alum a, California wit h his wife Miho and t wo sons, Andrew and Jonat han. Derrick St ory ( ht t p: / / www.st oryphot o.com / ) is t he coaut hor of iPhot o: The Missing Manual and aut hor of t he Digit al Phot ography Pocket Guide. His day j ob is m anaging edit or of O'Reilly Net work and t he Mac DevCent er ( ht t p: / / www.m acdevcent er.com / ) . Derrick's experience includes m ore t han 15 years as a phot oj ournalist , a st int as t he m anaging edit or for Web Review, and speaker at CMP and I DG t ech conferences. He also m anages his online phot o business, St ory Phot ography. Jon Udell ( ht t p: / / udell.roninhouse.com / ) is lead analyst for t he I nfoWorld Test Cent er. He is t he aut hor of Pract ical I nt ernet Groupware, published in 1999 by O'Reilly, and an advisor t o O'Reilly's Safari Tech Books Online. David E. Wheeler ( ht t p: / / david.wheeler.net / ) is President of Kinet icode ( ht t p: / / www.kinet icode.com / ) , an ent erprise cont ent m anagem ent and soft ware developm ent consult ing com pany based in San Francisco. He also serves as t he m aint ainer and lead developer for Bricolage, an open- source cont ent m anagem ent syst em built on Apache, mo d _ p e r l , and Post greSQL. An act ive m em ber of t he Perl com m unit y and a speaker at t he O'Reilly Mac OS X Conference ( ht t p: / / conferences.oreilly.com / m acosxcon/ ) , David has cont ribut ed an appendix int roducing Bricolage t o O'Reilly's Em bedding Perl in HTML wit h Mason, as well as several art icles addressing t he needs of t he serious Mac OS X- based Perl and Unix developer. David lives in San Francisco wit h his wife, Julie, and t heir t wo cat s.
[ Team LiB ]
[ Team LiB ] Acknowledgments We would like t o t hank all t hose who cont ribut ed t heir ideas and code for Mac OS X hacks t o t his book.
Rael First and forem ost , t o Asha and Sam — always m y inspirat ion, j oy, and best friends. My ext ended fam ily and friends, bot h local and virt ual, who'd begun t o wonder if t hey needed t o send in a rescue part y. I 'd like t o t hank Dale Doughert y for bringing m e in t o work on t he Hacks series; working from t he ot her side of t he page has been a learning experience and a half. The O'Reilly edit ors, product ion, product m anagem ent , and m arket ing st aff are consum m at e professionals, hackers, and m ensches. They've helped m e im m easurably in m y fledgling edit orial st int . Ext ra special t hanks goes out t o m y virt ual cube- m at e, Nat Torkingt on, and Laurie Pet rycki for showing m e t he ropes.
Kevin Thanks t o Derrick for suggest ing t he O'Reilly Net work art icle t hat event ually cascaded int o m y current t ech writ ing posit ion, as well as Aaron for t he good word he m ay or m ay not have put in for m e. To Kat herine for put t ing up wit h m y absent - m inded " I 'm busy! ," and t o Philip for get t ing m e int o Perl, Linux, and " bullet s! lot s of bullet s! ! " To Sean for picking t he berries from m y j am , and t o Deb, who has wat ched m e blossom int o t he handsom e young st allion I am now, while I have m erely wat ched her grow older and older. Don't forget m y discount .
[ Team LiB ]
[ Team LiB ] Foreword From one perspect ive, Mac OS X is heresy. I t 's an Apple operat ing syst em wit h a com m and line. I t doesn't hide it s innards from t inkerers and hackers. I t 's not a closed box wit h a st icker t hat says, " NO USER SERVI CEABLE PARTS I NSI DE," like all previous Mac operat ing syst em s. I n short , it 's a shocking and flagrant violat ion of everyt hing t he Mac has ever st ood for. As it t urns out , nobody m uch cares. Newbies plug along, clicking Dock icons and dragging t hings t o t he Trash, wit hout ever suspect ing t hat only a t hin shell of shiny pixels separat es t hem from t he seet hing, t hrashing Unix engine beneat h. And power users are on Cloud 9. So here t hey com e, out of t he woodwork: a nat ion of once m arginalized Unix geeks, em bracing t he Mac, hailing Apple as t he world's largest m anufact urer of Unix boxes. These people are t he pure of heart , t he superusers who clust er at com put er conferences wit h t heir PowerBook G4s and shoot bit s of code at each ot her over t he wireless net work. Apple m ay have lost t he bat t le for t he corporat e deskt op, but wit h Mac OS X, it 's picked up a new const it uency of it s own. Part of t he pleasure of reading t his book com es from t he hacks t hem selves: cont rolling iTunes wit h Perl script s, using a Bluet oot h cellphone as a wireless m odem for your lapt op, downloading files from t he com m and line, and ot her prepost erous st unt s. But m uch of t he pleasure, t oo, com es from t he pure, geeky fun t he aut hors seem t o be having. These are not serious adult m ales at t he peaks of t heir writ ing careers — t hey're five- year- olds st om ping in puddles, laughing t heir heads off. These are people who don't for a m om ent quest ion t he value of t urning t he Mac int o an I nt ernet radio st at ion powered by iTunes. Hey — it 's cool, and t hat 's t he great est value of all. These guys will lead you t o favorit e shareware program s, shine light on clever Unix com m and- line hacks, and show you how t o t urn off t he brushed- m et al window look of iChat and iSync. ( Why? Because you can! ) This book m ight occasionally be over t he head of m any Mac fans. ( I f you want m ore general, less t echnical, everyday operat ing t ips, t ry Mac OS X Hint s, Jaguar Edit ion.) But som e people get as m uch a kick out of put t ing a com put er t hrough it s paces as t hey do from everyday issues like product ivit y. Part of t he spirit of hacking is doing t hings t hat t he product 's developer didn't quit e im agine, finding t he new and creat ive uses t hat only are possible t o t hose who are willing t o leave t he beat en pat h. For t he hackers am ong us, it 's all about t he t hrill of discovery. I f you're one of t hem , put on your backpack; you're about t o go on quit e a ride. —David Pogue, Creat or of t he Missing Manual series
[ Team LiB ]
[ Team LiB ] Preface Mac OS X is a m arvelous confluence of t he user- friendly and highly cust om izable Macint osh of yest eryear and t he power and flexibilit y of Unix under t he hood. Those com ing t o Mac OS X from previous incarnat ions of t he operat ing syst em , while recognizing m uch of t he friendly face of t he Macint osh, are plunged int o a whole new world where t hings are alm ost like t hey were, but not quit e — not t o m ent ion all t hat Unix com m and- line st uff lurking in t he Term inal applicat ion. Unix convert s t o Mac OS X find a fam iliar FreeBSD- like operat ing syst em at t he core and m any of t he com m and- line applicat ions t hey're fam iliar wit h eit her already inst alled or a package or com pile away. On t he front end, however, m uch t hat is second nat ure t o an old Mac hand is st range and new, at once fascinat ing and confounding t o t hose used t o t he likes of X Windows and GNOME. This present s a unique opport unit y for com bining t radit ional Unix hacking and Mac OS know- how. Mac OS X Hacks goes beyond t he peculiar m ix of m anpages and not - part icularly- helpful Help Cent er, pulling t he best t ips, t ricks, and script s from Mac power users and Unix hackers t hem selves. The collect ion reflect s t he real- world experience of t hose well st eeped in Unix hist ory and expert ise, sharing t heir no- nonsense, som et im es quick- and- dirt y solut ions t o adm inist ering and t aking full advant age of everyt hing a Unix deskt op has t o offer: web, m ail, and FTP serving; securit y services; SSH, Perl, and shell script ing, as well as com piling, configuring, scheduling, net working, and hacking. Add t o t hat t he experience of die- hard Macint osh users, cust om izing and m odifying t heir hardware and soft ware t o m eet t heir needs: Syst em Preferences, GUI m ods and t weaks, hardware t ips, vit al shareware and freeware, AppleScript , AppleTalk and equivalent s, keyboard m odifiers, and general Macint osh- st yle t om foolery. Each hack can be read easily in a few m inut es, saving count less hours of searching for t he right answer. Mac OS X Hacks provides direct , hands- on solut ions t hat can be applied t o t he challenges facing bot h t hose m eet ing t he Mac for t he first t im e and longt im e users delving int o Mac OS X and it s Unix underpinnings. The collect ion should appeal t o hom e users and corporat e I T personnel alike.
[ Team LiB ]
[ Team LiB ] How to Use This Book You can read t his book cover- t o- cover if you like; but , for t he m ost part , each hack st ands on it s own. I f t here's a prerequisit e you ought t o know about , t here'll be a cross- reference t o guide you on t he right pat h. So feel free t o browse, flipping around what ever sect ion int erest s you m ost .
[ Team LiB ]
[ Team LiB ] How This Book Is Organized Mac OS X is rem arkable enough t o bring t oget her, on one deskt op, longt im e Mac devot ees and Unix hackers of old. I t does so by rebuilding t he renowned Mac look- and- feel on t he shoulders of a best - of- breed Unix operat ing syst em . OS X's flexibilit y, cust om izabilit y, and ext ensibilit y m ean t here's j ust about not hing you can't do if you set your m ind t o it . This book goes beyond t he sim ple t ips and t ricks, click here and drag t here, t o t he m ore int erest ing hacks — bit e- sized bit s of t ruly useful funct ionalit y you can m anage in j ust a few m inut es wit h t he help of a t rust y friend. The book is divided int o several chapt ers: Chapt er 1, Files The Mac OS X filesyst em is a blend of powerful, ancient Unix underpinnings and t he candy- coat ed shell known as t he Macint osh Finder. The hacks in t his sect ion poke and prod at t he seam s, revealing som e useful t echniques for backing up your syst em , t weaking files and folders, bending aliases t o your will, and underst anding how it all fit s t oget her — even dum pst er diving in t he Trash a lit t le. Chapt er 2, St art up At st art up, t here's an awful lot going on behind t he scenes t o bring your Mac t o life. This sect ion t akes a peek beneat h t he surface at j ust what 's m aking all t hat noise. We'll show you how t o boot from anot her device, t urn your Mac int o a FireWire hard drive, get OS X running on t hat old Power Mac in your closet , and lock up your Mac good and t ight . Chapt er 3, Mult im edia and t he iApps Apple has posit ioned t he Mac as a digit al hub, t he nexus for t he ot herwise disparat e com ponent s of your iLife. This sect ion provides t ips and t echniques for get t ing t he m ost out of t he iApps and t hird- part y m ult im edia applicat ions. Going beyond what t he iApps provide out of t he box, we'll also glue t oget her audio, video, t ext , and phot os in som e unexpect edly useful and fun com binat ions. Chapt er 4, The User I nt erface Mac users have a long hist ory of t weaking t he Mac OS graphical user- int erface. We provide a collect ion of inspiring hacks and point ers t o t hird- part y applicat ions for t weaking t he look- and- feel, ext ending t he funct ionalit y t hat 's already t here, and t eaching your Mac t o behave " j ust as it should." Chapt er 5, Unix and t he Term inal Beneat h t he sleek, elegant , Technicolor candy coat ing of Mac OS X's graphical user- int erface beat s t he heart of an honest - t o- goodness Unix operat ing syst em . This chapt er provides a gent le int roduct ion t o t he com m and- line environm ent , showing how t o m ove around and m anipulat e files and folders. Wit h t hat under your belt , we'll show you how t o t hread som e of t he built - in Unix applicat ions and funct ions t oget her t o creat e new funct ionalit y. Chapt er 6, Net working
Where OS X really shines is in it s net working, being able t o connect t o j ust about anyt hing wit h an I P heart beat . Com m unicat e as easily wit h Windows and Unix m achines as wit h ot her Macs. Share your I nt ernet connect ion via Et hernet , WiFi, or FireWire or connect one- t o- one wit h anot her com put er even when t here is no net work t o be found. This chapt er highlight s j ust som e of t he lim it less possibilit ies for int ernet working wit h j ust about anyt hing, j ust about anywhere. Chapt er 7, Em ail More t han j ust a choice of excellent m ail applicat ions, OS X's powerful Unix underpinnings provide access t o an array of t he m ost popular and versat ile m ail servers and filt ering syst em s on t he planet . This chapt er t akes you t hrough t urning your Mac int o a personal int ranet m ail server, as well as t eaching you a lit t le m ore about som e of t he m ail applicat ions you m ay be using and how t o get t he m ost out of t hem . Chapt er 8, The Web Mac OS X is a web powerhouse, bot h in t erm s of it s web- serving capabilit ies and wide range of web browsers from which t o choose. Beneat h t he underst at ed Personal Web Sharing is t he ubiquit ous, flexible, and indust rial- st rengt h Apache web server — j ust click t he St art but t on. By t he end of t his chapt er, you'll be serving up dynam ic cont ent , running CGI applicat ions, script ing PHP pages, and put t ing t oget her server- side include- driven pages wit h t he best of t hem . Chapt er 9, Dat abases Long t he backbone of j ust about any open source- driven web sit e, t he MySQL and Post greSQL dat abase engines are j ust as at hom e on your Mac as t hey have been in t he m ore t radit ional Unix shop. This chapt er walks you t hrough t he inst allat ion and explorat ion of t hese t wo rem arkable dat abase applicat ions, on bot h t he com m and line and t he Deskt op.
[ Team LiB ]
[ Team LiB ] Conventions Used in This Book The following is a list of t he t ypographical convent ions used in t his book: I t alic Used t o indicat e new t erm s, URLs, filenam es, file ext ensions, and direct ories and t o highlight com m ent s in exam ples. For exam ple, a pat h in t he filesyst em will appear as / Developer/ Applicat ions.
Cons t a n t wi d t h Used t o show code exam ples, t he cont ent s of files, com m ands, or t he out put from com m ands. Cons t a nt wi d t h b o l d Used in exam ples and t ables t o show com m ands or ot her t ext t hat should be t yped lit erally.
Cons t a n t wi d t h i t a l i c Used in exam ples and t ables t o show t ext t hat should be replaced wit h user- supplied values. Color The second color is used t o indicat e a cross- reference wit hin t he t ext . RETURN A carriage ret urn ( RETURN) at t he end of a line of code is used t o denot e an unnat ural line break; t hat is, you should not ent er t hese as t wo lines of code, but as one cont inuous line. Mult iple lines are used in t hese cases due t o page widt h const raint s. Menu sym bols When looking at t he m enus for any applicat ion, you will see som e sym bols associat ed wit h keyboard short cut s for a part icular com m and. For exam ple, t o open an old chat in iChat , you would go t o t he File m enu and select Open . . . ( File Open . . . ) , or you could issue t he keyboard short cut , - O. The sym bol corresponds t o t he key ( also known as t he " Com m and" key) , locat ed t o t he left and right of t he spacebar on any Macint osh keyboard. You should pay special at t ent ion t o not es set apart from t he t ext wit h t he following icons:
This is a t ip, suggest ion, or general not e. I t cont ains useful supplem ent ary inform at ion about t he t opic at hand.
This is a warning or not e of caut ion.
The t herm om et er icons, found next t o each hack, indicat e t he relat ive com plexit y of t he hack:
beginner
[ Team LiB ]
m oderat e
expert
[ Team LiB ] How to Contact Us We have t est ed and verified t he inform at ion in t his book t o t he best of our abilit y, but you m ay find t hat feat ures have changed ( or even t hat we have m ade m ist akes! ) . As a reader of t his book, you can help us t o im prove fut ure edit ions by sending us your feedback. Please let us know about any errors, inaccuracies, bugs, m isleading or confusing st at em ent s, and t ypos t hat you find anywhere in t his book. Please also let us know what we can do t o m ake t his book m ore useful t o you. We t ake your com m ent s seriously and will t ry t o incorporat e reasonable suggest ions int o fut ure edit ions. You can writ e t o us at : O'Reilly & Associat es, I nc. 1005 Gravenst ein Hwy N. Sebast opol, CA 95472 ( 800) 998- 9938 ( in t he U.S. or Canada) ( 707) 829- 0515 ( int ernat ional/ local) ( 707) 829- 0104 ( fax) You can also send us m essages elect ronically. To be put on t he m ailing list or t o request a cat alog, send em ail t o: [email protected] To ask t echnical quest ions or t o com m ent on t he book, send em ail t o: bookquest [email protected] The web sit e for Mac OS X Hacks list s exam ples, errat a, and plans for fut ure edit ions. You can find t his page at : ht t p: / / www.oreilly.com / cat alog/ m cosxhks For m ore inform at ion about t his book and ot hers, see t he O'Reilly web sit e: ht t p: / / www.oreilly.com Hack on! at : ht t p: / / hacks.oreilly.com
[ Team LiB ]
[ Team LiB ] Chapter 1. Files
Sect ion 1.1. Hacks # 1- 12 Hack 1. Underst anding and Hacking Your User Account Hack 2. Taking t he Bit e Out of Backup Hack 3. Backing Up on t he Go Hack 4. Dealing wit h Archives of Many Colors: .im g, .sit , .t ar, .gz Hack 5. A Line Break I s a Line Break Hack 6. Fiddling wit h Type/ Creat or Codes and File Ext ensions Hack 7. Locking and Unlocking Files Hack 8. St ubborn Trash, St uck I m ages, and Jam m ed CDs Hack 9. Aliases, Sym links, and Hard Links Hack 10. Recent Filenam es Hack 11. I nspect ing t he Cont ent s of an .app Package Hack 12. Opening Microsoft Word Docum ent s Wit hout Microsoft Word
[ Team LiB ]
[ Team LiB ] 1.1 Hacks #1-12 The Mac OS X filesyst em is a blend of powerful, ancient Unix underpinnings and t he candy- coat ed shell known as t he Macint osh Finder. To m ake t his a realit y, Mac OS X pulled off quit e a swit cheroo! I t yanked t he filesyst em of Mac OS 9 and earlier out from underneat h t he Finder's feet , replacing it wit h t he ut t erly foreign world of t he Unix filesyst em and all t hat goes wit h it . While all but invisible t o t he casual user, t here are som e cracks in t he façade, visible upon closer inspect ion. Som e are useful, ot hers a lit t le irrit at ing, and st ill ot hers sim ply fascinat ing and quit e hack- wort hy. The hacks in t his sect ion poke and prod at t he seam s, revealing som e useful t echniques for backing up your syst em , t weaking files and folders, bending aliases t o your will, underst anding how it all fit s t oget her — even dum pst er divingin t he Trash a lit t le.
[ Team LiB ]
[ Team LiB ] Hack 1 Understanding and Hacking Your User Account
Be for e M a c OS X w a s r e le a se d, t h e r e w a sn 't r e a lly a con ce pt of a u se r or a ccou n t in t h e M a cin t osh e n vir on m e n t . Th is h a ck in t r odu ce s you t o w h a t it m e a n s t o h a ve a n a ccou n t a n d w h a t t h is bu sin e ss of a H om e dir e ct or y is a ll a bou t . W e 'll a lso sh ow you h ow t o r e n a m e a n a ccou n t — a n on obviou s t a sk in de e d. When Mac OS X first appeared, a lot of people were aghast at t he concept of user account s, especially when t hey were t he only ones using t heir com put er. " Why go t hrough all t he hassle when only I exist ?" t hey asked. The com plaint s only int ensified as users were asked t o ent er an adm inist rat or password [ Hack # 50] for access t o cert ain files, som et im es even denied access t o set t ings and files on t heir very own com put ers — t he gall of it ! The reasoning is t wo- fold: t o prot ect you from yourself and t o support Mac OS X's m ult iuser environm ent . The concept of prot ect ing you from yourself m ay at first blush appear int rusive, but we've all had an inst ance where we've delet ed an innocent file from our OS 9 Syst em Folder, only t o discover our idiocy when our syst em didn't reboot , our print er didn't print , or our m odem didn't sizzle. I n t his regard, OS X has your back; crucial files necessary for everyday operat ion are prot ect ed from overzealous rem oval. The m ult iuser environm ent of OS X is based on t echnology t hat 's been around for a while in t he Unix world: a syst em of checks and balances t hat st op your kid sist er from gleefully delet ing t hat Phot oshop file you've been working on all weekend. Whet her you're t he only user isn't a concern; prot ect ion from t he inside ( yourself, your kid sist er) and prot ect ion from t he out side ( m alicious crackers, viruses, and t roj ans) becom es param ount . While a det erm ined user can delet e any file on t heir OS X m achine wit h enough effort ( t he easiest way being t o boot int o OS 9) , Apple has wisely m ade it difficult t o do so t hrough Mac OS X.
1.1 What's in a Name? When creat ing an account ( Syst em Preferences Account s New User . . . ) — eit her t he init ial account upon inst alling Mac OS X, or an addit ional account — you'll be prom pt ed for bot h your Nam e ( e.g., John Jacob Jingleheim er Schm idt ) and som et hing called a Short Nam e ( see Figure 1- 1) . Figu r e 1 - 1 . Se le ct in g a N a m e a n d Sh or t N a m e
Your Short Nam e is your act ual usernam e, or login nam e, t he nam e by which your com put er knows you. I t is usually t hree t o eight charact ers long, com posed of let t ers or num bers. While OS X at t em pt s t o choose a Short
Nam e for you based upon what you ent ered as your Nam e, it doesn't do a part icularly good j ob if your nam e isn't as sim ple as Sam Sm it h. And, t rust m e, you don't want t o spend your days being known by your com put er as j ohnj acobj ingleheim erschm idt . Choose som et hing short and quick t o t ype, like j ohn, j ohnj , or schm idt . Here's why . . .
1.2 Your Home Directory Your hom e direct ory is where you'll be keeping all your st uff ( see Figure 1- 2) . I n it you'll find special direct ories for your docum ent s, pict ures, m ovies, and set t ings ( t hat 's what t he Library is) . Of course, you're not forced t o organize your st uff t his way, but it is a good convent ion. Feel free t o set t le in, creat e new folders, and shuffle t hings about . I t 's generally a good idea not t o t hrow out t he special folders, as t he operat ing syst em and it s applicat ions oft en m ake use of t hem and expect t hem t o be t here. I n part icular, don't t ouch your Library folder; it 's t he hom e of your preferences, set t ings, and ot her pieces used by part icular applicat ions. Figu r e 1 - 2 . Fin de r vie w of a t ypica l h om e dir e ct or y
I f you chose j ohn as your Short Nam e, t hen your hom e direct ory will be Macint osh HD Users j ohn. By creat ing a cent ral place for all your im port ant dat a, OS X ensures easy backup or deploym ent on ot her m achines. I nst ead of having t o single out your favorit e cont rol panels or ext ensions from OS 9, you can sim ply backup your hom e direct ory. When you're ready t o rest ore, sim ply copy it over t o t he sam e locat ion, and your environm ent ( iTunes m usic library, deskt op pict ures, added soft ware t weaks, et c.) will t ake effect t he next t im e you log in. From t he com m and line's [ Hack # 48] point of view, your hom e direct ory — again, assum ing your Short Nam e is j ohn — is / Users/ j ohn. You'll som et im es see it referred t o on t he com m and line as ~ . I t 's a short cut t hat saves you from having t o t ype out your full login nam e when referring t o your hom e direct ory. So ~ / Docum ent s act ually refers t o / Users/ j ohn/ Docum ent s ( Macint osh HD
Users
j ohn
Docum ent s in t he Finder) .
1.3 Who's the Boss? As t he prim ary user of your com put er, you're aut om at ically afforded adm inist rat ive privileges [ Hack # 50] , which m eans t hat you can inst all j ust about any soft ware, m odify set t ings affect ing how OS X funct ions, and creat e and delet e ot her account s. Needless t o say, if you don't want your kid sist er m essing up your com put er, you shouldn't m ake her an adm inist rat ive user. Give adm inist rat ive access only t o t hose people ( read: account s) t hat t ruly need it .
1.4 Renaming an Account While OS X m akes it easy t o creat e new account s, alt er t heir capabilit ies, or change and delet e t heir passwords, it 's less t han helpful when it com es t o renam ing an account ( i.e., changing it s Short Nam e) . I n fact , t here's sim ply no way t o do so from t he GUI side of t hings. To do so, you'll have t o do som e of t he work on t he com m and line. For exam ple, let 's fix our earlier j ohnj acobj ingleheim erschm idt bungle, renam ing t he account ( a.k.a. Short Nam e) t o j ohn.
First , creat e a brand- new account ( Syst em Preferences Account s New User) . OS X won't allow you t o ent er t he sam e Nam e, so change it slight ly for now; you're always able t o change t he full nam e. As shown in Figure 1- 3, I chose John Jacob Jingleheim er Schm idt I I as a placeholder. For Short Nam e, choose som et hing reasonable. Again, I chose t he m ore sensical j ohn, since I know he'll be t he only John using m y com put er and I don't expect m uch confusion about who's who. Figu r e 1 - 3 . Cr e a t in g a n e w a ccou n t
Next , you'll need t o pull a swit cheroo, giving a copy of j ohnj acobj ingleheim erschidt 's hom e direct ory t o j ohn t o use as his own. Since you'll be m aking a copy rat her t han perm anent ly pulling j ohnj acobj ingleheim erschidt 's hom e direct ory out from underneat h him , you'll be able t o verify t hat all is as it should be before delet ing anyt hing pot ent ially valuable.
Before m oving on, you should m ake sure t hat you have enough hard drive space t o hold bot h copies. Com pare t he size of t he hom e direct ory t o t he am ount of available space on your drive using Get I nfo ( File
Get I nfo) on each.
All of t his m ust be done as t he adm inist rat ive ( or root ) user, as you'll be m anipulat ing files belonging t o t wo ot her account s. I f you have not already done so, enable t he root user [ Hack # 50] and log in as root .
Navigat e in t he Finder t o Macint osh HD
Users.
First , you'll rem ove j ohn's hom e direct ory; don't worry, since it 's brand new, it doesn't cont ain m uch of any wort h. Drag t he j ohn folder t o t he Trash. That out of t he way, duplicat e t he j ohnj acobj ingleheim erschm idt direct ory by Cont rol- clicking it and select ing Duplicat e from t he cont ext m enu, as shown in Figure 1- 4, and renam e it t o j ohn, as shown in Figure 1- 5. Figu r e 1 - 4 . D u plica t in g j oh n j a cobj in gle h e im e r sch m idt 's h om e dir e ct or y
Figu r e 1 - 5 . Re n a m in g t h e copy of j oh n j a cobj in gle h e im e r sch m idt 's dir e ct or y t o j oh n
j ohn and j ohnj acobj ingleheim erschidt now own ident ical hom e direct ories. About t he only bit you don't want t o be ident ical is t he keychain, st ill nam ed j ohnj acobj ingleheim erschm idt in j ohn's new hom e direct ory. Navigat e t o Macint osh HD Users j ohn renam e t he file j ohnj acobj ingleheim erschm idt t o j ohn, as shown in Figure 1- 6.
Library
Keychains and
Figu r e 1 - 6 . Re n a m in g j oh n j a cobj in gle h e im e r sch m id's k e ych a in t o j oh n
Speaking of ownership, while j ohn now has a new hom e direct ory, if you t ook a close look at t he perm issions, you'd see t hat he st ill doesn't act ually own t he direct ory or anyt hing in it — everyt hing's owned by t he root user ( since he request ed t he duplicat ion, he owns t he files) . To fix t he perm issions, launch t he Term inal [ Hack # 48] ( Applicat ions
Ut ilit ies
Term inal) and use t he c h own com m and, like so:
[ Ha ppyMa c : / Us e r s ] r o o t # c h o wn - R j o h n . s t a f f j o h n
[ Ha ppyMa c : / t ot a l 0 dr wxr wx- - dr wxr wxr wt dr wxr - xr - x dr wxr - xr - x j o hnj a c o b j
Us e r s ] r o o t # l s - l 4 3 11 11 i ngl
r oot a d mi n r oot wh e e l j ohn s t af f j ohnj a c o s t a f f e h e i me r s c h mi d t
136 102 374 374
Fe b 6 2 3 : 0 7 J ul 13 2002 Fe b 6 2 3 : 0 8 Fe b 5 1 7 : 4 8
De l e t e d Us e r s Sh a r e d j ohn RETURN
Not ice t hat t he j ohn direct ory is now owned by t he j ohn account and is in t he right ( s t a f f ) group.
You'd t hink you could do t his via t he Get I nfo dialog box. I t does, aft er all, allow you t o change perm issions on a folder and " Apply t o enclosed it em s . . . " , but it j ust doesn't work as expect ed. You can apply som e changes recursively t o t he cont ent s of a folder, but you can't change t he ownership in t his way.
Log out as t he root user and log back in again as yourself. Disable t he root user [ Hack # 50] and you're done. Give t he new j ohn account a t ry by logging in and fiddling about . When you're sure all's as it should be, go ahead and delet e t he old j ohnj acobj ingleheim erschm idt account and alt er j ohn's Nam e ( Syst em Preferences Account s
Edit User) as appropriat e — in t his exam ple, we dropped t he I I bit .
1.5 Deleting an Account Delet ing an account under Mac OS X is sim ple using t he Account s Syst em Preferences panel ( Syst em Preferences Account s
Delet e User) . This will rem ove t he account and disable t he associat ed hom e direct ory.
Delet ed account s, however, are gone but not com plet ely forgot t en. I f you t ake a m om ent t o act ually read t he confirm at ion dialog shown in Figure 1- 7, you'll learn t hat t he cont ent s of t he now- delet ed account 's hom e direct ory are archived as a disk im age in Macint osh HD
Users
Delet ed Users.
Figu r e 1 - 7 . Con fir m in g a ccou n t de le t ion
When and if you're ready t o perm anent ly delet e t he cont ent s of an archived hom e direct ory ( see Figure 1- 8) , sim ply drag it s disk im age t o t he Trash.
Figu r e 1 - 8 . A de le t e d a ccou n t 's a r ch ive d h om e dir e ct or y
[ Team LiB ]
[ Team LiB ] Hack 2 Taking the Bite Out of Backup
W it h a con fu sin g a r r a y of ba ck u p solu t ion s for M a c OS X, w e pick ou t a cou ple of ou r fa vor it e s: Apple 's Ba ck u p a n d t h e ope n sou r ce , Pe r l- ba se d psyn c. Backup is t he bane of anybody's com put er exist ence. You know it 's an int egral part of dat a hygiene — not unlike flossing, in fact . But it 's lat e, you have a present at ion in t he m orning, and you're t oo busy creat ing dat a t o bot her finding a CD or som e ext ra hard drive space t o shove a backup set ont o. Not t hat you'd know what and how t o back up in t he first place. Many of t he available soft ware applicat ions don't work as advert ised, are com plicat ed when t hey shouldn't be, don't rest ore as one would hope during your t im e of need, and are oft en expensive t o boot . Online backup always sounds like a good idea; and it is, for reasonably sized dat a set s, m eaning not m ine and probably yours. Backup proves such a pain t hat you never really t hink about it unt il it 's t oo lat e — again, m uch like flossing. So what 's a dat a hog t o do?
2.1 .Mac's Backup Backup ( ht t p: / / www.m ac.com / 1/ iTour/ t our_backup.ht m l) , .Mac's free personal backup soft ware, has t he sim plicit y you've been craving in a backup applicat ion. I t sport s an int uit ive iApp- st yle int erface and an int elligent QuickPicks feat ure t o help you ident ify im port ant files and locat e t hem on your hard drive for you rat her t han t he hunt - and- peck of lesser backup program s. You can back up t o CD or DVD, even spanning m ult iple CDs or DVDs should your im port ant dat a be j ust t hat m uch. I f you're a .Mac m em ber ( $99.95 per year) , you have 100 m egabyt es of iDisk space ( upgradable up t o 1 gigabyt e for a fee) t hat can be used for rem ot e backup. That 100 m egabyt es isn't m uch and will be gobbled up pret t y quickly if used as your prim ary backup space, but it 's useful for backing up your address book, keychain, I nt ernet Explorer set t ings and favorit es, Quicken financial dat a, and a few ot her vit al files while you're on t he road.
Disappoint ingly, Backup doesn't allow you t o back up t o an int ernal or ext ernal hard drive, m eaning t hat m y 20- gigabyt e ext ernal FireWire sim ply can't be used by t his ut ilit y. Ot t o Moerbeek has a nice hack for running Apple's Backup wit hout a .Mac account ( ht t p: / / www.drij f.net / dot ot t o/ ) .
Backup is also covered in [ Hack # 3] .
2.2 psync
Dan Kogai's psync ( ht t p: / / www.dan.co.j p/ cases/ m acosx/ psync.ht m l) , part of t he MacOSX: : File ( ht t p: / / search. cpan.org/ dist / MacOSX- File/ ) Perl m odule dist ribut ion is a rat her nice, free, open source backup solut ion. I t will back up Mac volum es, synchronize direct ories, and creat e boot able backups but cannot yet m ake an increm ent al backup of only changed files. I t plays nicely wit h j ust about any m edia you t hrow at it , including NFS and Sam ba for rem ot e backup.
2.3 psyncX psyncX ( ht t p: / / sourceforge.net / proj ect s/ psyncx) is an Aqua front end t o t he p s y n c com m and. psyncX's Package I nst aller guides you gent ly t hrough inst allat ion of bot h psyncX and t he underlying psync Perl bit s. I t includes a handy backup scheduler ( see Figure 1- 9) , so you can archive your dat a while you snooze — j ust so long as your com put er isn't asleep as well. Figu r e 1 - 9 . Th e psyn cX Aqu a in t e r fa ce
2.3.1 Backing up I f you forego psyncX's GUI int erface and would rat her run psync from t he com m and line or regularly out of c r o n [ Hack # 53] , go ahead and st art up t he Term inal [ Hack # 48] . Run t he ps yn c com m and specifying a source direct ory t o back up and a dest inat ion direct ory for t he backup. Here I back up everyt hing in m y Docum ent s direct ory t o m y FireWire drive:
% p s ync ~/ Do c u me n t s / Vo l u me s / Fi r e The dest inat ion direct ory should be on anot her disk or at least anot her part it ion; ot herwise, it won't do m uch good if t he original part it ion or drive goes under. To back up anyt hing but your own hom e direct ory, you need superuser privileges [ Hack # 50] ; aft er all, you can't
back up what you don't have perm ission t o access. Use t he s u com m and t o t em porarily ( for t his com m and only) becom e t he superuser. For exam ple, t he following backs up everyt hing on t he local drive ( t he / direct ory and below) t o anot her m ount ed volum e, / Volum es/ BackupDisk:
% s udo ps y n c / / Vo l u me s / Ba c k u p Di s k By t he t im e you next back up t he sam e source direct ory t o t he sam e dest inat ion direct ory, you m ay well have rem oved som e of t he original files — t hat proj ect was over and you want ed t o be rid of all t races of it . I f you really don't want t hem in your backup direct ory, t ell psync t o delet e t hose files t hat exist in t he dest inat ion but not in t he source, using t he - d swit ch like so:
% p s ync - d ~/ Do c u me n t s / Pr o j e c t s / Vo l u me s / Fi r e 2.3.2 Testing backup To t est psync t o m ake sure it does t he right t hing wit hout act ually copying any files, use t he - n swit ch t o t urn on sim ulat ion m ode. The p s y n c com m and report s what it would have done, but does not hing ot herwise.
% s udo ps y n c - n / / Vo l u me s / Ba c k u p Di s k 2.3.3 Remote backup To back up t o a filesyst em ot her t han a m ount ed hard drive, use t he - r swit ch t o t urn on rem ot e backup m ode:
% p s ync - r ~/ Do c u me n t s / Vo l u me s / Wi n d o ws _ Sh a r e Since rem ot e filesyst em s do not behave in quit e t he sam e m anner as a local hard drive, psync st ores som e ext ra inform at ion in a file called .psync.db.
2.3.4 Restoring from backup To rest ore your dat a, sim ply reverse t he source and dest inat ion direct ories — you're only synchronizing/ copying, aft er all. The p s y n c com m and aut om at ically t urns int o rem ot e rest ore m ode if it finds t he .psync.db file in t he source direct ory, and allows it t o rest ore file ownership and perm issions.
2.4 See Also ●
●
Ret rospect Express Backup ( available at ht t p: / / www.dant z.com / index.php3?SCREEN= reb_m ac) ( $49) is probably t he m ost well respect ed com m ercial backup solut ion for Macint osh. [ Hack # 60]
—brian d foy
[ Team LiB ]
[ Team LiB ] Hack 3 Backing Up on the Go
Com bin in g .M a c se r vice s w it h 8 0 2 .1 1 b con n e ct ivit y pr ovide s som e vit a l pr ot e ct ion for cu r r e n t pr oj e ct s w h ile on t h e r oa d. Generally speaking, I 'm pret t y good about backing up m y PowerBook dat a. But som et im es a few days go by bet ween sessions. I used t o t hink t hat such a span was accept able, but t hese days, when every hour of work is as precious as gold, I 'm ret hinking m y old habit s. I don't want t o replace m y exist ing syst em . I like it . What I really want t o do is add t he capabilit y t o t em porarily back up work files t o prot ect m e bet ween archiving sessions. As I was m ulling over t his sit uat ion, I not iced a nice convergence of t echnologies t hat present ed m e wit h a solut ion.
3.1 Backup as Part of .Mac Membership Aft er I upgraded m y .Mac m em bership, I t ook a look at t he new t ools available. At t his point , t he one t hat int erest s m e t he m ost is t he Backup ( ht t p: / / www.m ac.com / ) applicat ion. Clearly, I didn't see t his as a t ot al solut ion t o m y archiving needs, especially wit h a m easly 100MB iDisk, but I t hought t hat Backup had som e pot ent ial as a t em porary cont ainer for m y work in progress. The appealing aspect of t his new applicat ion is t hat I can designat e part icular folders on m y hard drive t o be copied t o m y iDisk whenever I have a net work connect ion. At t he end of each work session, for exam ple, I sim ply click t he Backup Now but t on, and t he lat est version of m y designat ed files is copied t o m y iDisk ( see Figure 110) . That m eans inst ead of risking 24 hours or m ore bet ween archiving sessions, I 'm const ant ly saving m y m ost im port ant docum ent s m any t im es a day. Figu r e 1 - 1 0 . Ba ck u p
The log files for Backup are very accessible and help m e keep t rack of t he success of m y sessions. I recom m end t hat you use t he Show Toolbar view of Backup, enabling you t o access your log files direct ly from t he m ain int erface. Also, t o keep t his syst em as efficient as possible, don't designat e t oo m any it em s t o back up — your sessions will run t oo long and defeat t he purpose of having an easy- t o- use safet y net during t he course of your workday. For t he m ost part , t he applicat ion's behavior has been st eady. Every now and t hen I get a st range pop- up not ice t hat I need t o j oin .Mac t o use Backup. I j ust click t he Quit but t on, and Backup cont inues t o go about it s business unint errupt ed. I f you want t o rest ore a file — in ot her words, copy it from your iDisk back t o your com put er — sim ply select Rest ore from iDisk from t he View m enu. Backup will ask you if you're sure you want t o replace your exist ing file wit h t he iDisk version before copying it t o your hard drive. This funct ion worked well in m y t est ing.
3.2 AirPort, Unwiring Backup More and m ore I 'm writ ing out side of t he office or hom e. Travel m eans t hat I find m yself working on docum ent s in St arbucks, airport s, and ot her rem ot e locat ions. Since I 'm using a lapt op, I 've been concerned about prot ect ing m y work while I 'm away from t he auxiliary FireWire drive I use at hom e for archiving. Fort unat ely, 802.11b net works are appearing everywhere. For exam ple, St arbucks has cont ract ed wit h T Mobile Hot Spot ( ht t p: / / www.t - m obile.com / hot spot / ) t o provide wireless I nt ernet access in m ost of t heir U.S. locat ions. You can sign up ( wit hout a cont ract ) and use t he service for $2.99 for a 15- m inut e session, which is m ore t han enough t im e t o check your em ail and run Backup. I f you want m ore t im e, you can sign up for a m ont hly program t oo. This t ype of connect ivit y changes everyt hing. I f I 'm on t he road working on a proj ect for an hour in St arbucks, t hen as soon as I finish sipping m y t all Am ericano, I can run Backup and send updat es of all t he changed files t o m y iDisk drive, and t hat includes new browser bookm arks and scrapbook pages. Heaven forbid if m y PowerBook ever suffered an ill fat e while on t he go, but if so, I won't lose a single hour of
work as a result .
3.3 Using Other Media Too You can use Backup t o save t o CDs also, which does have som e m erit for larger archiving sessions. For m y purposes on t he road, I 'm not as int erest ed in t his feat ure, because if I lose m y lapt op, chances are t hat t he CDs in t he case are gone t oo. Obviously, CD archives offer som e prot ect ion from hard- drive failure. But for t he m ost part , I t hink m y exist ing archiving syst em covers t hat base j ust fine.
3.4 The Cost of Protection This nift y syst em I 've discussed is flexible and, so far, has proved reliable. But it 's a convenience t hat com es wit h a price t ag. The upgrade t o m y .Mac m em bership was $49 ( annual fee) , and next year I 'll have t o pay t he full $99. Wireless access on t he road runs from $2.99 a session t o as m uch as $10, depending on t he service you use. Every now and t hen you m ay happen upon a free access point , but generally speaking, you should be prepared t o pony up a few bucks for t he connect ion.
3.5 Final Thoughts The individual t echnologies are not groundbreaking in and of t hem selves, but what I find int erest ing is t hat I can st ring t hese services t oget her t o fill a need. These days, t he t hought of losing even one hour of product ive work is disheart ening. Now, by com bining .Mac services wit h 802.11b connect ivit y, I 'll keep m y proj ect s safe, even when I 'm on t he road. —Derrick St ory
[ Team LiB ]
[ Team LiB ] Hack 4 Dealing with Archives of Many Colors: .img, .sit, .tar, .gz
Ba ck in t h e in n oce n t da ys of OS 9 , on e com pr e ssion for m a t r e ign e d su pr e m e : St u ffit fr om Ala ddin Syst e m s. W it h OS X a n d it s BSD Un ix fou n da t ion , t h e r e 's a w h ole sle w of com pr e ssion t e ch n ologie s a va ila ble , a ll bu ilt in t o you r de fa u lt in st a lla t ion . St uffit Expander, DropSt uff, and t heir Aladdin ilk have long been st alwart s of t he Mac OS, included on Apple CDs and preinst alled m achines. The sam e can be said for Unix ut ilit ies like gzip, bzip2, and com press, also included wit h OS X and available t hrough t he Term inal. Throw in Apple's disk- im age t echnology, which creat es archives t hat look and act like rem ovable disks, and you've got a verit able cornucopia of com pression and archival t echnologies.
4.1 .dmg and .img Apple has been providing disk im age t echnology in t he shape of it s Disk Copy ut ilit y for years now. Creat ing a disk im age is a m indless t ask — sim ply open Disk Copy, drag a folder over t he float ing window ( see Figure 1- 11) , decide if you want encrypt ion, and choose where t o save t he result ant file ( see Figure 1- 12) . Figu r e 1 - 1 1 . D r a ggin g a folde r in t o D isk Copy
Figu r e 1 - 1 2 . Se t t in g I m a ge Folde r opt ion s
Creat ing im age files, however, doesn't offer m uch com pression, and you'll see a lot of dm g.gz ext ensions on your new downloads. That leads us int o gzip and t ar. gzip is as m uch of a Unix st andard as St uffit has been for t he Mac. By it self, it 's only a com pression ut ilit y — it doesn't bundle and archive m ult iple files like Aladdin's DropSt uff ( also included in OS X) . For t hat abilit y, it 's m ost oft en com bined wit h anot her ut ilit y called t ar or wit h t he generat ed disk im ages from Apple's Disk Copy. I f you want t o com press a .dm g file you've j ust creat ed, you'd j um p int o t he Term inal [ Hack # 48] :
gz i p - 9 f i l e na me . d mg This com m and will aut om at ically com press filenam e.dm g int o filenam e.dm g.gz, at m axim um com pression. I f we don't include t he - 9 , t hen gzip will finish slight ly fast er, but at t he expense of a slight ly larger file size ( - 6 is t he default ) . Alt ernat ively, if we're going t o use t ar ( very com m on when it com es t o Unix downloads) , we could bundle up our ent ire ~ / Docum ent s direct ory t his way:
t a r - c vf f i l e na me . t a r ~/ Do c u me n t s The c is t o creat e a new archive, t he v is t o keep us inform ed of it s progress, and f indicat es t he nam e of t he final archive — in t his case, filenam e.t ar. Finally, we indicat e what we want t o archive, which is ~ / Docum ent s. We could easily archive m ore direct ories ( or individual files) by adding t hem aft er our init ial ~ / Docum ent s. Unlike gzip, t ar only archives t he files — it com presses not hing it self, m uch like Apple's Disk Copy. To com press our new filenam e.t ar, we'd used gzip as shown earlier. Because t ar and gzip are so oft en int ert wined, we can com bine t wo com m ands int o one:
t a r - c vz f f i l e n a me . t a r . g z ~/ Do c u me n t s Not ice t hat we've added a z flag, which t ells t ar t o aut om at ically com press t he final archive wit h gzip. We've also changed our final filenam e t o reflect it s com pressed st at us. More inform at ion about bot h of t hese ut ilit ies can be accessed from your Term inal wit h ma n g z i p and ma n t a r .
4.2 bzip2
Whereas gzip uses a com pression t echnique called Lem pel- Ziv, bzip2 t akes a different approach wit h t he BurrowsWheeler block- sort ing t ext - com pression algorit hm . I t 's a lit t le slower com pressing t han gzip, but it oft en ret urns a sm aller file size ( see Table 1- 1 at t he end of t his hack) . I t s use ( and com binat ion wit h t ar) is sim ilar t o gzip, always preferring m axim um com pression:
t a r - c vf f i l e na me . t a r ~/ Do c u me n t s bz i p2 f i l e na me . t a r 4.3 Other Compression Techniques While gzip is m ore popular t han bzip2 for Unix downloads, bzip2 has been m aking headway due t o it s st ronger com pression. St uffit Expander can readily ext ract eit her form at . St ill m ore com pression flavors exist , however. I 've briefly out lined t heir usage here — you can find m ore inform at ion about t heir usage and specific abilit ies by t yping ma n c o mp r e s s , ma n z i p , or ma n j a r in your Term inal.
# u s i ng t h e c o mp r e s s u t i l i t y t a r - c vf f i l e na me . t a r ~/ Do c u me n t s c o mpr e s s f i l e na me . t a r # t he s a me a s p r e v i o u s t a r - c vZf f i l e na me . t a r . Z ~/ Do c u me n t s # n ow, z i p a t ma x i mu m c o mp r e s s i o n z i p - r - 9 f i l e na me . z i p ~/ Do c u me n t s # a nd j a r ( u s e f u l f o r J a v a a p p l i c a t i o n s ) j a r c f f i l e na me . z i p ~/ Do c u me n t s 4.4 Don't Forget Stuffit Aladdin Syst em s realized t here would be a need for a sim ple drag and drop ut ilit y t hat could com press in ot her form at s besides it s own — t hat 's why you'll see DropTar and DropZip ut ilit ies in your / Applicat ions/ Ut ilit ies/ St uffit Lit e ( or St uffit St andard) direct ory. Using t hese is as you'd expect — sim ply drag and drop t he files and folders you want t o archive over it s icon ( or drag t o it s window) , and you're set . DropTar even has t he capabilit y t o com press in m ult iple form at s: bzip2, com press, gzip, and t he nat ive St uffit form at . I n Table 1- 1, we've com pressed a 100MB direct ory using each of t he ut ilit ies, wit h m axim um com pression. I f you're looking for t he sm allest file, t hen bzip2 should be your first choice, but gzip could be m ore com pat ible wit h every com put er your archive lands on ( if you're worried only about OS X, t hen bzip2 is a good bet ) . Be forewarned: t he t ypes of files you're archiving will give you different result s wit h each ut ilit y — t he source direct ory in t his case was filled wit h an equal am ount of t ext , im age, and binary files, but you'll not ice fluct uat ing result s wit h large t ext files, m ult iple t iny files, and so on.
Ta ble 1 - 1 . Com pr e ssion t e ch n iqu e s a n d r e su lt in g file size s Com pr e ssion t e ch n iqu e
File size ( in byt e s)
com press
45,264,549
DropTar ( com press)
45,032,503
j ar
30,322,992
zip
30,232,529
DropTar ( gzip)
30,069,414
gzip
30,042,941
DropZip
29,877,021
DropTar ( bzip2)
26,072,415
bzip2
25,825,723
[ Team LiB ]
[ Team LiB ] Hack 5 A Line Break Is a Line Break
A lin e br e a k is a lin e br e a k is a lin e br e a k , e x ce pt w h e n it 's n ot . Su r pr isin gly, t h e r e a r e t h r e e diffe r e n t t ype s of lin e br e a k s in t h e m ode r n com pu t in g w or ld, a n d OS X u se s t w o of t h e t h r e e . One m ight t hink t he innocent line break, t hat docile whit espace t hat t ells us when paragraphs begin and end, would be a relat ively sim ple piece of com put er engineering. Unfort unat ely, t here's m ore t o t he line break t han m eet s t he eye. There are t hree different t ypes of line breaks, all originally unique t o t he m aj or operat ing syst em s: Windows/ DOS, Macint osh, and Unix. A docum ent using Mac line breaks would look horrid on a Windows syst em , and a docum ent using Windows line breaks on Unix also wouldn't be int erpret ed correct ly. The cause for t his is how t he line break is act ually creat ed. The Mac, by default , uses a single carriage ret urn ( ) , represent ed as \ r . Unix, on t he ot her hand, uses a single linefeed ( ) , \ n . Windows goes one st ep furt her and uses bot h, creat ing a ( ) com binat ion, \ r \ n . To m ake m at t ers st ill m ore int erest ing, unt il OS X cam e along, OS- specific line breaks st ayed in t heir own environm ent and didn't play nicely wit h ot hers. Windows underst ood only it s bret hren, Unix cackled m adly at anyt hing else, and t he Mac j ust grinned knowingly. OS X, however, underst ands bot h t he original Mac line break and Unix line breaks. This can cause confusion very easily, especially considering t hat m ost Mac applicat ions ( i.e., m ost anyt hing t hat runs t hrough t he GUI of OS X) read and save using Mac- st yle line breaks, while anyt hing used t hrough t he Term inal ( like t he com m on t ext edit ors [ Hack # 51] : vi, pico, and Em acs) enforces t he Unix variet y. Thankfully, it 's pret t y easy t o solve problem s caused by t his dual m ent alit y. The first st ep is ident ifying t hat you have an issue. Say you have a t ext file you saved wit h Sim pleText or a default inst allat ion of BBEdit . I f you t ry t o open t hat file in a shell edit or like vi, you'll see t his inst ead of what you'd expect :
Th i s s hou l d b e l i n e o n e . ^ MTh i s s h o u l d b e o n l i n e t wo . See t hat ugly ^ M charact er st uck in t he m iddle of our t wo sent ences? That 's t he best vi ( and m ost Unix applicat ions) can do in an at t em pt t o display a Mac linefeed. Likewise, if you open a t ext file craft ed in vi wit h Sim pleText , you'll see square boxes where t here should be line breaks. Obviously, t his wreaks havoc wit h any at t em pt at poet ry — or syst em adm inist rat ion, for t hat m at t er. There are a few solut ions, depending on your skills and desires. The m ost obvious is t o change your t ext edit or t o m at ch what you'll be needing m ost frequent ly. I f you're const ant ly going t o be writ ing files t hat will be used in t he shell, t hen set your t ext edit or t o save as Unix linefeeds. A m ust - have edit or, BBEdit ( ht t p: / / www.barebones. com / ) from Bare Bones Soft ware, allows you t o do t his quit e easily, bot h on a file- by- file basis ( see Figure 1- 13) and globally t hrough BBEdit 's ult raconfigurable preferences ( see Figure 1- 14) . Figu r e 1 - 1 3 . Se le ct in g a lin e fe e d st yle in BBEdit
Figu r e 1 - 1 4 . Se t t in g de fa u lt lin e fe e d st yle in BBEdit pr e fe r e n ce s
I f Term inal- based t ext edit ors are m ore your cup of t ea, a st ronger version of vi called vim ( for vi, im proved) is flexible and infinit ely configurable when it com es t o edit ing files of varying form at s. ht t p: / / vim .sourceforge.net / ht m ldoc/ usr_23.ht m l provides m ore t han enough det ail on choosing your own line break. I f you want a less perm anent opt ion, a single com m and line can save you som e hassle. Here, we've list ed t wo sim ple Perl one- liners. The first t ranslat es Mac linefeeds t o t heir Unix equivalent , and t he second does t he reverse. You'll not ice t hat t he linefeeds are represent ed by t he sam e charact ers we m ent ioned before:
pe r l - pi - e ' s / \ r / \ n / g ' pe r l - pi - e ' s / \ n / \ r / g '
f i l e _wi t h_ma c _ l i n e f e e d s . t x t f i l e _wi t h_un i x _ l i ne f e e ds . t x t
On t he flip side, if you ever run across a file wit h Windows linefeeds, you can easily convert t hem t o your preferred form at wit h t he following exam ples:
pe r l - pi - e ' s / \ r \ n / \ n / g ' pe r l - pi - e ' s / \ r \ n / \ r / g '
f i l e _ wi t h _ wi n _ l i n e f e e d s . t x t f i l e _ wi t h _ wi n _ l i n e f e e d s . t x t
Using t he exam ples present ed in t his hack, you'll be able t o piece t oget her t he code needed t o convert t o Windows linefeeds from eit her Mac or Unix.
[ Team LiB ]
[ Team LiB ] Hack 6 Fiddling with Type/Creator Codes and File Extensions
M a c OS X u se s a com bin a t ion of t ype a n d cr e a t or code s a n d file e x t e n sion s t o de t e r m in e t h e a pplica t ion w it h w h ich a file is a ssocia t e d. Every file in OS X and earlier versions of t he Mac OS usually have bot h a t ype and creat or at t ribut e t hat help det erm ine which applicat ion should open t hem . For exam ple, a .ht m l file m ay have a t ype and creat or t hat say it should be opened in Microsoft 's I nt ernet Explorer, while a .m ov file would have different at t ribut es t hat suggest it should be opened by QuickTim e. Files also have ot her at t ribut es, like st at ionary, locked or unlocked, and t im ely inform at ion like creat ion and m odificat ion dat es. Unlike Windows, however, a Mac file doesn't need an ext ension t o det erm ine associat ion wit h an applicat ion. A file nam ed webcam could be a JPEG im age, a t ext file t o be opened by BBEdit , or even an HTML file associat ed wit h I nt ernet Explorer. The t ype and creat or codes rise above pet t y nam ing dist inct ions. Norm ally, you'd need special soft ware t o set or change t hese t ypes and creat ors, m aking t he t ask m ore difficult ( or expensive) t han you'd hope. Longt im e users of t he Mac OS would oft en use t he venerable ResEdit t o perform t he dirt y deed, perhaps also t weaking ot her applicat ion st rings in a fit of m irt h and because t hey're t here. Thankfully, if you've inst alled Apple's Developer Tools, you can do t his easily wit h t he Term inal [ Hack # 48] . The easiest way t o change a file's t ype and creat or codes is t o find a file you want t o m im ic and use it s t ype and creat or codes as a guide for your changes. For exam ple, if you had a copy of Apple's hom e page ( ht t p: / / www. apple.com ) saved as an HTML file nam ed Apple Hom e.ht m l, you'd ent er t he following int o a Term inal [ Hack # 48] window t o find it s t ype and creat or:
% / De ve l o p e r / To o l s / Ge t Fi l e I n f o " Ap p l e Ho me . h t ml " The out put would look som et hing like t his:
f i l e : " Ap p l e Ho me . h t ml " t y p e : " TEXT" c r e a t or : " MSI E" a t t r i but e s : a v b s t c l i n me d c r e a t e d: 0 8 / 0 8 / 2 0 0 2 1 9 : 1 2 : 4 6 mo d i f i e d: 0 8 / 0 8 / 2 0 0 2 1 9 : 1 2 : 4 6 Wit h t his, we know t hat a file associat ed wit h I nt ernet Explorer needs t o have a t ype of TEXT and a creat or of MSI E. I f you check ot her files, you'll not ice t hat t ypes and creat ors are always four let t ers in lengt h, oft en creat ing ungodly com binat ions of whim sy, like DBSE and FTCH, which have not hing t o do wit h what you m ight t hink t hey do ( an Ext ensis Port folio dat abase) . To associat e som e ot her file wit h I nt ernet Explorer, you'd ent er t he following:
% / De ve l o p e r / To o l s / Se t Fi l e - c MSI E - t TEXT s o me _ o t he r _ f i l e Because Mac OS X has a Unix underlayer, som e files ut ilized by t he Unix side of t hings m ay have no t ype and creat or. Ge t Fi l e I n f o , in t hose cases, would show blank values for t hose fields:
% / De ve l o p e r / To o l s / Ge t Fi l e I n f o / u s r / b i n / v i f i l e : " / us r / bi n/ vi " t ype : " " c r e a t or : " " a t t r i but e s : a v b s t c l i n me d c r e a t e d: 1 1 / 1 1 / 2 0 0 2 1 8 : 2 8 : 5 6 mo d i f i e d: 1 1 / 1 1 / 2 0 0 2 1 8 : 2 8 : 5 6 What 's int erest ing is how a file wit h no associat ed t ype or creat or codes m ight st ill be associat ed and opened wit h a part icular applicat ion. Take, for exam ple, an archived copy of t he source code for Perl 5.8, freshly downloaded off t he Net :
% / De ve l o p e r / To o l s / Ge t Fi l e I n f o p e r l - 5 . 8 . 0 . t a r . g z f i l e : " pe r l - 5 . 8 . 0 . t a r . g z " t ype : " " c r e a t or : " " Wit h no file t ype and creat or, you m ay be confounded by t he fact t hat t ar.gz is nonet heless associat ed wit h St uffit Expander when you look at it from t he Finder's point of view, as shown in Figure 1- 15. Figu r e 1 - 1 5 . t a r .gz is a ssocia t e d w it h St u ffit Ex pa n de r
The reasoning is sim ple: if a file has t ype and creat or codes, t hey're used. Ot herwise, Mac OS X t akes a look at t he file ext ension — m uch like Windows does — wit h an eye t o figuring out what it belongs wit h. Renam e perl5.8.0.t ar.gz t o j ust perl- 5.8.0 and Mac OS X will be lost ; t he St uffit Expander icon changes im m ediat ely t o a blank sheet . Arm ed wit h an underst anding of set t ing t ypes and creat ors, you can easily fix t his. A gzipped file has a t ype of Gzip and a creat or of SI Tx; alt er t he codes on t he com m and line and all's as expect ed:
% / De ve l o p e r / To o l s / Se t Fi l e - c SI Tx - t Gz i p p e r l - 5 . 8. 0 Wit h t ype and creat or set , you can renam e t hat file t o your heart 's cont ent , appending what ever ext ension you like, and it 'll rem ain associat ed wit h St uffit Expander.
6.1 See Also ●
For det ails on Ge t Fi l e I n f o and Se t Fi l e , at t he Term inal [ Hack # 48] , t ype ma n Ge t Fi l e I n f o and
ma n Se t Fi l e , respect ively.
[ Team LiB ]
[ Team LiB ] Hack 7 Locking and Unlocking Files
For ye a r s, t h e M a cin t osh ope r a t in g syst e m h a s a llow e d you t o lock a file or folde r t o pr ot e ct a ga in st a ccide n t a l de le t ion or m odifica t ion . I n OS X, you h a ve t h a t sa m e a bilit y, e it h e r t h r ou gh t h e Fin de r or t h e sh e ll. I f t here's one t hing t hat friends and fam ily know, it 's how t o find t hat one file you've been spending an inordinat e am ount of t im e on and t hen delet e it in a fit of gleeful innocence. For m any years in Mac OS 9 and earlier, t he first line of defense for t his behavior has been locking a file, m aking sure t hat it can't be changed or delet ed unless it is specifically unlocked. This abilit y rem ains in Mac OS X and applies even t o t he root user ( locked files can't be delet ed wit hout being unlocked first , period) . Longt im e Mac users are fam iliar wit h t he following process for locking a file or direct ory in t he Finder: 1. Select t he file or direct ory you want t o lock. 2. Choose Get I nfo from t he File m enu or press
-I.
3. Place a check in t he Locked checkbox. Eit her of t he following t wo shell com m ands do t he sam e t hing under OS X:
% c hf l a gs u c h g f i l e n a me . t x t % / De ve l o p e r / To o l s / Se t Fi l e - a L f i l e n a me . t x t The c h f l a g s ut ilit y is part of a default OS X inst all and changes t he uc hg flag of a file, represent ing t he im m ut able bit ( lit erally, " t his file is not subj ect t o change" ) . c h f l a gs can be perform ed only by a superuser or t he file's owner. Se t Fi l e is a ut ilit y t hat com es wit h t he Developer Tools and operat es on a file's at t ribut es ( at t ribut es and flags can be considered equivalent ) . I n t his case, you're saying t he locked at t ribut e ( - a L) of t he file should be set . Via t he Finder, you can t ell when a file is locked because it 'll have a padlock icon superim posed over t he lower left of it s norm al icon, as shown in Figure 1- 16. Figu r e 1 - 1 6 . A lock e d file
I n t he Term inal [ Hack # 48] , you can t ype l s - ol ( o t o show t he file flags, and l for long list ing) . Any file wit h t he u c h g flag is locked:
% l s - ol f i l e n a me . t x t - r w- r - - r - - 1 mo r b u s s t a f f u c h g 0 De c 4 0 1 : 0 7 f i l e n a me . t x t Unlocking is a sim ple m at t er of reversal. Eit her uncheck t he locked checkbox in t he file's Get I nfo inspect or or ent er one of t he following shell com m ands:
% c hf l a gs n o u c h g f i l e n a me . t x t % / De ve l o p e r / To o l s / Se t Fi l e - a L f i l e n a me . t x t Not hing really surprising t here. To unset a u c h g or any ot her file flag using t he c hf l a g s ut ilit y, sim ply prefix t he flag nam e wit h n o . When using Se t Fi l e , sim ply reverse t he case of t he at t ribut e let t ers; uppercase let t ers always add t he flag t o t he file, and lowercase let t ers rem ove t he flag.
1.8.1 See Also ●
For det ails on c h f l a g s and Se t Fi l e , at t he Term inal [ Hack # 48] , t ype ma n c hf l a g s and ma n
Se t Fi l e , respect ively.
[ Team LiB ]
[ Team LiB ] Hack 8 Stubborn Trash, Stuck Images, and Jammed CDs
Eve r y so oft e n it t a k e s a lit t le k n ow - h ow t o e m pt y t h e Tr a sh or e j e ct a CD ; le a r n w h e n a n d h ow . There are t im es, rare as t hey m ay be, when OS X goes a lit t le haywire and sim ply won't spit out a CD or DVD, unm ount a disk im age, or em pt y t he Trash. Oft en t hings have a way of sort ing t hem selves wit h a lit t le pat ience, wit h a Finder rest art , by logging out and back in, or ( heaven forbid) by reboot ing your Mac. Som et im es, however, t hat st uck CD/ DVD or im age doesn't budge or t he Trash sim ply refuses t o em pt y.
8.1 Stubborn Trash I t does t he heart good t o do som e occasional housekeeping. One such act ivit y is em pt ying t he Trash folder t o free up m ore disk space for your Mac. This is usually as sim ple as Finder Delet e. Every so oft en, t hough, a file or folder refuses t o leave.
Em pt y Trash . . . or
- Shift -
First a lit t le background on t he m yst ical Trash can. Every file you delet e is m oved int o a folder called .Trash in your hom e direct ory:
% l s - al t o t a l 48 dr wxr - xr - x 2 0 we i me n g l s t a f f 6 8 0 De c 1 4 1 2 : 3 5 . dr wxr wxr - t 8 r o o t wh e e l 2 7 2 De c 1 0 0 9 : 3 0 . . dr wx- - - - - - 6 we i me n g l s t a f f 2 0 4 De c 1 4 1 2 : 5 5 . Tr a s h ... To dip int o t he Trash, sim ply open a Term inal [ Hack # 48] window, navigat e t o t he .Trash direct ory, and list files:
% c d . Tr a s h % l s - al Em pt ying t he Trash is not hing m ore t han delet ing all t he cont ent s of your .Trash folder.
8.1.1 In use Despit e having been placed int o t he Trash, a file m ay st ill be in use by an applicat ion ( see Figure 1- 17) . Figu r e 1 - 1 7 . Tr a sh e d file st ill in u se
The rem edy is t o guess which applicat ion is using it and close t he file or shut down t he applicat ion if you're no longer using it . Try em pt ying t he Trash again and, assum ing t hat was t he problem , it should em pt y wit hout incident . I f you aren't able t o figure out what applicat ion is using t he file and have shut down j ust about anyt hing you can find, launch t he Term inal and use t he f s t a t ( file st at us) com m and t o ascert ain which is t he offending program :
% f s t a t . Tr a s h / f i l e 1 USER CMD PI D we i me ngl La u n c h CFMA 2 0 7 0
FD I NUM MODE SZ| DV R/ W MOUNT NAME 3 0 3 4 7 7 0 8 - r w- r - - r - - 31 9 7 4 r w / . Tr a s h / f i l e 1
Not ice t he PI D ( process I D) of t he applicat ion holding t he file host age. Let 's see what applicat ion t hat corresponds t o by using t he p s ( process st at us) com m and. The - p 2 070 argum ent specifies t he process I D, and - w displays t he first 132 charact ers of t he process nam e rat her t han j ust as m uch as can fit on one Term inal line.
% ps PI D 20 7 0 Ap p l i
- wp 2 0 7 0 TT STAT TI ME COMMAND ?? S 2 3 : 4 7 . 7 7 / Ap p l i c a t i o n s / Mi c r o s o f t Of f i c e X/ Mi c r o s of t Wor d / c a t i o n s / Mi c r o s o f t Of f i c e X/ Mi c r o s o f t Wo r d - p s n_ 0 _ 1 8
There we are! I t 's Microsoft Word. Get it t o release t he file and t ry em pt ying t he Trash again.
8.1.2 Locked Anot her problem t hat crops up occasionally is locked files [ Hack # 7] in t he Trash. While you shouldn't be able t o put a locked file int o t he Trash in t he first place, som et im es one sneaks by. Look in your Trash folder via t he Finder and see if t he offending file is locked ( t he icon is overlaid by a sm all lock) , as shown in Figure 1- 18. Figu r e 1 - 1 8 . A lock e d file
To unlock t he file, select File Get I nfo or press - I for t he File I nfo inspect or ( see Figure 1- 19) . I f t he Locked checkbox is checked, click it t o unlock t he file. Figu r e 1 - 1 9 . A lock e d file
I f t he file refuses t o unlock, t ry one of t he t echniques covered in [ Hack # 7] .
8.1.3 Permissions Anot her possibilit y is t hat a file in your Trash m ay not belong t o you. You'll need t o alt er t he perm issions or t ake ownership [ Hack # 49] of t he file before you're able t o em pt y it from t he Trash.
8.1.4 rm
I t 's st ill t here and refusing t o budge? Try sim ply rem oving t he offending file( s) using t he rm [ Hack # 48] com m and, like so:
% r m ~/ . Tr a s h / f i l e 1 I f t hat has no effect , or if OS X com plains about som et hing else, force it wit h t he - f opt ion:
% r m - f ~/ . Tr a s h / f i l e 1 I f t here's a whole hierarchy of folders and files causing you t rouble, you can recursively delet e all t he files in your Trash using s u d o t o get around perm issions issues, - i t o ask for confirm at ion before delet ing each, and - r t o recurse t hrough t he hierarchy:
% s udo r m - r i ~/ . Tr a s h / * r e move / Us e r s / we i me n g l / . Tr a s h / f i l e 1 ? y
Be forewarned! Most books on Unix will warn you of t he disast rous out com e if you are not careful wit h t he r m - r com binat ion, and I 'm going t o say it again. I m agine t he effect s of inadvert ant ly adding a space like so: s u do r m - r f ~/ . Tr a s h ; you'd rem ove all t he cont ent s of your hom e direct ory. Before delet ing anyt hing, t hink t wice before you hit t he Ret urn key.
8.2 Stuck Image You've pressed - E and dragged t hat m ount ed disk im age t o t he Trash unt il you're blue in t he face, but st ill it won't disappear. No com plaint s, no errors, not hing; it sim ply ignores your every at t em pt t o ej ect it . This is usually one of t hose sit uat ions best cleaned up by a logging out and back in, relaunching t he Finder, or reboot ing. I t 's safer and less likely t o m angle t he dat a on t he disk im age if you avoid resort ing t o brut e force t act ics.
8.3 Jammed CD/DVD CD/ DVD loading and unloading on all recent Macint oshes are done t hrough t he operat ing syst em rat her t han t he physical ej ect but t ons you usually find on ot her syst em s. Windows users are oft en caught looking nervously about for t he CD ej ect but t on — I have t o adm it I 've done so m yself. What t o do if t hat CD/ DVD get s st uck? Your first course of act ion is t o pull out your handy- dandy paper clip, t he t ool of choice for t he Mac generat ion. Oh, you don't have one? Sham e on you! All right , so t here's act ually anot her way t o do it t hat will work, j ust so long as t here's not hing physically wrong wit h t he drive t hat 's keeping it from ej ect ing your CD/ DVD. Launch t he Term inal and use t he d f com m and t o find t he filesyst em I D of your CD/ DVD:
% df - l Fi l e s ys t e m 512- bl oc ks Us e d Av a i l Ca p a c i t y Mo u n t e d o n / d e v/ di s k 0 s 9 1 2 0 0 9 1 2 8 0 3 1 3 4 8 0 3 2 8 8 2 3 1 2 4 8 26% / f de s c 2 2 0 100% / de v
/ d e v/ di s k 1 s 1 s 2
614256
478912
135344
7 7 % / Vo l u me s / A CD
I n m y case, t he CD is m ount ed as d i s k 1 s 1 s 2 . To ej ect t he CD, use t he di s k t o o l ut ilit y, handing it t he filesyst em I D:
% d i s kt oo l - e d i s k 1 s 1 s 2 di s k1s 1s 2 d e v i c e wi l l a t t e mp t t ** * Not i f i c a t i o n s Co mp l e t e f o r t ** * Di s k Un mo u n t e d ( ' d i s k 1 ' ) ** * Di s k Un mo u n t e d ( ' d i s k 1 s 1 s 1 ' ) ** * Di s k Un mo u n t e d ( ' d i s k 1 s 1 ' ) ** * Re s pon d i n g y e s t o u n mo u n t ** * Di s k Un mo u n t e d ( ' d i s k 1 s 1 s 2 ' ) ** * Re s pon d i n g y e s t o e j e c t - d i ** * Re s pon d i n g y e s t o e j e c t - d i ** * Re s pon d i n g y e s t o e j e c t - d i ** * Re s pon d i n g y e s t o e j e c t - d i ** * Di s k Ej e c t e d ( ' d i s k 1 ' ) ** * Di s k Ej e c t e d ( ' d i s k 1 s 1 s 1 ' ) ** * Di s k Ej e c t e d ( ' d i s k 1 s 1 s 2 ' ) Your CD/ DVD should pop right out . —Wei- Meng Lee and Rael Dornfest
[ Team LiB ]
o be e j e c t e d . . . ype 1
di s k1s 1s 2 s k1 s k1s 1s 1 s k1s 1s 2 s k1s 1
[ Team LiB ] Hack 9 Aliases, Symlinks, and Hard Links
Pok in g a bou t w it h a lia se s, sym lin k s, a n d h a r d lin k s r e ve a ls som e in t e r e st in g e n t a n gle m e n t s in t h e m e r gin g of t h e M a c GUI a n d it s Un ix u n de r pin n in gs. Aliases ( short cut s, if you're from t he Windows world) are indispensable for t hose of us who insist upon filing t hings in m ore t han one place or like t o have access t o part icular groupings of applicat ions, files, and what not wit hin easy reach. An alias provides a t rail of bread crum bs t o t he original it em aliased, keeping t rack of it no m at t er where it m ight reside. I t was com m on in OS 9 t o add aliases for your oft - used applicat ions and folders eit her right on t he deskt op or in t he Apple m enu, or, indeed, bot h. Now, t hanks t o t he Dock and som e Dock alt ernat ives [ Hack # 51] , t here's lit t le need t o clut t er your Apple m enu or Deskt op wit h aliases. That 's not t o say t hat OS X doesn't have aliases; it does indeed. Sim ply select a file, folder, applicat ion, or what not and select File current window inst ead) .
Make Alias or press
- L ( in OS 9 it was
- M, which now, sadly, m inim izes t he
OS X being a hybrid of t he Mac and Unix worlds causes som e int erest ing ent anglem ent s when it com es t o keeping t rack of t he locat ions of t hings and t heir aliases. Mac OS X does a seam less j ob of glossing over t he det ails. That doesn't m ean, however, it 's not wort h poking about a bit . The Unix world's aliases — act ually called links — com e in t wo flavors: hard and soft ( sym bolic) . Wit h a hard link, t wo or m ore filenam es point t o t he sam e dat a on disk; t hink m y house, our house, and t he house where I live. A sym bolic link ( a.k.a. soft link or sym link) is a different file from t he original, holding not hing but a link t o t he original's filenam e; t hink address book, signpost , or bank account num ber. Rem ove one of t wo hard links and your dat a st ill exist s. Rem ove t he last rem aining hard link and a sym link doesn't do you a bit of good, holding no real dat a it self. The l n com m and creat es and alt ers links on t he com m and line via t he Term inal [ Hack # 48] . Figure 1- 20 shows m e creat ing a file, original, t hen hard linking, and sym linking t o it . Not e t hat t he original alias was creat ed on t he deskt op via t he Finder's Make Alias opt ion. Figu r e 1 - 2 0 . Cr e a t in g a n a lia s on t h e com m a n d lin e
As t he I nfo box shows, OS X sees no difference bet ween a sym link creat ed on t he com m and line and an alias creat ed via t he Make Alias com m and. However, from t he com m and- line point of view, t his is not t he case; t he original alias is an ent irely different file. Edit it and you'll find you've not t ouched t he original, nor does it have any effect on t he GUI view of t he original alias it self at all. Mac OS X appears t o care only about knowing it 's an alias from t he GUI side, leaving t he Unix side t o t reat it as a regular file. Touching t he original ( t o u c h o r i g i n a l ) again t o alt er it s t im est am p affect s only t he original and hard link as expect ed, since t hey are indeed t he sam e file.
[ Team LiB ]
[ Team LiB ] Hack 10 Recent Filenames
M a c OS X h a s som e t r ick y w a ys of r e m e m be r in g w h ich file s w e r e u se d r e ce n t ly. Did you know t hat OS X applicat ions don't act ually rem em ber t he nam es of recent files you've opened? That 's not t o say t hat t hey don't recall what you've been edit ing; aft er all, Op e n Re c e n t does work rat her nicely. What t he applicat ion rem em bers is t he locat ion of t he file on disk. Renam e t hat file. Change it s file ext ension. Move it som ewhere else ent irely. Just as long as it 's st ill on t he sam e disk ( inodes don't t ransfer from disk t o disk) , your app should be able t o find it t he next t im e you choose Open Recent . Just how t his is im plem ent ed varies from applicat ion t o applicat ion. St art ing wit h a file called som efile.t xt on m y Deskt op, I did a lit t le experim ent ing. Move, renam e, and t am per wit h it as I m ight , BBEdit cont inued t o list it as Hard Drive: Users: rael: Deskt op: som efile.t xt . Preview not iced a renam e of som efile.t iff t o som eot herfile.t iff. Microsoft Word, like BBEdit , insist ed som efile.doc was st ill som efile.doc, despit e it s being renam ed som eot herfile. doc and m oved elsewhere. Why's t his useful? Let 's say you've creat ed a m arvelous piece of poet ry, saved it t o t he Deskt op in a hurry as your plane lands, lat er renam ed it t o som et hing m ore appropriat e t han Unt it led1.doc, and m oved it som ewhere or ot her. Sure, Sherlock m ay be able t o find it if you search by cont ent , dat e changed, or docum ent t ype. Or you could sim ply relaunch t he app you believe you were using at t he t im e, select it from t he list of recent files, and you're off t o t he races.
[ Team LiB ]
[ Team LiB ] Hack 11 Inspecting the Contents of an .app Package
I f you w e r e a n OS 9 fiddle r , t w e a k e r , or de via n t , t h e r e w a s on e pie ce of soft w a r e you sim ply h a d t o h a ve : Re sEdit , Apple 's ve n e r a ble , u n su ppor t e d, u se - a t - you r - ow n r isk u t ilit y. Re sEdit is n o lon ge r a pplica ble u n de r OS X, bu t pa ck a ge e dit in g is. I n earlier versions of t he Mac OS, files could have dat a forks and resource forks. The dat a fork was t he gooey inside, and t he resource fork was t he fluffy out side — whet her it be im age t hum bnails, saved edit ing dat a from applicat ions like BBEdit , or applicat ion widget s, like window layout s, user int erface im ages, and so fort h. Wit h Apple's ResEdit , you could easily access t his resource fork and change t he fluff — it wasn't easily possible t o change t he coding of an applicat ion, but it was cert ainly m indless t o change int erface elem ent s. I n OS X, wit h it s grounding in t he BSD operat ing syst em , resource forks are rarely used for applicat ions, effect ively m aking ResEdit useless. I nst ead, we've got packages or, less j argony, files t hat end in .app. You've got .app files spread all over your OS X syst em already — you j ust m ay not know it . Take, for inst ance, Apple's popular Mail program . I t sit s innocent ly in your Applicat ions folder, act ing as if it were a single file. I nst ead, it 's really called Mail.app; t he .app is hidden from view ( you can confirm it s exist ence by exam ining t he Get I nfo propert ies) . The m agic of t hese .app files is t hat t hey're really a special kind of folder called a package; t hey cont ain a good port ion of t he sam e fluff available in an OS 9 applicat ion's resource fork. Even bet t er, you don't need an ext ra ut ilit y like ResEdit t o st art fiddling; sim ply Cont rol- click on a file you know is an .app and choose Show Package Cont ent s, as shown in Figure 1- 21. Figu r e 1 - 2 1 . Re ve a lin g pa ck a ge con t e n t s via Con t r ol- click con t e x t m e n u
Once inside t he package Cont ent s folder, you'll see a subfolder called Resources ( see Figure 1- 22) . I f you needed yet anot her hint t hat t his is sim ilar t o ResEdit hacking, t hen t his nam ing choice is it . I n t he case of Apple's Mail, we can see a decent num ber of im age files, represent at ive of various visual elem ent s you see during norm al use of Mail, as well as a few .plist , .t oolbar, and .nib files. Figu r e 1 - 2 2 . Pa ck a ge r e sou r ce s
The .t iff and .icns files are obvious; m odify t hem in your preferred graphic edit or, rest art Mail, and you'll see your changes. .plist files are t he equivalent of preferences; t here are usually front ends t o t hese set t ings via t he program it self ( not always t hough — in Mail's case, you can edit urlPrefixes.plist t o add m ore clickable bit s of t ext in m ail m essages, or Colors.plist t o edit t wo m ore levels of quot e coloring) . The .nib and .st ring files, locat ed under English.lproj for English- speaking users, are where you can find som e user- int erface aspect s of t he program in quest ion. You won't see t hese for every package you open ( like iTunes) , but in t he case of Mail, you can go nut s edit ing warning m essages, like t his one in Prefs.st rings ( perhaps t o t he m ore ferocious " Ya Screwed Up, I diot ! " ) :
/ * Ti t l e o f p a n e l s h o wn wh e n t h e u s e r t r i e s t o e n t e r a n e mp t y h os t n a me f o r a n a c c o u nt * / " I NVALI D_ SMTP_ HOST_ TI TLE" = " I n v a l i d SMTP Ho s t n a me " ; On t he ot her hand, if you know your way around Apple's I nt erface Builder ( available if you have t he Apple Developer Tools [ Hack # 55] inst alled) , you can open up one of t he m any .nib files and furt her t weak display elem ent s. As wit h t he t ypical warnings when using ResEdit , be sure t o m ake a backup before doing anyt hing m ore t han exploring ( and exploring is when t he best discoveries are m ade, like t he abilit y t o peel t he annoying chrom e [ Hack # 47] from a shiny iApp, add new boards and pieces t o Chess, or change t he default search engine in I nt ernet Explorer) .
[ Team LiB ]
[ Team LiB ] Hack 12 Opening Microsoft Word Documents Without Microsoft Word
Th e t e x t of a n y M icr osoft W or d docu m e n t is r e a da ble w it h t h e gr e a t e st of e a se t h a n k s t o a t in y, fr e e u t ilit y a n d a lit t le ope n sou r ce k n ow - h ow . You open an innocent em ail from som e long- lost relat ive, and she's sent you a vit ally im port ant docum ent . " Open now! " t he em ail shout s, com ical in it s at t em pt t o disguise t he friendly spam it really is. Even worse, t he at t achm ent is a Microsoft Word docum ent , and you've yet t o pony up t he dough for Office under OS X. How do you read it ? Run out and get som e large Word equivalent like AbiWord or AppleWorks, or download a free, 300K ut ilit y? Craft y, experim ent al users realize t hat every file or docum ent ever creat ed can be opened up in a plain- old t ext edit or. Whet her you act ually get som et hing useful is up for grabs, but m ore t im es t han not , you can recover a bit of m eaning from a Word docum ent by dropping it int o your friendly neighborhood t ext edit or, as shown in Figure 1- 23. I n som e cases, you can act ually learn inform at ion t he sending user didn't int end for you t o know — like t he locat ion on her hard drive where it was originally saved. Figu r e 1 - 2 3 . A W or d docu m e n t in Te x t Edit
But I digress. Opening Word docum ent s in BBEdit or Text Edit ( or even vi, pico, or Em acs for shell [ Hack # 48]
lovers) is a hack at best — one we could cert ainly do wit hout in our beloved OS X. That 's where Ant iWordService ( ht t p: / / www.devon- t echnologies.com / ) from DEVONt echnologies com es in. I t 's a very sm all and easy- t o- inst all piece of freeware t hat will give any Cocoa applicat ion t he abilit y t o open Microsoft Word docum ent s. Download, drop int o your ~ / Library/ Services direct ory, log out and back in, and drag t hat dast ardly .doc t o Text Edit . Bingo! I nst ant plain t ext . I t 's not perfect , as t he docum ent at ion confesses: only plain t ext is preserved, no im ages and no form at t ing. But in m ost cases t hat 's m ore t han enough, since you're opening up a Word docum ent ; nat urally, you should be int erest ed only in t he words. One t hing of not e about Ant iWordService is how it 's a perfect m arriage of t he OS X ease of use and t he power of Unix, now part of Apple's OS for t he next fift een years. I n act ualit y, Ant iWordService is j ust an OS X wrapper around an open source shell ut ilit y called ant iword ( ht t p: / / ant iword.cj b.net / ) , available for t en different operat ing syst em s. You'll also find t wo ot her OS X ut ilit ies based on ant iword: t he ant iword port ( ht t p: / / www.ronaldo.com / proj ect s/ ant iword/ ) by Ronaldo Nascim ent o and DOCt or ( ht t p: / / www.st one.com / DOCt or/ ) from St one Design. Of t he t hree OS X variant s, Ant iWordService int egrat es best wit h your day- t o- day work, m aking t he t ranslat ion effort invisible.
[ Team LiB ]
[ Team LiB ] Chapter 2. Startup
Sect ion 2.1. Hacks # 13- 17 Hack 13. Get t ing a Glim pse of t he Boot Process Hack 14. Boot ing from Anot her Device Hack 15. Turning Your Mac int o a Hard Drive Hack 16. Using Open Firm ware Password Prot ect ion Hack 17. OS X for This Old Mac
[ Team LiB ]
[ Team LiB ] 2.1 Hacks #13-17 As you st are adm iringly at t hat elegant whit e- on- gray Apple logo and are m esm erized by t hat spiraling progress spinner, you m ay not ice t he quiet t icking, grinding, and plinking em anat ing from your Mac's innards. Before fading t o a brilliant blue and filling your screen wit h colorful icons and t hat fam iliar m enu bar, t here's an awful lot going on behind t he scenes t o bring your Mac t o life. And it isn't all t hat pret t y. This chapt er t akes a peek beneat h t he surface at j ust what 's m aking all t hat noise. We'll show you how t o boot from anot her device, t urn your Mac int o a FireWire hard drive, get OS X running on t hat old Power Mac in your closet , and lock up your Mac good and t ight so t hat only t hose wit h t he right key can get t o your st uff.
[ Team LiB ]
[ Team LiB ] Hack 13 Getting a Glimpse of the Boot Process
A lot goe s on be h in d t h e sce n e s w h e n e ve r you r e st a r t you r M a cin t osh ; ve r bose boot in g pr ovide s a u n iqu e glim pse of t h e Un ix u n de r pin n in gs of M a c OS X. A lot goes on behind t he scenes whenever you rest art your Macint osh. I n pre- OS X days, we couldn't really t ap int o t his knowledge; at m ost , we knew what cont rol panels and ext ensions had been st art ed, but t hat was about it . Nicely, OS X gives us a few ways we can t urn on verbose boot ing, providing m ore esot eric knowledge for our coffers. Being able t o see exact ly what goes on when you st art your com put er is easier t han you m ay t hink. Longt im e OS 9 users m ay recall t he Shift or spacebar keyboard t ricks: hold one down during boot up and you'll disable, or int eract ively choose, your ext ensions, respect ively. The sam e principle lies behind verbose boot ing in OS X: sim ply hold down t he and V keys. When you do t his during st art up, your screen should t urn black and you'll see t iny t ext inst ead of t he norm al happy Mac or Apple logo. Most of t his t ext m ay not m ake m uch sense t o you, but som e m essages about your hardware will appear as OS X t ries t o figure out what you've got plugged in or inst alled. You m ay find t hat t he t ext scrolls by t oo fast for your inquisit ive m ind t o handle. No worries, t hough; since OS X is based on Unix, nearly everyt hing get s writ t en down. Once you're logged int o t he Finder, open a Term inal window and ent er t he following com m and:
dme s g This displays t he syst em m essage buffer and covers everyt hing before t he OS X logging daem on boot s up ( called syslogd, it 's com m on across Unix inst allat ions) . The out put from your dme s g will cont ain m ost of t he hardware lines I m ent ioned before, as well as a few ot her nit picks here and t here; what you see will be unique for your com binat ion of hardware and equipm ent . Once t he OS X logging daem on com es int o play, t he rest of your dat a is saved int o / var/ log/ syst em .log, t he norm al place for m essages like t hese. I f you open t hat file up in any t ext edit or ( like vi or Em acs) , you'll see t he out put from d me s g ( as t he buffer is flushed t o t he syst em .log) , as well as a few ot her Con s ol e Me s s a g e lines — which should be t he sam e as what you'd see right before t he OS X login screen ( or Finder, if aut ologin is enabled) . I f you want t o see t he verbose m essages for each and every boot up, t here's an easier way t hen holding down t he t wo keys, and t hat 's by m odifying your com put er's nonvolat ile RAM t o rem em ber your preference. Ent er t he following com m and:
s u d o nvr a m b o o t - a r g s =" - v " Wit h t his, your com put er will always rest art wit h verbose boot ing and will cont inue t o do so unt il t he PRAM is
zapped or you boot int o OS 9. To st op t he verbosit y m anually, sim ply leave b oo t - a r g s em pt y:
s u d o nvr a m b o o t - a r g s =" " 13.1 See Also ●
For det ails on d me s g and n v r a m, at t he Term inal [ Hack # 48] , t ype ma n dme s g and ma n nv r a m,
●
respect ively. Boot ing and Logging I n ( ht t p: / / developer.apple.com / t echpubs/ m acosx/ Essent ials/ Syst em Overview/ Boot ingLogin/ index.ht m l) .
[ Team LiB ]
[ Team LiB ] Hack 14 Booting from Another Device
Boot a n d r u n you r M a c fr om a n ot h e r de vice , w h e t h e r it 's a n in t e r n a l h a r d dr ive or a n e x t e r n a l Fir e W ir e dr ive . I was t hrilled t o have t he chance t o t ry out a seed build or t wo of Mac OS X 10.2 ( Jaguar) before final release. That is, unt il yet - unnot iced bugs wit h t he Quart z rendering engine t urned m y screen t o m ush and com pat ibilit y problem s wit h som e of m y old set t ings rendered an applicat ion all but unusable. Thank goodness I 'd not act ually inst alled t he prerelease on m y iBook's hard drive, but was running it from an ext ernal FireWire hard drive. A quick reboot and I was back t o m y t rust y 10.1.5 part it ion running on m y int ernal drive. Macint osh m akes it easy t o boot from anot her device. No need t o fiddle wit h a BI OS or horrid boot .ini files. And absolut ely no need t o unplug one drive t o have t he Mac recognize and use anot her. To boot from anot her device, m ake sure it 's plugged in, is recognized by Mac OS X, and has a boot able part it ion cont aining a usable operat ing syst em . Shut down your Mac ( Apple m enu Shut Down) . While holding down t he Opt ion key, t urn on your Mac. You'll be greet ed wit h t he screen shown in Figure 2- 1. Figu r e 2 - 1 . Boot in g fr om a n ot h e r de vice
I have only one part it ion list ed, despit e having an ext ernal FireWire drive plugged in; t he FireWire drive doesn't have a viable operat ing syst em on it at present , so it is excluded from t he list of possibilit ies. Were I t o have m ore t han one usable device/ operat ing syst em , t hey would be list ed alongside Macint osh HD. Your m ouse point er will probably look like a wat ch for a t im e as your Mac scans at t ached and int ernal hardware for possible boot devices. You can force a rescan — perhaps aft er plugging in anot her device — by clicking t he but t on wit h t he sem icircular icon on t he left . When you're ready, choose a device by clicking on it . Macint osh HD, in m y case, is already select ed. Click t he but t on wit h t he right arrow on t he right t o boot .
Of course, if you j ust want t o boot from anot her part it ion on your local hard drive — you want t o pop int o Mac OS 9 for a m om ent , for inst ance — you should use t he St art up Disk preference pane ( Applicat ions Preferences Figure 2- 2.
St art up Disk) . Select t he syst em you wish t o boot and click t he Rest art . . . but t on, as shown in
Figu r e 2 - 2 . Se le ct in g t h e St a r t u p D isk
[ Team LiB ]
Syst em
[ Team LiB ] Hack 15 Turning Your Mac into a Hard Drive
Boot you r M a c in t a r ge t m ode a n d t r e a t it lik e j u st a n ot h e r Fir e W ir e dr ive . I got m y brand- spanking- new 800MHz iBook t he ot her day. I was short on t im e — finishing t his book, in fact — but couldn't wait t o m ake t he swit ch from m y exist ing Mac t o m y sleek, snappy bundle of OS X j oy. How could I m ove all of m y applicat ions and hom e direct ory ( / Users/ rael) ? I could do wit hout t he et ernit y I 'd have t o wait t ransferring it over t he net work. I didn't relish t he num ber of CDs I 'd have t o burn t o bring across all 3 gigabyt es. And t he idea of picking t hrough t he clut t er on m y ext ernal FireWire drive t o m ake room left m e ill. I f only I could m ount m y old m achine's hard drive alongside t he new one wit hout t ools and duct t ape. Surely I could j ust t reat m y old Mac as a hard drive som ehow. I sure could, and did. I t t urns out you can m ount one Mac's hard drive ont o anot her Mac over FireWire quit e easily. You sim ply t ie t hem t oget her wit h a FireWire cable and reboot one of t hem wit h t he T ( for t arget ) key held down.
This assum es, of course, t hat you have a FireWire- capable Mac on bot h ends.
Aft er j ust a few seconds, m y old m achine boot ed int o what 's known as t arget m ode, t he screen blinking a FireWire logo where usually t here'd be a Mac OS X login screen. A click, spinup, and whirr lat er, m y old hard drive showed up right on m y new Mac's deskt op. Thanks t o Macint osh's t radit ion of not spreading inst alled soft ware all over t he hard drive, I was able t o drag over individual applicat ions from m y Applicat ions folder. I dragged m y hom e direct ory over and logged out and back in again and I was m oved in, preferences and Deskt op as I 'd left t hem on t he ot her m achine. And all t hat in around 23 m inut es, from boot t o enj oy. When you're done, ej ect t he m ount ed drive by dragging it t o t he Trash or select ing it and pressing - E. As far as t he t arget m achine's concerned, j ust t urn it off or reboot it when you're finished; it 'll com e back up as if it were all j ust a dream .
[ Team LiB ]
[ Team LiB ] Hack 16 Using Open Firmware Password Protection
Pa ssw or d- pr ot e ct you r M a c, block in g cir cu m ve n t ion by boot in g fr om a n ot h e r de vice , boot in g in t o sin gle - u se r m ode , a n d m or e . There are t im es when you want nary a finger but your own fiddling wit h your com put er. No sist er, no boss, no m ot her looking for porn, no husband reading chat logs. Wit h t he Open Firm ware built int o newer m odels of t he Mac ( iBooks, G4s, som e iMacs, et c.) , you have access t o a st rong, low- level way of password prot ect ing your Mac from m eddling int erlopers and innocent wanderers. Before we go any furt her, you'll have t o check whet her your com put er has t he necessary firm ware. To do so, open t he Apple Syst em Profiler ( under / Applicat ions/ Ut ilit ies/ ) and look under t he Syst em Overview sect ion for t he Boot ROM version ( which also represent s your Open Firm ware version) , as shown in Figure 2- 3. On m y dual 450MHz G4 running 10.2.2, you can see Boot ROM info wit h a value of 4.2.8f1. To be eligible for password prot ect ion, you'll need lat er t han 4.1.7 or 4.1.8 ( firm ware upgrades are available at Apple's web sit e) . Figu r e 2 - 3 . Apple Syst e m Pr ofile r
Once we've m et t he version prerequisit es, what exact ly does t his password prot ect ion prevent ? Longt im e users of t he Mac OS m ay recall such pre- OS X hacks as holding down t he Shift key or cust om izing your ext ensions wit h t he spacebar, as well as t he abilit y t o boot from a CD. While ext ensions don't exist under OS X, Open Firm ware blocks all ot her avenues t hat do, including boot ing up wit h t he C, N, or T keys depressed, in single or verbose m ode, or zapping t he PRAM. I t 'll also require a password if you t ry t o edit it s set t ings or get int o t he St art up Manager.
As wit h m ost t echnology, t here's m ore t han one way t o set t he password, depending on your skills. Apple provides a ut ilit y t hat will do all t he m agic for you in a pret t y GUI ( see t he link in t he See Also sect ion of t his hack) . Sim ply download t he inst aller, run t he single screen configurat ion, and reboot your m achine t o solidify your password prot ect ion. But what if you want ed t o do everyt hing by accessing Open Firm ware m anually and having com plet e cont rol over , Opt ion, O, and F keys t he process? No problem ! First off, boot int o Open Firm ware by holding down t he during st art up. You'll be dropped int o a blank screen wit h a m ere prom pt for t yping com m ands. Next , set t he firm ware password by t yping p a s s wo r d and ent ering your password t wice ( for verificat ion) . Once you've done t hat , set t he securit y level wit h s e t e n v s e c u r i t y- mod e , where can be one of t hree words: none ( no securit y) , c o mma n d ( rest rict s usable Open Firm ware com m ands) , or f ul l ( which does t he sam e t hing as Apple's downloadable ut ilit y) . Finally, t o reboot t he com put er wit h your changes saved, ent er r e s e t - a l l . Disabling t he password prot ect ion can be done wit h Apple's provided ut ilit y or by boot ing int o Open Firm ware ( as before) , t yping s e t e n v s e c u r i t y - mo d e n o n e , ent ering your password, and t hen reboot ing t he com put er wit h r es et - al l .
16.1 Hacking the Hack The inevit able has happened: you've forgot t en t he password you've set in Open Firm ware. Luckily, t here are a couple of alt ernat ives: boot ing int o OS 9 ( and opt ionally zapping t he PRAM) or rem oving som e m em ory DI MMs. But if you're lucky enough t o st ill be logged int o t he Finder ( before a worrisom e reboot ) , you can download an OS 9 ut ilit y called FW Sucker. Wit h a sim ple double- click, it 'll display t he current firm ware password, from which you can t hen disable t he prot ect ion or change it t o som et hing m ore suit able ( via t he earlier inst ruct ions) .
16.2 See Also ●
● ● ●
How t o Set Up Open Firm ware Password Prot ect ion ( ht t p: / / docs.info.apple.com / art icle.ht m l? art num = 106482) Open Firm ware Password 1.02 Download ( ht t p: / / docs.info.apple.com / art icle.ht m l?art num = 120095) Open Firm ware Password Prot ect ion ( ht t p: / / www.securem ac.com / openfirm warepasswordprot ect ion.php) FW Sucker 1.0 ( ht t p: / / www.m sec.net / soft ware/ index.ht m l# fwsucker)
[ Team LiB ]
[ Team LiB ] Hack 17 OS X for This Old Mac
Give you r le ga cy M a c h a r dw a r e a n u dge in t o OS X w it h t h e XPost Fa ct o h a ck . Wait , don't t hrow out t hat old Power Mac or Um ax clone; it m ay j ust be up for a lit t le Mac OS X sprucing. Som e of t hose old Macs will act ually run Mac OS X 10.2 ( Jaguar) — wit h a lit t le help from an unassum ing- looking cont rol panel. I recent ly gave an old 7500 a G3 upgrade card from Sonnet ( ht t p: / / www.sonnet t ech.com / ) , a quad- port FireWire card, and a dual- port USB card ( only $37, com bined) . Mac OS 9 ran rat her snappily and t he m achine served quit e nicely as a USB print server. Then I st um bled across a lit t le som et hing called XPost Fact o ( ht t p: / / eshop. m acsales.com / OSXCent er/ XPost Fact o/ ) , which is open source and free. XPost Fact o is a lit t le hack t hat brings Mac OS X, OS X Server, and Darwin t o older, unsupport ed, and forgot t en Mac m odels — t hose draped in t he unfashionable beige of t im es past . Before you t hink of giving XPost Fact o a whirl, be sure t o consult t he com pat ibilit y chart at : ht t p: / / eshop.m acsales.com / OSXCent er/ XPost Fact o/ fram ework.cfm ?page= XPost Fact o.ht m l# preparing Also, m ake sure your m achine has been recent ly backed up. You're dealing wit h an unsupport ed hack here. You can find XPost Fact o sit e's com prehesive docum ent at ion at : ht t p: / / eshop.m acsales.com / OSXCent er/ XPost Fact o/ fram ework.cfm ?page= XPost Fact o.ht m l The procedure in a nut shell is: 1. Boot int o Mac OS 9. 2. I nsert your st andard- issue Mac OS X inst allat ion CD. 3. Run t he XPost Fact o applicat ion ( icon shown in Figure 2- 4) . 4. Point XPost Fact o at t he inst all CD and t arget volum e. 5. Click t he I nst all but t on. 6. Follow t he usual inst allat ion inst ruct ions.
Figu r e 2 - 4 . Th e XPost Fa ct o u t ilit y
I t 'll t ake a while, m ind you. Have som e coffee, read The New York Tim es, wat ch a m ovie, and have a good m eal. When you ret urn, if all's gone according t o plan, OS X should be hum m ing away on your old t hrowaway Mac.
Ot her World Com put ing does offer XPost Fact o support for a one- t im e $10 fee. I f you're going t o be running OS X on a legacy m achine in a real product ion environm ent — as opposed t o j ust seeing if it can be done — m aking t he invest m ent in som e help m ay j ust be wort hwhile.
[ Team LiB ]
[ Team LiB ] Chapter 3. Multimedia and the iApps
Sect ion 3.1. Hacks # 18- 32 Hack 18. Top iChat Tips Hack 19. AI M Alt ernat ives Hack 20. Print ing t o PDF or Bit m apped I m age Hack 21. I m age Conversion in a Pinch Hack 22. Top 10 iPhot o Tips Hack 23. Make Your Own Docum ent ary Hack 24. From Slideshow t o Video Present at ion Hack 25. Hij acking Audio from Mac Apps Hack 26. Running Your Own Web Radio St at ion Hack 27. Sharing Your List ening Preferences Hack 28. Cont rolling iTunes wit h Perl Hack 29. iCal Calling iTunes Hack 30. Publishing and Subscribing t o iCal Calendars Hack 31. Using Bluet oot h for SMS and Phone- Call Handling Hack 32. iSync via Bluet oot h
[ Team LiB ]
[ Team LiB ] 3.1 Hacks #18-32 Apple has posit ioned t he Mac as a digit al hub, t he nexus for t he ot herwise disparat e com ponent s of your iLife. I t has m ore t han backed up t his claim wit h a suit e of sim ply powerful applicat ions: iPhot o, your digit al shoebox; iTunes, your personal audio j ukebox; iMovie and iDVD, for t he budding independent film m aker; iCal t o keep t rack of where you're supposed t o be next ; and iSync t o keep all your devices in sync. Add t o t his Apple's .Mac online service, ever m ore int egrat ed int o your Mac's online life. Back up your Mac's preferences and t hose im port ant docum ent s you have wit h you on t he road. Check your m ail, consult your address book, and share your calendar t hrough any ordinary web browser. I t 's all com ing t oget her rat her nicely. That doesn't m ean t here isn't room t o hack. This chapt er provides t ips and t echniques for get t ing t he m ost out of t he iApps and t hird- part y m ult im edia applicat ions. Going beyond what t he iApps provide out of t he box, we'll also glue t oget her audio, video, t ext , and phot os in som e unexpect edly useful and fun com binat ions.
[ Team LiB ]
[ Team LiB ] Hack 18 Top iChat Tips
iCh a t is m or e t h a n j u st a gr e a t in st a n t m e sse n ge r clie n t . H e r e is a colle ct ion of t ips t o ge t t h e m ost ou t of t h is fa bu lou s a ddit ion t o t h e iApp fa m ily. The m om ent it becam e available, j ust about every Mac geek I knew dropped t heir AI Ms, Adium s, Fires, Jabbers, and Prot euses and m ade t he swit ch t o iChat , Apple's iApp- flavored inst ant m essaging client . What 's not t o love? I t 's colorful, friendly, and decidedly Mac. But t here's m ore beneat h t he candy- coat ed surface t han j ust anot her inst ant m essenger ( I M) applicat ion. This hack is all about get t ing t he m ost out of iChat t hrough a few useful t ips and delight ful surprises discovered bet ween " Up lat e?," " We're m oving t hat m eet ing t o Friday," and " Dinner's ready! "
18.1 Into the Well Before you do anyt hing else, be sure t o put a face t o your I M nam e. There's not hing quit e as dist ancing as a conversat ion wit h a generic AI M ( AOL I nst ant Messenger) icon. Whet her you choose a cart oon charact er close t o your heart or a recent prom o snapshot you were badgered int o, sim ply drag an im age int o t he buddy icon well at t he t op right of t he iChat buddy list window ( see Figure 3- 1) and it 'll appear along wit h your nam e or I M handle in your buddies' buddy list s. Figu r e 3 - 1 . D r a ggin g a pict u r e in t o t h e bu ddy icon w e ll
As shown in Figure 3- 2, iChat 's Buddy I con dialog allows you t o scale and posit ion your preferred im age unt il it 's j ust right . Slide t he lit t le blue ball left and right t o scale t he im age. Drag t he im age it self around unt il it 's where you like it . Click Done when you're done. Figu r e 3 - 2 . Re sizin g a n d posit ion in g a bu ddy icon
Change your buddy icon any t im e you wish, depending on m ood, int erest , or j ust random ly t o confuse and delight your friends.
18.2 Rendezvous Rendezvous ( ht t p: / / www.apple.com / m acosx/ j aguar/ rendezvous.ht m l) , Apple's branding of a larger st andardizat ion effort called Zeroconf ( ht t p: / / www.zeroconf.org/ ) , allows for devices t o broadcast t heir exist ence and discover ot hers on a local net work, peering and m aking use of each ot her's available services — all wit h zero configurat ion. iChat has Rendezvous baked right in. I t 'll not ice ot her iChat users com ing and going on t he local net work, keeping t rack of t he t ransient populat ion in a Rendezvous buddy list ( see Figure 3- 3) . Figu r e 3 - 3 . A Re n de zvou s bu ddy list
To enable Rendezvous in iChat , select iChat
Log I nt o Rendezvous or press Opt ion-
special Rendezvous buddy list ( separat e from your personal I M buddy list ) , select Window press - 2.
- L. To display t he Rendezvous or
Even if you're not connect ed t o t he I nt ernet , you can chat on your local Et hernet or AirPort net work t hrough t he wonders of Rendezvous. Rat her t han I M m essages flowing bet ween t wo buddies via AOL's I nst ant Messenger servers, t hey flow direct ly, peer t o peer. This m eans t oo t hat file t ransfer over iChat is m uch fast er, lim it ed by t he speed of your local net work rat her t han your connect ion t o t he I nt ernet and responsiveness of AOL's servers. iChat Rendezvous is j ust perfect for a hom e net work, int erm it t ent ly connect ed ( t o t he I nt ernet ) classroom net work, and at m eet ings for ad hoc collaborat ive online not e t aking and side conversat ion. Where t he Rendezvous/ iChat com bo really shines is at WiFi- enabled conferences, part icipant s keeping in t ouch wit h one anot her t hrough t he course of t he day and discovering people t hey didn't know were at t ending.
18.3 File Transfer You're chat t ing wit h a buddy about som e lat est bit of shareware and want t o pass it along. Perhaps you're checking in wit h a coworker a world away about t he lat est copy of t hat report you're bot h suppposed t o have finished already. Sim ply drag t hat shareware inst aller, PowerPoint report , or any ot her file t o t he nam e or icon represent ing som eone in your buddy list . He'll be not ified t hat you've init iat ed a file t ransfer, confirm receipt , and away t hat file goes. No need for uploading t he report t o your ent erprise server for download by your coworker. No need for t urning on Apache, figuring your your I P address, and providing your buddy wit h a URL. iChat 's perfect when you want t o copy a file quickly from one m achine t o anot her. No need t o set up a separat e I M nam e; Rendezvous will t ake care of t he int roduct ions for you. Just drag t he file ont o your alt er ego's nam e in your Rendezvous buddy list and roll your chair across t he floor t o t he ot her m achine t o accept t he file t ransfer. I f you have m ult iple files t o t ransfer, unfort unat ely, iChat won't sim ply allow you t o drag t hem all ont o a buddy's nam e. What you can do, however, is put t he files int o a folder and drag and drop t he folder t o your buddy.
File t ransfer works regardless of operat ing syst em or I M applicat ion, j ust as long as you're bot h using an AOL I nst ant Messenger- or @m ac.com - enabled I M client . Your firewall will also need t o be liberal enough t o allow peer- t o- peer file t ransfer.
18.4 Screenshot Sharing Here's a variat ion on t he file- t ransfer t hem e. Trying t o help a fam ily m em ber wit h som et hing on her Mac and having t rouble pict uring what exact ly it is t hat she's doing? Get her t o t ake a screenshot [ Hack # 41] ( - Shift - 3) of her screen j ust as it is at t hat m om ent and drag t he Pict ure x.pdf file t o your nam e in her buddy list . I t 's am azing what a t im e saver t his can be. I f you're a cust om er- support person dealing wit h a Mac user, t ry t his wit h t hat cust om er who doesn't appear all t hat adept at describing what he's doing.
18.5 Whereabouts Even when I don't chat wit h t he gaggle of buddies winking in and out of exist ence in m y buddy list , it 's nice t o see t hem passing t hrough. Som et im es I even get a slight ly m ore det ailed glim pse of what t hey're up t o and where t hey're going, t hanks t o buddy st at us m essages. Set your st at us by clicking t he exist ing st at us m essage below your nam e at t he t op of your Buddy List window, as shown in Figure 3- 4. Figu r e 3 - 4 . Se t t in g a va ila bilit y st a t u s
The default s aren't part icularly descript ive: Available, Away, and Offline. But you can set a cust om st at us associat ed wit h eit her a red or green st at us light . I nst ead of choosing a st at us from t he list , select Cust om . . . associat ed wit h eit her a red ( unavailable) or green ( available) st at us light . Type in a short m essage — 10 t o 15 charact ers is about right — and press your Ret urn key. The result should look som et hing like Figure 3- 5. Figu r e 3 - 5 . Cr e a t in g a cu st om st a t u s
Your cust om st at us will be reflect ed wherever you appear in som eone's buddy list ( see Figure 3- 3) . I f you ever want t o rem ove old st at us m essages en m asse, select Edit List . . . from t he st at us list .
Select ing a red st at us light m eans t hat anyone who doesn't not ice t hat you're unavailable and t ries t o init iat e a chat will receive your st at us m essage as an aut oreply. You'll st ill have t heir incom ing m essage wait ing for you when you ret urn.
18.6 Chatrooms iChat allows m ore t han j ust one- t o- one I M chat s. You can creat e a new ad hoc chat room and invit e buddies t o j oin you, all chat t ing t oget her in a secluded lit t le online space. There are act ually t wo t ypes of chat space: invit eonly and a m ore t radit ional chat room where people can pop in at will — assum ing t hey know of it s exist ence.
To st art an invit e- only chat space, select File New Chat ( - N) . This creat es a chat space j ust as wit h any ot her one- t o- one conversat ion. The differences are t hat you are current ly t he only part icipant and a Part icipant s pane is at t ached t o t he side of t he chat window. To invit e som eone, click t he plus sign ( + ) in t he Part icipant s pane and select a buddy. Do t his for as m any buddies as you like. Act ually, any one- t o- one chat can be t urned int o an invit e- only chat space by clicking t he person icon ( t hat 's t he left m ost but t on on t he bot t om of a chat window) t o open t he Part icipant s pane and t hen proceeding as before. The second t ype of group chat is a m ore t radit ional AOL- st yle chat room . To creat e or j oin an exist ing chat room , select File
Go To Chat . . . (
- G) , as shown in Figure 3- 6. Figu r e 3 - 6 . Go To Ch a t . . .
I n t he Go To Chat . . . dialog, leave t he AOL I nst ant Messenger service select ed and t ype t he nam e of an exist ing chat room or what ever you'd like t o nam e a new one in t he Chat Nam e field, as shown in Figure 3- 7. Click Go and you'll be whisked away t o your chat room aft er a few seconds.
Figu r e 3 - 7 . Join in g a ch a t r oom
To leave a chat space, sim ply close t he chat window. Your buddies can cont inue chat t ing as if you'd never been t here.
18.7 Buddies Unfort unat ely, at t he t im e of t his writ ing, iChat doesn't have any easy way t o add som eone you've been chat t ing wit h t o your buddy list . You'd t hink it 'd j ust be a m at t er of dragging his buddy nam e from t he chat window t o t he buddy list , but t hat sim ply doesn't work. To add a buddy, click t he plus sign ( + ) but t on on t he bot t om left of your Buddy List window ( see Figure 3- 8) . Figu r e 3 - 8 . Th e a dd bu ddy bu t t on
You'll be offered t he opport unit y t o search for or select som eone from your Address Book. I f she is in your Address Book but doesn't yet have an AI M or @m ac handle associat ed wit h her, ent er one in t he supplied field and you're done. I f she's not already one of your cont act s, click New Person and fill in t he form t o creat e an ent ry in t he Address Book and add her t o your buddy list sim ult aneously ( see Figure 3- 9) . Figu r e 3 - 9 . Addin g a bu ddy
18.8 Logs Unless you've chanced upon t hem in your Docum ent s direct ory, you probably don't know t hat iChat keeps logs of every chat you have. You'll find t hem all in Docum ent s/ iChat s. They're list ed by buddy ( full nam e or buddy handle) and num ber, st art ing wit h 1 ( e.g., St eve Jobs # 7.chat ) . Don't bot her t rying t o read t hem in a t ext edit or; t hey're serialized obj ect s ( noise t o you and m e) viewable eit her program m at ically or from wit hin iChat .
Open an old chat by select ing File
Open . . . (
- O) and select ing it from t he list , as shown in Figure 3- 10.
Figu r e 3 - 1 0 . Ope n in g a n iCh a t log e n t r y
Figure 3- 11 shows an exact replica of an earlier chat , replet e wit h buddy icons and sm ileys. Figu r e 3 - 1 1 . Re a din g a n iCh a t log e n t r y
Of course you can rem ove old logs at any t im e by sim ply delet ing t hem from Docum ent s/ iChat s.
[ Team LiB ]
[ Team LiB ] Hack 19 AIM Alternatives
Th e r e a r e va r iou s fe a t u r e - pa ck e d a lt e r n a t ive s t o t h e de fa u lt AOL I n st a n t M e sse n ge r clie n t for M a c OS X. When people st art ed discovering AOL's I nst ant Messenger t aking up a large port ion of t heir CPU for seem ingly m enial ( or nonexist ent ) t asks, t he proverbial chad hit t he fan; people want ed som et hing bet t er and t hey want ed it now, regardless of what silly or point less feat ures t hey m ay end up m issing. Let 's t ake a brief look at som e of t he alt ernat ives t hat have gained popularit y: iChat ( ht t p: / / www.apple.com / ichat / ) Since Apple ships iChat wit h it s OS X 10.2, t here's a very good chance t hat iChat will becom e t he reigning cham p of AI M im it at ors. Creat ed wit h t he blessing of AOL it self, iChat support s chat s, file t ransfers, and buddy icons and uses a GUI t hat m anifest s m essages int o cart oon- st yle balloons ( which don't look as bad as t hey sound) . I t has st rong support for Mail ( a colum n t hat t ells you if t he sender of t he em ail is online) and t he Address Book, along wit h t he abilit y t o cust om ize which act ions will be perform ed for a num ber of com m on event s ( buddy logging in, buddy t yping, et c.) . Adium ( ht t p: / / www.adium x.com ) Adium has been gaining a st rong following for guerrilla AI M users, m ainly due t o it s im m ense cust om izat ion and it s low syst em requirem ent s. I t has a clean and refined int erface, as well as being m inim al for t hose worried about screen real est at e. I t 's free and is built using Cocoa ( and t hus get s a num ber of t hings for free: spellchecking, ant ialiasing, et c.) . Fire ( ht t p: / / www.epicware.com / fire.ht m l) Fire is t he granddaddy of inst ant m essengers for OS X; it 's been around as long as OS X has and has consist ent ly been im proved from version t o version. I t 's open source and it shows, offering langauge localizat ions cont ribut ed by ot hers, heart y am ount s of bug fixes, soundset s, icons, and m ore. While it s int erface m ay not be t he pret t iest , it s abilit y t o hook int o AI M, Yahoo! , MSN, I CQ, Jabber, and I RC is a clincher for t hose wit h m ult iple service needs. Prot eus ( ht t p: / / www.indigofield.com / ) Prot eus, m y current favorit e, is m uch like Fire in t hat it hooks int o a num ber of providers: AI M, Yahoo! , MSN, I CQ, and Jabber. I t benefit s by having a st rong am ount of cust om izat ion, wit h t he int erest ing abilit y t o run shell script s at various point s ( such as when m essages are received, so t hat , for inst ance, you could m ake your own logging syst em ) , along wit h t he abilit y t o choose t hem es, icons, soundset s, and so on. I t s GUI is a lit t le m ore refined t han Fire's. I f t hese AI M alt ernat ives don't sat isfy your m essaging it ch, don't hesit at e t o browse t he excellent VersionTracker
( ht t p: / / www.versiont racker.com ) for m ore possibilit ies. You m ay also want t o t ake a look int o Jabber m essenging syst em s, which can hook int o any I M prot ocol t hat t he Jabber server support s. The best way t o find t hese XMLbased alt ernat ives is t o search Sourceforge ( ht t p: / / www.sourceforge.net / ) or VersionTracker.
[ Team LiB ]
[ Team LiB ] Hack 20 Printing to PDF or Bitmapped Image
Pr in t in g t o PD F or bit m a ppe d TI FF im a ge u n de r OS X is bu ilt r igh t in , a va ila ble t o a lm ost a n y a pplica t ion w it h Pr in t fu n ct ion a lit y. OS X's reliance on PDFs for everyt hing from t he Dock t o Print Preview present s quit e a boon when it com es t o PDF viewing support and t he creat ion of sim ple PDFs. While it 's som et hing t hat ordinarily requires specialized soft ware, print ing t o PDF or bit m apped TI FF im age under OS X is built right in, available t o alm ost any applicat ion wit h t he abilit y t o print .
From your applicat ion, choose Print — alm ost always File Print or - P. I n t he Print dialog, select t he applicat ion- specific set t ings from t he pull- down m enu ( Copies & Pages should be select ed by default ) and m ake any adj ust m ent s you wish. These range from sim ple font select ion t o I nt ernet Explorer's wide- page handling and cont rol over t he inclusion of headers and foot ers, im ages, and backgrounds. Som e applicat ions m ake t heir opt ions available out side of t he Print dialog via an Opt ion but t on. When you're ready, rat her t han being t em pt ed by t he pulsat ing Print but t on, click Preview ( see Figure 3- 12) . Figu r e 3 - 1 2 . I n t e r n e t Ex plor e r 's Pr in t dia log
I f Print Preview's m ore visual way of adj ust ing opt ions is m ore your gam e — and is available t o you in t he applicat ion at hand — go right ahead. When you're finished, click Print in t he Print Preview dialog followed by Preview in t he Print dialog and you're back wit h t he class. Previews are handled, appropriat ely enough, by t he Preview applicat ion, t he light weight PDF viewer t hat com es wit h OS X. You'll see a fresh, piping hot PDF of what ever it was you were print ing. To save t he PDF, select File
Save As PDF . . . , renam e Preview of what ever.pdf t o som et hing nicer, select your preferred save locat ion, and click t he Save but t on. Don't worry about t hat .pdf file ext ension [ Hack # 6] ; if you lop it off, OS X will kindly st ick it back on for you.
I f you prefer t o save t he preview as a bit m apped TI FF im age, select inst ead File - S. com binat ion Shift -
Save As . . . or t he key
Of course, using a specialized applicat ion like Adobe Acrobat for your PDF creat ion and edit ing needs provides m uch m ore fine- grained cont rol over t ext form at t ing, im age scaling, m argins, indent ing, and t he like. I f, however, you j ust want t o quickly package up a web page for offline viewing [ Hack # 86] or a rough cut of your lat est brochure for a friend wit hout needing anyt hing but a PDF viewer, Save As PDF in Preview sure does t he t rick.
[ Team LiB ]
[ Team LiB ] Hack 21 Image Conversion in a Pinch
Th e a bilit y t o con ve r t im a ge s fr om on e for m a t t o a n ot h e r w it h m in im a l r e t ou ch in g a n d m a n ipu la t ion is bu ilt r igh t in t o M a c OS X. Every so oft en — but not oft en enough t o warrant shelling out for a full- scale draw or paint program — I find m yself needing t o convert an im age from one form at t o anot her. Perhaps I have a phot o in TI FF form at I 'd like t o incorporat e int o m y web sit e as a JPEG or GI F. Or I need t o share a screenshot wit h a Windows user who prefers BMP t o PNG. Thankfully, OS X users have som e m inim al funct ionalit y for im age conversion and alt erat ion built right int o t heir OS.
21.1 Preview Preview t akes m e back t o t he days when a web browser becam e a launchpad for a plet hora of helper apps, specialized viewers for im ages, m ovies, or sounds. I t 's t he helper you always wished for for all t hings im age, able t o open, save, and convert PDF, JPEG, TI FF, PNG, and ot hers, as well as t o export a Phot oshop im age as a GI F, a Windows BMP t o Quickt im e, or a fancy new PNG t o old fait hful MacPaint .
Open an im age via File
Open,
- O, or double- clicking an im age file or dragging and dropping it t o
Export . . . , pick an out put form at , and save. For a m it e m ore Preview's Dock or Finder icon. Choose File fine- t uning, click t he Opt ions . . . but t on in t he Save sheet t o set color dept h, sim ple filt ering, int erlacing, and t he like, as shown in Figure 3- 13. Figu r e 3 - 1 3 . Ex por t in g t o a diffe r e n t im a ge for m a t
Now, don't expect m uch m ore t han open and save. Preview has som e m inim al flipping and rot at ing, but t hat 's about it . Most not ably lacking is t he abilit y t o crop, a m ust - have when creat ing screenshot s or a doing a quick hack j ob on an unduly large im age before forwarding it via em ail.
21.2 iPhoto iPhot o ( ht t p: / / www.apple.com / iphot o/ ) , while best suit ed t o it s prim ary role of digit al shoebox, does provide som e useful conversion facilit ies in a pinch. I t 's far m ore lim it ed t han Preview in t he im age form at s it support s ( JPG, TI FF, and PNG) but has a good deal m ore feat ures up it s sleeve: scaling, sim ple bright ness and cont rast cont rols, red- eye reduct ion, rot at ion, cropping, one- click enhance, ret ouching, and convert ing t o black and whit e.
Launch iPhot o. Drag one or m ore im ages int o it s window or select files via File I m port . . . iPhot o will im port your specified im ages and add t hem t o it s library. Click t he Last I m port roll in t he left hand pane t o narrow your view t o only what you j ust im port ed. I f you'd like t o do som e edit ing, select an im age and click Edit at t he bot t om of t he Preview ( right hand) pane. Most apropos t o what we're t rying t o accom plish is iPhot o's abilit y t o convert m ult iple files at once. When you're ready t o save, go back t o t he organize view by clicking Organize at t he bot t om of t he preview pane, select ( # ) Export . . . or press - E. Choose t he File Export t ab, m ake t he im ages you wish t o save, and choose File any size adj ust m ent s you wish, pick a form at , and click Export . iPhot o will prom pt you wit h t he st andard OS X Save dialog for a preferred export locat ion.
21.3 Graphic Converter
The venerable Graphic Convert er ( ht t p: / / lem kesoft .com / us_gcabout .ht m l) shareware app ( U.S.$30 in Europe, U. S.$35 in t he rest of t he world at t he t im e of t his writ ing) m akes t he t ransit ion over from OS 9 t o carbonized OS X. I t 's been t he Swiss Arm y knife for im ages on t he Mac as far back as 1993, im port ing around 160 im age file form at s and export ing t o around 45. Graphic Convert er support s bat ch conversion, is AppleScript - aware ( ht t p: / / lem kesoft .com / us_script s.ht m l) , and sport s a com prehensive t oolset including: rot at ion, com prehensive level adj ust m ent , sharpen and blur, cropping, and lot s m ore.
21.4 More Of course if you need m ore advanced im age m anipulat ion and drawing t ools, you m ay be in t he m arket for som et hing like Phot oshop or I llust rat or. The m aj or drawback is, of course, price; com prehensive com m ercial packages do com e rat her dear. A free, open source alt ernat ive is The Gim p ( ht t p: / / gim p.org/ ) , t he GNU I m age Manipulat ion Program ( read: Phot oshop- alike) ; alt hough it runs only under X11 for Mac OS X ( ht t p: / / www.apple. com / m acosx/ x11) or XonX ( ht t p: / / m rcla.com / XonX/ ) ( t hat 's X Windows on OS X) , you cert ainly can't beat t he power/ price com binat ion.
[ Team LiB ]
[ Team LiB ] Hack 22 Top 10 iPhoto Tips
Ye s, a t fir st gla n ce , iPh ot o a ppe a r s de ce pt ive ly sim ple . Bu t t h e r e 's a Un ix - com pa t ible da t a ba se lu r k in g be n e a t h t h a t be a u t ifu l Aqu a su r fa ce . At first glance, Apple's iPhot o ( ht t p: / / www.apple.com / iphot o) appears decept ively sim ple. You plug in your digit al cam era, iPhot o grabs all t he pict ures, and you play wit h t hem on your com put er screen. This process is so easy, in fact , t hat t he next t hing you know you have hundreds, if not t housands of im ages annexing real est at e on your hard drive. At som e point sobriet y set t les in, and you realize t hat you need t o back up t hose iPhot o im ages. Or you m ay want t o m ove t hem t o anot her com put er or free up space on your hard drive for even m ore pict ures. So, you open your iPhot o Library folder, which has grown t o m ore t han a gig in size, and figure you'll j ust grab logical part s of it and burn a few CDs. Problem is, t here appears t o be not hing logical about t he cont ent s of t his folder. All you see are num bered direct ories, which when you open t hem cont ain m ore num bered direct ories. Suddenly you realize t hat sort ing all t his out isn't going t o be so easy. This scenario is based on t he prem ise t hat you've figured out t he best way t o shoot your pict ures in t he first place. You've heard som e recom m endat ions here and t here about how t o t ake good digit al im ages, but you're st ill not sure about t hings such as: Do you always shoot at t he highest resolut ion? How do you t ake flat t ering port rait s of people out doors? And how t he heck do you prevent red eye? By now you m ay be t hinking, " Hey, I t hought iPhot o was going t o solve all m y problem s. I 'm m ore confused t han ever. You're bringing m e down, m an." The t rut h is, iPhot o is really quit e powerful ( and com plicat ed) , even t hough it appears sim ple on t he surface. The following 10 t ips will put you on t he fast t rack t o avoiding t he iPhot o " got chas" t hat lurk beneat h it s Aqua surface.
22.1 Data In: Taking Better Pictures I refer t o t his first sect ion ( t he first five t ips) as " Dat a I n" because iPhot o is really j ust anot her dat abase. As wit h all dat abases, t he higher t he qualit y of t he inform at ion going in, t he bet t er your out put will be. Taking good pict ures is key t o an enj oyable iPhot o experience.
22.1.1 Tip #1: Buy a bigger memory card for your camera. Forget about t hat cheesy 8MB card t hat cam e wit h your digicam and buy yourself som e real m em ory. Pony up for at least 32MB for 1.3- m egapixel cam eras, 64MB for 2- m egapixel m odels, 128MB for 3- m egapixel digis, and 256MB for 4- m egapixel shoot ers — anyt hing less will force you t o shoot at low resolut ion, t em pt you t o pass on creat ive pict ures, or send you const ant ly running t o your hot el room t o upload im ages because your m em ory card is full again. St ick t he 8MB card in your pocket for em ergencies and go wit h t he big guns in your cam era.
22.1.2 Tip #2: Shoot at your camera's highest resolution. You'll need a decent - sized m em ory card t o do t his, but it 's wort h t he invest m ent m any t im es over. You m ay t hink t hat you only want vacat ion phot os for your web sit e, but what if one t urns out t o be a real winner? Wouldn't it be nice t o have it as an 8- by- 10- inch print t oo? You'll need all t he resolut ion your cam era can m ust er t o m ake a phot o- qualit y print t hat size. Rem em ber, you can always scale high- resolut ion im ages down for ot her uses, but you can't go t he ot her way wit hout loss of qualit y. To get t he m ost out of your cam era, look for set t ings such as SHQ ( superhigh qualit y) and avoid anyt hing m arked as st andard resolut ion — which is really cam era- com pany lingo for subst andard.
22.1.3 Tip #3: Get closer. Casual phot ographers t end t o st and t oo far away from t heir subj ect s. Sure you can crop t he im age lat er in iPhot o, but t hat 's like t urning your pricey 3- m egapixel cam era int o a run- of- t he- m ill 2- m egapixel m odel. Get close t o your subj ect , fram e it in your viewfinder, t hen get even closer. Your shot s will require less cropping and have m ore personalit y.
22.1.4 Tip #4: Find the fill flash setting and use it. Fill flash m eans t hat t he cam era's flash fires every t im e, even in broad daylight . You see, j ust because it 's light out side doesn't m ean t hat t he light is good on your subj ect 's face. By t urning on t he fill flash and get t ing wit hin 10 feet of your m odel, you illum inat e his handsom e feat ures and add a nice t winkle t o his eyes. Look for t he flash icon t hat 's usually a plain light ning bolt . Rem em ber t hat your flash will m ost likely ret urn t o t he default aut oset t ing when you t urn off t he cam era, which m eans your cam era, not you, will decide when t o use t he flash.
22.1.5 Tip #5: Avoid red eye when possible. This m onst erlike count enance t hat appears in ot herwise innocent subj ect s is t he bane of com pact cam eras. Red eye is caused by t he flash reflect ing off t he subj ect 's ret inas. This usually happens in dim ly lit room s when a subj ect 's eyes are dilat ed. You can help avoid red eye by having t he subj ect look at a lam p or an open window ( t hat is, if it 's light out side! ) right before t he shot . Ot her t ricks include t urning up t he room light s or shoot ing from a slight angle so t hat t he subj ect isn't looking direct ly int o t he cam era. I f all else fails, iPhot o does include a red- eye- rem oval t ool t hat can help wit h t his problem , but it 's best t o avoid post product ion work as m uch as possible.
22.2 Data Out: Managing iPhoto Files This sect ion ( t he last five t ips) focuses on m anaging t he m ount ain of dat a you'll be loading int o your com put er in t he form of JPEG files. Wit h j ust a lit t le foresight , and by adding a couple of free ( or really inexpensive) t ools, you'll never suffer from t he iPhot o backup blues.
22.2.1 Tip #6: Limit library size to 650MBs.
Every t im e you upload a phot o, your iPhot o library grows a lit t le m ore. Before t oo long it can easily swell t o a gigabyt e or m ore. Unless you own a DVD burner or you have lot s of spare space on a FireWire hard drive, you're going t o have a hard t im e fit t ing libraries ont o st andard CDs for backup and port abilit y. Plus, if you hang out in t he iPhot o discussion groups, you know t hat perform ance t ends t o slow down as libraries grow in size.
You can check t he size of your iPhot o library by following t his pat h: Macint osh HD
Users
Your Nam e
Pict ures iPhot o Library. Click once on t he folder t o highlight it , t hen choose Show I nfo from t he File - I ) . I f your library is approaching 650MB, burn it ont o a CD, t hen pull it out of your drop- down m enu ( or press Pict ures folder. The next t im e you launch iPhot o, it will creat e a brand- new library.
22.2.2 Tip #7: Use iPhoto Library Manager to switch between libraries. Brian Webst er's nift y piece of freeware enables you t o select t he iPhot o library you want t o view before you launch t he program . I f you have t hree different libraries on your hard disk ( each 650MBs or less! ) , t hen sim ply launch iPhot o Library Manager first and select t he library you want t o load, as shown in Figure 3- 14. You can download Brian's soft ware at ht t p: / / www.versiont racker.com . Figu r e 3 - 1 4 . Ch oosin g a n iPh ot o libr a r y w it h iPh ot o Libr a r y M a n a ge r
I recom m end t hat you keep all your iPhot o libraries in your Pict ures folder. I give each library a descript ive nam e such as iPhot o Library ( Vol 2) t o help m e keep t rack of t hem . I also like t o put a ~ at t he beginning of t he filenam e, so t he iPhot o libraries show up at t he t op of t he window when I open m y Pict ures folder in list view.
22.2.3 Tip #8: Create custom albums for better organization and retrieval. Not only will t his help you m anage your pict ures wit hin iPhot o, but it also forces t he applicat ion t o creat e readable dat a t hat can be ret rieved by CD- cat aloging applicat ions. Figure 3- 15 shows a select ion of iPhot o album s.
Figu r e 3 - 1 5 . iPh ot o a lbu m s
To creat e an album in iPhot o, j ust click t he + but t on in t he lower- left corner.
By creat ing cust om album s in iPhot o, you force t he applicat ion t o creat e dat a t hat can be ret rieved quickly by cat aloging applicat ions such as CDFinder. Over t im e, you'll probably end up wit h dozens of iPhot o libraries st ored on dozens of CDs. I f you use cat aloging soft ware such as CDFinder ( ht t p: / / www.cdfinder.de/ ) , it will capt ure all of t hose album nam es you creat ed wit hin each iPhot o library ( see Figure 3- 16) . When you need t o find out which CD ( iPhot o library) a group of phot os resides on, such as European Vacat ion 2001, t hen j ust use t he Find com m and in your CD- cat alog program , and it will t ell you which iPhot o library cont ains t hose im ages. Figu r e 3 - 1 6 . CD Fin de r in a ct ion
22.2.4 Tip #9: Duplicate photos before editing. When preparing a pict ure in iPhot o for print ing or ot her specific out put , you m ay want t o duplicat e it before you st art edit ing. This allows you t o keep t he prist ine, original im age for fut ure use right beside t he edit ed version. To duplicat e a phot o, click on t he t hum bnail once t o highlight it , t hen press
- D or choose File
Duplicat e.
I f you forget t o duplicat e and want t o rest ore an edit ed phot o back t o it s original st at e, you can select File Revert t o Original.
22.2.5 Tip #10: Add titles to important photos. Digit al cam eras are user- friendly in m any ways, but t he files t hey produce are not . iPhot o can help you creat e logical nam es for your pict ures t hat replace t he alphanum eric syst em t he cam eras use. This funct ionalit y is part icularly nice for im ages t hat you want t o export for ot her uses out side of iPhot o, such as creat ing web pages, em ail at t achm ent s, and CD libraries.
First , click once on t he iPhot o t hum bnail t o highlight it , t hen ent er t he inform at ion you want t o use as t he filenam e in t he Tit le field, as shown in Figure 3- 17. You have t o ent er each phot o's t it le individually unless you want t o opt for one of iPhot o's bat ch opt ions: Roll I nfo, File Nam e, or Dat e/ Tim e. To use one of t hese labels t o replace t he exist ing filenam es for an ent ire bat ch of phot os, Shift - click all t he im ages you want select ed, and choose Set Tit le To under t he Edit drop- down m enu. Figu r e 3 - 1 7 . Addin g a de scr ipt ive t it le t o a ph ot o
Most likely t hough, you're going t o want t o add filenam es t hat are m ore descript ive, such as Eiffel Tower, Big Ben, or Crazy Taxi Driver. I n t hat case, highlight t he t hum bnail, ent er t he descript ive nam e in t he Tit le field, and press t he Ret urn key. You m ay want t o enlarge t he size of your t hum bnails using t he slider bar on t he lower- right side of iPhot o's applicat ion window. This will m ake it easier t o ident ify t he pict ure. Once you have all of your new t it les ent ered t he way you want t hem , creat e a new album ( by clicking on t he + key in t he lower- left side of iPhot o and drag all t he newly nam ed im ages int o t he album . Then click once on t he album t o highlight it , and click on t he Share but t on t o reveal t he Export icon in t he lower- right corner of iPhot o. Click on Export and choose File Export from t he t abbed dialog box. I n t he File Export dialog box, be sure t o click on t he Use Tit les radio but t on under Nam e. Once you've decided t he ot her param et ers you want , click t he Export but t on. iPhot o will ask you where you want t hese im ages placed on your hard drive. Navigat e t o t he desired folder, click OK, and iPhot o) will export t he ent ire album and include t he nam es you wrot e in t he Tit le field as t he new filenam es for t he pict ures. Now here's som et hing really cool: if you want t o build an iPhot o library t hat has all descript ive filenam es for your JPEGs, and t hen include t hem in your Tit le field t oo, follow t hese easy st eps: 1. Creat e a fresh iPhot o library as described in Tip # 6. 2. Choose I m port from t he File m enu. 3. Navigat e t o a folder wit h renam ed im ages.
4. I m port t he ent ire folder. All of your pict ures will ret ain t heir descript ive filenam es in iPhot o, and t hose nam es will also be displayed in t he Tit le field.
Edit or's not e: Since t he t im e of t his writ ing, Apple has released it s m uch- ant icipat ed upgrade, iPhot o2. Nevert heless, all of t he inform at ion in t his hack st ill holds t rue. For a quick run- down of som e of t he changes, upgrade guidelines, and init ial im pressions, see " iPhot o — I t 's Most ly Good News" ( ht t p: / / www.oreillynet .com / cs/ weblog/ view/ wlg/ 2691) .
—Derrick St ory
[ Team LiB ]
[ Team LiB ] Hack 23 Make Your Own Documentary
Usin g on ly digit a l ph ot ogr a ph s, m u sic, a $ 1 0 a pp, a n d w h a t t h e iApps pr ovide , you ca n pu t t oge t h e r a r a t h e r n ice docu m e n t a r y. A lot has been going on in t he video indust ry lat ely. Em m y winner and m ast er of t he docum ent ary film , Ken Burns, has rereleased a digit ally rem ast ered copy of his epic film The Civil War. The Digit al Hollywood conference has com e and gone. And som eone nam ed Chris Meyer has released a $10 applicat ion called Phot o t o Movie ( ht t p: / / lqgraphics.com / soft ware/ phot ot om ovie.ht m l) , which I consider a m ilest one in video product ion.
Edit or's not e: Apple's newly released iMovie3 act ually incorporat es m uch of t he funct ionalit y of Phot o t o Movie as a " Ken Burns Effect ." St ill, Phot o t o Movie offers m ore cont rol over m ovem ent and key fram es.
Basically, t his sm all app ( approxim at ely 1MB) allows you t o t ake a phot o or im age and do a panning m ot ion effect across it ( Pan & Scan) , a la Ken Burns. This caused m e t o have a st range t im e- warp experience; all of a sudden I t hought about m y old st udio. I rem em bered edit ing video and doing anim at ion on m y $100,000 Mac Media 100 workst at ion ( wit h a $15,000 10GB drive array, $20,000 in soft ware, a blazing fast 8100 running at 110MHz, an unheard- of 256MB of RAM, et c.) . Then it dawned on m e t hat I can now do m ore advanced video work t han I could wit h t hat syst em , wit h a $1,600 lapt op and a $9.95 program . Heck, you don't even need a video cam era t o use iMovie. Thanks t o Apple, m ore and m ore people are exploring digit al video, but I wasn't sure if people realized how far we've com e in such a short t im e. The whole art form has been liberat ed and sim plified. I recent ly set up a Bryce server farm in m y house t o render anim at ion bet ween t hree Macs and a PC. I t t ook about 30 m inut es of set up t im e. Six years ago, t hat t ype of com put ing power would have been nearly im possible wit hout several SGI m achines and $1,000,000. Apple has opened t he door t o new film m akers who have no idea how lucky t hey are. Anyway, Phot o t o Movie inspired m e t o experim ent wit h m aking a docum ent ary m ovie. And alt hough I can't prom ise t hat our work will ever m easure up t o t hat of Mr. Burns, it doesn't m ean we can't aspire t o do great work! This is not a highly t echnical piece on edit ing video. This is j ust a fun exercise t o get your feet wet .
23.1 What You'll Need ● ● ● ● ● ● ●
Scanner or digit al cam era iPhot o or Phot oshop iMovie Som e m usic A piece of freeware called Audio I n ( opt ional) Phot o t o Movie ( $9.95) St opwat ch or wat ch wit h second hand
●
A few spare gigs of drive space ( or an iPod)
23.2 Photos and Music When m aking our docum ent ary video, we need t o decide what it will be about . Rem em ber, video is st ory/ concept driven, so pick it em s t hat have a narrat ive t hread. I t hought t hat I would use som e phot os from m y childhood on t he farm . My first decision was about how m any phot os I planned t o use. Part of t his decision had t o do wit h t he lengt h of t he audio t rack. So, if you plan on set t ing your m ovie t o m usic, you need t o do a quick- and- dirt y calculat ion of t im e per shot . So, let 's get our audio piece lined up, shall we? As a source of audio, you can use any MP3 file or even pull a CD t rack right from your CD- ROM while in iMovie. I decided t o use an audio t rack from one of t he select ions up on iDisk. There is a folder in Soft ware Ext ras called FreePlay Music. I nside, you'll find hundreds of royalt y- free MP3 audio clips for use in your m ovies. The clips' lengt hs range from 10 seconds t o several m inut es.
I f you view t he t racks in colum n view, you can sam ple t he audio before you download.
Now, t ake t he lengt h of t he audio t rack and divide it by t he num ber of im ages you've select ed. My audio t rack was 2: 03, so I convert ed t hat t o seconds and dropped t he ext ra t hree seconds in order t o work wit h a sim ple num ber. Lat er, I could always fudge ( t rim ) t he lengt h of m y clips t o accom m odat e t he ext ra t hree seconds. I t ook 120 seconds and divided it by t he num ber of phot os I was using. I n m y case, I decided on six phot os, which gave m e 20 seconds per clip. Now, I know t hat 20 seconds doesn't sound like a lot of t im e, but go over t o your TV and count t o yourself for 20 seconds. How m any shot changes do you see in t he t ypical com m ercial?
23.3 Image Prep I scanned m y six phot os ont o one sheet . This saved m e a great deal of scanning t im e. I f you're using iPhot o, you can m im ic Phot oshop's edit ing abilit ies by im port ing t he im age several t im es and t hen cropping each copy or j ust scan individual phot os. Let 's not forget you can use any im ages for t his, not j ust scanned phot os. Let 's t alk about im age resolut ion for a m om ent . Lat er, when we get t o t he Phot o t o Movie applicat ion, we want t o avoid get t ing art ifact s in our video ( t he sam e goes for iMovie) , so when I scanned m y im age, I opt ed for a m inim um of 300 dot s per inch ( dpi) t o prevent unwant ed dist ort ions. You can get away wit h 72- dpi im ages for video, but when zoom ing in and out of an im age, it is best t o st art wit h a higher resolut ion. Since t he look of t he video we are t rying t o m im ic is t hat of a Ken Burns black- and- whit e docum ent ary, I decided t o alt er m y phot os by convert ing t hem t o grayscale ( change t hem t o Black and Whit e) , adj ust ing t he curves ( play wit h t he Bright ness and Cont rast , as shown in Figure 3- 18) , and adding som e grain and im perfect ions t o each im age. I didn't want t he phot os t o appear perfect , or t he illusion of t im e would be lost . Figu r e 3 - 1 8 . Alt e r in g a ph ot o's br igh t n e ss a n d con t r a st in Ph ot osh op
Go ahead and save t he file as a JPEG or Phot oshop file, and duplicat e t his process wit h each addit ional phot o.
23.4 Storyboard To save t im e, it is sm art t o plan out your m ovie before you begin t o edit it . For m e, I t ook t he original phot os and laid t hem out in t he order in which I want ed t hem t o appear. I f you are planning t o add narrat ion t o your m ovie, you m ay want t o t ake t his t im e t o writ e t he script t hat will go wit h each phot o, and t hen t im e how long it t akes for you t o speak it ( t his is where t he st opwat ch com es in handy) . You m ay want t o use lit t le st icky not es beneat h each im age ( and I 'm referring t o act ual pieces of paper) . I f you're using purely digit al im ages, you can insert t hem int o a Word doc, t ype t he t ext t here, and t hen print it out . Originally, I t hought of doing a narrat ion for m y m ovie, but I changed m y m ind because I t hought t he power of t he m usic and t he im ages would be dilut ed wit h words.
23.5 Photo to Movie I t is rare t o find an applicat ion t hat does what it should in such a sim ple and st raight forward way. And alt hough Phot o t o Movie is m issing a few feat ures ( which I hear are com ing) t hat , as a professional video edit or, I would like t o see, it does such a respect able j ob for t he price t hat I hardly m iss t hem . Begin by dragging your first im age int o t he im age well of t he applicat ion. You'll see t wo squares. The green square is t he st art fram e, or where your cam era is when t he m ovie begins. You can adj ust t he scale of t his fram e t o give t he illusion of zoom ing in a cam era lens. Move t he st art fram e t o where you want t he clip t o begin and t he end fram e ( t he red box) t o where you want t he clip t o end. Then set t he durat ion of t he clip; in Figure 3- 19, I set m ine t o 20 seconds.
Figu r e 3 - 1 9 . Ph ot o t o M ovie in a ct ion
A word about art ist ic int erpret at ion; since t he world of art is a subj ect ive one, I can't really t ell you how t o line up your cam era shot s for t his. I can, however, give you som e advice. I suggest t hat you place your end fram e at a point t hat holds som e significance or is t he m ost powerful point in t he im age. This is t he im age t hat your viewer will ult im at ely be left wit h. What ever you decide t o do, j ust rem em ber each im age will have it s own special m eaning, so t ry t o decipher t hat when m aking each clip. Once we've set t he st art and end fram es, we can preview t he clip by using t he Play but t on. I f we're happy wit h t he preview, we can go ahead and render t his clip.
23.6 Advanced Options Under t he File m enu, you'll find a m enu it em called Advanced Opt ions ( t his drops down a hidden drawer) . Here we have t he opt ion of changing t he durat ion of t he clip t o a m ore specific t im e fram e, but we also have som e cont rol over t he accelerat ion/ decelerat ion of t he clip and t he opt ion t o hold t he cam era at t he st art fram e/ end fram e for a period of t im e t o lend m ore im pact t o t he im age. For exam ple, say t he clip is set t o: ● ● ● ● ●
Durat ion: 20 seconds Accelerat ion: 10 seconds Decelerat ion: 15 seconds Hold st art : 2 seconds Hold end: 2 seconds
The cam era will first hold t he st art fram e in posit ion for 2 seconds. I t will go slow init ially, speeding up unt il 10 seconds int o t he clip, t hen t rack over t he im age at t he sam e rat e unt il 15 seconds int o t he clip. Finally, it will slow down unt il it reaches t he end fram e, where it will st op and hold for 2 seconds. For m y own im ages, I went ahead and select ed a four- second hold at t he st art fram e, no hold on t he end fram e, and no accelerat ion or decelerat ion. I have plans t o use a cert ain t ransit ion ( cross- dissolve) in iMovie, so holding t he cam era at t he end fram e won't be necessary. Once you are happy wit h t he clip, go ahead and click Make Movie ( see Figure 3- 20) . Nam e t he video clip and save it t o a locat ion, such as t he Movies folder. Be careful t o select t he DV St ream form at , and if you live in Nort h Am erica, select NTSC as t he Video St andard. Finally, if t his video is going t o t ape, you should select high- qualit y rendering. Figu r e 3 - 2 0 . M a k e M ovie
23.7 Narration I decided t o skip a narrat ion, but I want t o discuss a few point s for t hose t hat decide t o use it . There are a few ways t o record your narrat ion; one solut ion is t o record t he audio direct ly int o iMovie, as shown in Figure 3- 21. Figu r e 3 - 2 1 . Re cor din g a u dio dir e ct ly in t o iM ovie
I f you t ake a peek in t he iMovie applicat ion, you'll see a but t on called Audio. Here you'll find a line- level m et er and, if your m icrophone is connect ed, you m ay see t he m et er spike as it det ect s sound. The problem wit h recording here is t hat you m ay run int o a problem of iMovie having difficult y recording audio because of disk speed. I t m ay not be able t o keep up. I f t his happens t o you, you'll need anot her t hird- part y solut ion t o record your audio. A good free solut ion, called Audio I n, can be found on VersionTracker. The int erface needs som e work, but t he price is right and it does a respect able j ob. I recorded a few sam ples and found t hat iMovie wouldn't recognize t he AI FF form at of t he Audio I n files. I 'm not sure why t his is, but in case t his happens t o you, I have a fast workaround. When you record your narrat ion t racks wit h Audio I n, it saves t hem t o t he deskt op. Drag t he files int o t he Library of iTunes. Then, from iTunes, select Advanced
Convert Select ion t o MP3. Then j ust export t he MP3 file t o a folder.
23.8 iMovie, You Movie St ep one is t o locat e and im port all of t he video clips we m ade wit h Phot o t o Movie, and let 's not forget our audio t racks ( see Figure 3- 22) . Figu r e 3 - 2 2 . I m por t in g vide o a n d a u dio t r a ck s in t o iM ovie
Drag t he im port ed clips down t o t he t im e line in t he order in which you would like t hem t o appear. I suggest you use t he t ab wit h t he lit t le eyeball ( as shown in Figure 3- 23) , which gives you a visual represent at ion of t he st ory narrat ive. Figu r e 3 - 2 3 . Addin g t r a ck s t o t h e t im e lin e
23.9 Transitions
A t ransit ion is t he change from one scene t o t he next . I t can be a st raight cut or an effect . I n iMovie, t he t ransit ions are effect s t hat bring t wo different scenes t oget her. You don't have t o use t ransit ions; good exam ples of som e of t he best st raight cut s ever can be found in t he m ovie Lawrence of Arabia. I n one scene, Lawrence has a lit m at ch in his fingers and t he m om ent he blows it out , t here is a st raight cut t o t he sun rising in t he desert . St unning! However, t ransit ion effect s can add a lot of subst ance t o t he im ages. The t rick when using t ransit ions in a short piece is using t hem sparingly and lim it ing t he variet y. I n publishing, t he rule of t hum b is t o lim it your font choice; t he sam e applies here. One of m y biggest pet peeves when I see a PowerPoint present at ion is when som eone has used every available t ype of t ransit ion. Som et im es, less is m ore. I used t hree t ransit ions in m y m ovie. The first , fade in, was applied at t he beginning of t he first clip. I t gave m e a nice, slow ent ry int o m y m ovie, which fit t he st yle of t he m usic. The second t ransit ion, cross- dissolve, was used bet ween each pair of clips. One of m y favorit es, t his t ransit ion dissolves one clip out while fading t he next clip in. The blend of t he t wo clips has a nice, soft , and soot hing feeling. Finally, m y last t ransit ion was at t he end of t he m ovie. I used a fade out j ust as t he last chord of m usic st art ed t o fade.
23.10 Can I Have the Envelope, Please? The whole point of t his hack was t o give you som e sense of t he power you have right t here in your com put er. You don't need t he best equipm ent and you don't need a $1,000 video cam era t o get som e value out of iMovie. A scanner or digit al cam era, a $10 shareware app, and an OS X Mac, and you're m aking m ovies. I n t ot al, t his m ovie t ook approxim at ely one and a half hours t o com plet e, and by using t he video out on m y iBook, I was able t o t ransfer it t o VHS wit h very lit t le effort .
23.11 See Also ●
●
An I nt roduct ion t o iMovie ( ht t p: / / www.m acdevcent er.com / pub/ a/ m ac/ 2002/ 10/ 11/ im ovie.ht m l) by N.D. Woods iMovie 2: The Missing Manual ( ht t p: / / www.oreilly.com / cat alog/ im oviem m 2/ ) by David Pogue
—Alan Graham
[ Team LiB ]
[ Team LiB ] Hack 24 From Slideshow to Video Presentation
M a k e a slide sh ow in t o a vide o pr e se n t a t ion u sin g t h e com bin e d pow e r of iM ovie , iPh ot o, a n d iTu n e s. The so- called m edia iApps — iMovie, iPhot o, and iTunes — act ually form an ad hoc int egrat ed developm ent environm ent ( I DE) for creat ing digit al cont ent . You probably didn't realize t his because Apple's m arket ing focus t o consum ers is sim plicit y, not int egrat ed environm ent s. But t here's cert ainly m ore t o t he iApps t han init ially m eet s t he eye. This hack shows you how t hese com ponent s work t oget her by m aking an iPhot o slideshow int o a full- fledged video present at ion. All you need is a decent digit al cam era, a st ack of m usic CDs, and Mac OS X.
24.1 Using Just One Leg of a Three-Legged Stool During a recent iPhot o workshop, I learned t hat m any of t he part icipant s hadn't opened iMovie or played m uch wit h iTunes. When I asked, " Why not ?" I heard responses such as, " I don't own a DV cam corder or an iPod, so why would I need t hose apps?" I realized t hat m any creat ive people have been influenced by Apple's consum er m arket ing t hat aim s t o keep t hings sim ple in order t o appeal t o t he great est num ber of pot ent ial cust om ers. But t he iApps are bet t er t han t hat . Beneat h t heir t ant alizing GUI lurk powerful t ools capable of producing professional qualit y m edia, especially when used as a group. So, let 's t ake a look at how t o get som e serious work done wit h t his t rio of digit al m edia program s.
24.2 Get Your Toolbox in Order I f you don't have Jaguar ( 10.2) yet , t hat 's j ob num ber one. You need all t he perform ance you can get when working wit h digit al m edia, and Jaguar is t he best Apple has t o offer. Next , m ake sure you have iMovie, iTunes, and iPhot o accessible, because you'll be opening t hem a lot . I keep t hem in t he Dock. Put t hem wherever you want , but m ake sure t hey're easy t o get t o. I f you haven't upgraded t o QuickTim e Pro, Version 6 ( ht t p: / / www.apple.com / quickt im e/ download/ ) , now's t he t im e t o do it . The player version is fine for playback, but you'll need t he pro t ools t o do serious work. And for $29.95, it 's not a bad deal, especially since t he iApps com e bundled wit h t he operat ing syst em . Finally, you m ay want t o grab a couple of enhancem ent applicat ions t o expand t he capabilit ies of t he m edia iApps. Here are m y favorit es: BBEdit ( ht t p: / / www.barebones.com / product s/ bbedit _lit e.ht m l) ( Lit e Version 6.1 is free) Serious Mac power users t ypically have t he full version of t his versat ile t ext edit or. I f you haven't
snagged your own copy yet , you can use t he free version unt il you're ready t o upgrade. This t ool is necessary for edit ing code for t asks such as em bedding QuickTim e m ovies int o web pages. PixelNhance im age edit or ( ft p: / / ft p.cs.unm .edu/ pub/ st one/ St oneSt udio/ CaffeineApps.dm g) ( free) I t 's like t he folks at Caffeine Soft ware looked at iPhot o and creat ed an applicat ion t o fill it s gaps. You'll need t his freebie for sharpening, color adj ust ing, and levels cont rol. iPhot o Library Manager ( ht t p: / / www.versiont racker.com / m oreinfo.fcgi?id= 13532&db= m ac) ( free) This applicat ion enables you t o creat e m ult iple iPhot o libraries, st ore t hem on hard drives, t hen swit ch bet ween t hem as necessary. I t gives iPhot o t he flexibilit y you need for m anaging t housands of pict ures wit hout bogging down t he applicat ion. CDFinder ( ht t p: / / www.cdfinder.de/ ) ( shareware) This nift y applicat ion allows you t o cat alog t he archive CDs and ext ernal drives where your collect ion of iPhot o libraries and ot her m edia reside. I f you can't rem em ber in which iPhot o library t he NY Tim es Square im ages reside, CDFinder will help you locat e t hem .
24.3 How the iApps Can Work Together Now it 's t im e t o look at how t he iApps can work t oget her. First , let 's explore t he t wo dat abase applicat ions: iTunes and iPhot o. This is where your m usic and st ill im ages are st ored and organized. You can t ap t hese dat abases from ot her applicat ions or t hrough t he Finder. I f you configure t hem properly, you can easily find t he cont ent you're looking for when you're out side t he cozy confines of t he applicat ion int erface. What do I m ean by t his? Let 's say you want t o find a song in iTunes t o accom pany a slideshow ( as we're going t o do lat er in t his hack) . I f all of your songs in iTunes have t heir dat abase records com plet ed ( art ist , album , song, et c.) , t hen you'll be able t o find what you're looking for quickly when searching your m usic DB via iPhot o ( yes, iPhot o can t alk t o iTunes) or when looking for a part icular t une via t he Finder. I f you haven't com plet ed t hose iTunes records, t hen all you'll see is Unknown Art ist and Track 01 — not m uch help. More on t his lat er. I 'm assum ing t hat you have dat a in iTunes and iPhot o. I f you haven't used t hese t wo program s m uch, go upload som e pict ures and rip a few CDs so you have m edia in t here t o play wit h. You'll be surprised at how oft en you'll t ap t his inform at ion aft er it 's in t here. Once you have cont ent in your dat abases, t hen you can use QuickTim e Pro, iMovie 2, and BBEdit t o assem ble and enhance your m edia. The basic process looks like t his: 1. Upload m usic and im ages int o t he dat abase apps ( iPhot o and iTunes) . 2. Organize t he cont ent and m ake sure t he dat abase records t hat accom pany t he m edia are accurat e. 3. Out put raw cont ent from t he dat abases. 4. Assem ble and enhance t he raw cont ent wit h iMovie, QT Pro, and BBEdit .
5. Share t he finished product wit h coworkers, client s, friends, and fam ily. Obviously, t here are m any variat ions on t his t hem e of iApps working t oget her. I f you're shoot ing digit al video, for exam ple, you m ay t hink you never have t o leave t he iMovie environm ent . But what if you want t o im port st ill im ages int o your m ovie ( iPhot o) ? How about adding m usic ( iTunes) ? Why cont inue t o shuffle t hrough m usic CDs when you have your ent ire library sit t ing t here in iTunes? Once you underst and t he iApp relat ionships, you'll find t hat you can creat e bet t er product ions in less t im e, regardless of which m edium you're prim arily working in. To work wit h t his exam ple, you'll need a decent digit al cam era and som e good m usic on a CD. We're going t o build a bet t er slideshow. iPhot o enables you t o export pict ures and m usic t o QuickTim e, but t he final product is a lit t le rough around t he edges. By enhancing t he core slideshow wit h iMovie, iTunes, and QT Pro, you can t ransform your hum ble iPhot o slideshow int o a polished present at ion. Aft er a few m inut es of work, you'll see how t he iApps funct ion as a full- fledged developm ent environm ent . This is only one scenario. There are m any ot her excit ing ways t o use t hese t ools. So, let 's st art by digging int o t he t wo dat abase applicat ions: iTunes and iPhot o.
24.3.1 iTunes I probably don't have t o say t his, but you need t o have a good variet y of m usic in your iTunes library. So, t ake a st ack of your favorit e CDs and rip t hem . Before doing so, however, rem em ber t wo t hings: ●
●
Encode at 192 kbps t o capt ure as m uch fidelit y as possible. You can always sam ple down specific t racks lat er if you need t o reduce t heir size. But in t erm s of file size, m usic t racks are act ually relat ively sm all com pared t o video and im ages. There's no need t o scrim p on sound qualit y unless you're serving on t he Web, which is a different anim al alt oget her. Connect t o t he I nt ernet before ripping. Prior t o encoding your CD t racks, go t o t he Advanced m enu and select Get CD Track Nam es. By doing so you'll populat e all t he vit al dat a fields associat ed wit h your m usic including song t it le, art ist , and album . Rem em ber, iTunes is your m usic dat abase. I f you're t o use it efficient ly, you need t o have your records filled out properly. This is t he easiest way t o do so. You'll see how t his plays out soon.
When you first load a CD in iTunes, you see only t he m ost basic dat a, such as Track 01. I f you were t o rip t he m usic at t his point , you wouldn't have m uch dat a t o accom pany t he MP3 files, which m akes it difficult t o use t hem out side of iTunes lat er on. I f you're online, you can access t he CDDB resource t o aut om at ically populat e t he im port ant fields in your songs' dat abase records. Select Advanced in for you.
Get CD Track Nam es t o have t hem filled
Now, aft er accessing t he CDDB, you have m uch richer song records, as shown in Figure 3- 24. iTunes will use t his inform at ion t o build a logical folder st ruct ure on your hard drive ( as long as you have " Keep iTunes m usic folder organized" checked in t he Advanced preferences) . Figu r e 3 - 2 4 . CD in iTu n e s sh ow in g r ich e r son g r e cor ds
24.3.2 iPhoto Now it 's t im e t o get your im age dat abase in order. As wit h iTunes for m usic, t here are a few det ails t o t end t o when populat ing your dat abase t hat will m ake your workflow sm oot her lat er on: ●
●
●
●
●
Capt ure your im ages at high qualit y and full resolut ion. I don't m ess m uch wit h saving pict ures in TI FF or Raw form at s because t hey are unwieldy ( even t hough t he qualit y is great ! ) , but I do recom m end t hat you use t he highest qualit y JPEG set t ings. You want t he best dat a possible in your iPhot o libraries, because you never know how you're going t o want t o use t hat inform at ion down t he road. Check your cam era's dat e and t im e set t ings t o m ake sure t hey are correct . When you capt ure a pict ure, your cam era also writ es valuable m et adat a t o t he file header. But your set t ings have t o be on t arget for t his inform at ion t o be accurat e. For m ore inform at ion about t he value of pict ure m et adat a, see " Use Met adat a t o I m prove Your Pict ures" ( ht t p: / / www.m acdevcent er.com / pub/ a/ m ac/ 2002/ 11/ 14/ phot o_m et adat a.ht m l) . Creat e descript ive cust om album s in iPhot o t o organize your various shoot s. Every t im e you creat e one of t hese cust om album s, iPhot o writ es valuable dat a t o your library file. This dat a m akes it easy t o search specific im ages across m any libraries and will save you lot s of t im e as your im age collect ion grows. When you nam e your iPhot o album s, t hink in t erm s of keywords, such as Paris Vacat ion 2000, Annie's Graduat ion 1999, or Sout hwest I m ages 2002. Keep your iPhot o libraries t o 650 MBs or less. Use iPhot o Library Manager t o swit ch bet ween libraries as needed. By lim it ing t he size of your libraries, iPhot o will perform bet t er and you can easily archive your im ages t o CD. Add descript ive inform at ion t o t he Tit le and Com m ent s fields. Again, t he t im e you spend adding dat a t o t his im age record will com e back t o you posit ively in t he fut ure when you're t rying t o find in which iPhot o library t hose im ages reside.
iPhot o also let s you add valuable dat a t o your digit al cont ent . The four key areas are: cust om album s ( e.g., Tues Uploads in Figure 3- 25) , Tit le, Dat e, and Com m ent s. When you add inform at ion in t hese record fields, iPhot o st ores it in t he iPhot o library wit h t he im age files. Now you can search for im ages across m any iPhot o libraries using cat alog apps such as CDFinder. Figu r e 3 - 2 5 . Adde d da t a a ssocia t e d w it h a pict u r e in iPh ot o
24.4 Working Example: Use iMovie and iTunes to Add Professional Touches to Your Still Images One of t he m ost powerful m et hods I have for present ing st ill im ages is t he QuickTim e slideshow. The pict ures seem t o com e t o life as t hey are organized by st ory line and accom panied by m usic. For exam ple, in m y phot o business I now show t hese t wo- m inut e shows at t he beginning of wedding appoint m ent s before I hand over t he act ual print s. The com binat ion of pict ures and m usic t elling t he st ory of t heir m arriage m akes a t rem endous im pact on client s, and t he rest of t he appoint m ent always seem s t o go well. But like everyt hing else good in life, t here's an art t o m aking a persuasive present at ion, whet her it be for client s, coworkers, friends, or fam ily. My best slideshows use iPhot o t o creat e t he core present at ion, iTunes for t he m usic, iMovie for t he t it les, and QuickTim e Pro t o st it ch everyt hing t oget her. I 'm going t o breeze t hrough a couple of t echniques t o give you a feel for how t hese apps can cooperat e wit h one anot her. I f you don't have experience working in iPhot o, iMovie, and QuickTim e Pro, you m ay wish t o refer t o m y t ut orials in t he Digit al Phot ography ( ht t p: / / www.m acdevcent er.com / pub/ a/ m ac/ collect ions/ iphot o.ht m l) and QuickTim e and iMovie ( ht t p: / / www.m acdevcent er.com / pub/ a/ m ac/ collect ions/ qt _im ovie.ht m l) collect ions on MacDevCent er.com .
24.4.1 Create opening titles in iMovie St art by export ing your core slideshow from iPhot o t o QuickTim e. ( Highlight t he album t hat cont ains t he fram es for your slideshow, click t he Share but t on, t hen click on Export , t hen select t he QuickTim e t ab.) At t his point , you don't need t o export t he m usic wit h t he slides, even t hough I usually include it so I have a feel for t he raw present at ion. You'll act ually end up adding a different soundt rack lat er in t his process. Here's where iMovie com es in handy for t his proj ect : t o build your opening t it le for t he slideshow you creat ed in iPhot o and export ed t o QuickTim e. Open iMovie and creat e a new proj ect . Then build your opening t it le using t he
Tit les palet t e, shown in Figure 3- 26. This is an am azing t ool. Even t hough you can creat e j ust about any opening sequence possible using Tit les in iMovie, keep it sim ple for now. Figu r e 3 - 2 6 . Th e iM ovie Tit le s box is a gold m in e for digit a l m ovie m a k e r s
Once you have an opening t hat you like, you need t o render it by dragging it from t he Tit les work area t o t he Clip Viewer bar at t he bot t om of t he iMovie int erface. iMovie will now t ake a few seconds t o build your opening sequence.
Export your sequence by choosing File Export Movie. Then select To QuickTim e, and choose Expert in t he Form at drop- down m enu. Here's where you set a few param et ers, such as dim ensions, com pression, and fram e rat e. Make sure your sequence has t he sam e dim ensions as t he core slideshow you creat ed in iPhot o, usually 640 x 480 or 320 x 240. Phot o JPEG is a good com pression set t ing, and 12 or 15 fps will do for fram e rat e. Click OK, t hen Export . You now have a QuickTim e opening sequence for your iPhot o slideshow. This is where you need QuickTim e Pro t o st it ch t hem t oget her. You're going t o select t he ent ire cont ent s of your core slideshow ( export ed from iPhot o) , copy it , t hen add it t o t he opening sequence you creat ed in iMovie, t hen export ed t o QuickTim e. Click on t he core slideshow, t hen grab it s cont ent by choosing Select All, t hen Copy. Now click on t he opening sequence m ovie and select Add. QuickTim e will add t he core slideshow t o wherever you have t he playback
indicat or posit ioned. I n t his case, it should be at t he end of t he clip. Now you have a slideshow wit h an opening sequence. I f you have QuickTim e Pro, you can st it ch various QT clips t oget her by copying t he clip from one player, t hen adding it t o t he ot her ( Don't use Past e, or one clip will replace t he ot her! ) . I n Figure 3- 27 I 'm adding t he soundt rack I export ed from iMovie t o m y QuickTim e slideshow. Figu r e 3 - 2 7 . Addin g t h e sou n dt r a ck t o m y Qu ick Tim e slide sh ow
You can creat e as m any sequences as you want in iMovie and add t hem t o your QuickTim e present at ions. I usually st ick wit h opening and closing t it les, but I 'm not lim it ed t o t hem .
24.4.2 Fine-tune your music track Once you have all of your im age sequences st it ched t oget her, it 's t im e t o add t he soundt rack. You probably want t o clean out any exist ing soundt racks in your present at ion. This is easy in QuickTim e Pro. Go t o Edit and select Delet e Tracks. You'll see a num ber of video t racks ( don't t ouch t hose! ) and a couple of soundt racks. Delet e all of t he soundt racks. Not e t he lengt h of your m ovie. Hopefully it 's not longer t han a couple of m inut es. Now open iMovie again and
select I m port File from t he File m enu. Navigat e t o your Music folder where iTunes keeps all of your audio asset s. I f you've been conscient ious about filing out your song records, t hen you'll see a list of folders by art ist , wit h t heir respect ive album s inside. But it get s even bet t er. Open t he album folder, and you'll see all of t he MP3 files wit h t he song t it les as t he filenam es. Sweet . I m port t he song you want t o use for your present at ion int o iMovie where it will be placed on t he audio port ion of t he Clip Viewer. Move t he endpoint s of t he t rack t o m ake it t he sam e lengt h ( or a t ad short er) t han your slideshow. ( For exam ple, if your slideshow is 2 m inut es long, t hen you m ight m ove t he audio endpoint s t o creat e a m usic t rack t hat is 1 m inut e, 55 seconds in lengt h.) Then, check t he Fade I n and Fade Out boxes so your m usic doesn't begin and end abrupt ly. Fade Out is especially im port ant and wort h using iMovie j ust for t hat funct ion. Now export your edit ed m usic t rack t o QuickTim e j ust as you did your t it le clip. I usually choose no com pression for m y m usic unless I plan on serving it on t he Web. When you open t he m usic t rack in QuickTim e, you'll see t hat it also has an unnecessary video t rack. Use Delet e Tracks t o get rid of it , t hen Select All, Copy, and Add t o your slideshow. Now you have a cust om soundt rack t hat is t he perfect lengt h for your show and fades at t he end. I f you want , you can add m any soundt racks at various point s t hroughout your present at ion. And, for t hat m at t er, you can add voiceover t oo.
24.5 Pulling It All Together Once you have your present at ion t he way you want it , save it as a self- cont ained m ovie. This will put all of your part s in one cont ainer t hat you can play off your hard drive, burn ont o a CD, or at t ach t o m ail ( if it 's not t oo big! ) . You can serve it on t he Web t oo, but t here are som e issues involved, such as com pression ( t o reduce download t im es) and aut horizat ion for t he m usic. You can bypass t hese issues for now by sharing your present at ions in person. Once you've finished your work of art , be sure t o use t he Save As com m and and click t he " Make m ovie selfcont ained" radio but t on, as shown in Figure 3- 28. By doing so, QuickTim e will place all t he m ovie elem ent s in one port able cont ainer t hat you can burn t o CD or share wit h friends. Figu r e 3 - 2 8 . Sa vin g a s a se lf- con t a in e d m ovie
Of course, t here are m any ways t o refine your present at ion, but even wit h t hese few sim ple t echniques, you can see how well t he iApps work t oget her and what great pot ent ial t hey have as a harm onious group. —Derrick St ory
[ Team LiB ]
[ Team LiB ] Hack 25 Hijacking Audio from Mac Apps
Au dio H ij a ck gr a bs t h e a u dio ou t pu t of a n y M a c OS X Cocoa or Ca r bon a pplica t ion for you r list e n in g ple a su r e . Rogue Am oeba's Audio Hij ack ( ht t p: / / www.rogueam oeba.com / audiohij ack/ ) , as it s nam e suggest s, hij acks t he audio of any Mac OS X applicat ion for doct oring and recording. Billed as an audio enhancer wit h DSP effect s and an equalizer t o beat all ot hers, it 's t he audio recording t hat 's of m ost int erest t o m e. Figure 3- 29 shows t he Audio Hij ack int erface. Figu r e 3 - 2 9 . Au dio H ij a ck in t e r fa ce w it h e qu a lize r
Launch Audio Hij ack, select a t arget applicat ion, and launch it wit h t he Launch but t on. Audio Hij ack will at t ach it self — t his is why you m ust launch t he t arget app from t he inside — and pass t hrough all sound generat ed by t he app. You can begin and end recording at any t im e using t he St art Recording/ St op Recording but t on. You can forego set t ing a m axim um durat ion if you're not sure what it should be, but I found set t ing it and let t ing it record unat t ended far m ore relaxing t han rem em bering t o check back every so oft en for fear of t he audio filling up m y hard drive. Click t he DSPs but t on and you can apply all m anner of sound effect s t o t he sound out put and recording. Add flange or reverb, alt er t he bass and t reble levels, display a pair of VU m et ers, or t reat yourself t o a 10- band equalizer wit h savable preset s, as shown in Figure 3- 29. A friend point ed out t hat Audio Hij ack is t he perfect ut ilit y for recording live audio st ream s delivered via Real Audio. The applicat ion's t im ers act as an audio VCR of sort s, launching Real Audio and recording for a specified am ount of t im e. Drop t he recording of NPR's All Things Considered ont o iTunes and sync wit h your iPod, and you have your favorit e public radio on dem and and port able. Finally, I can grab t he audio t racks from m y yoga class video, allowing m e t o t ake m y pract ice anywhere m y iPod
goes. Audio Hij ack is available for a 15- day free t rial, aft er which it 's only $16 for a fully licensed version.
[ Team LiB ]
[ Team LiB ] Hack 26 Running Your Own Web Radio Station
Cr e a t e pr iva t e pla ylist s you ca n st r e a m 2 4 / 7 t o a lm ost a n y w e b- e n a ble d de vice , in side or ou t side t h e h om e . I f you've been paying at t ent ion t o what 's happened wit h t he deregulat ion of t he airwaves, you m ay have not iced t hat m ost of t he dial is owned by a few m edia conglom erat es t hat cont rol m ost of what you hear. Many of us t urned t o t he I nt ernet t o find a t ast eful alt ernat ive t o all of t he FM noise. And while t he fut ure of webcast ing is current ly t ied up in t he m uck of figuring out fair m usic licensing fees, t here is no doubt in m y m ind t hat t he I nt ernet is t he last bast ion for m usic. I f t he idea of having your own radio webcast , for fun or profit , int rigues you, t hen you've com e t o t he right place. Even if you don't plan on sharing your m usical t ast es wit h t he world, you can have a lot of fun creat ing privat e playlist s you can st ream 24/ 7 t o alm ost any web device in your hom e. Or m aybe you j ust want t o be able t o t une int o your m usic anywhere, anyt im e, on any m achine. Well, guess what ? You've probably got m ost of what you'll need sit t ing on your hom e m achine. Moreover, set t ing up your own st at ion is easy t o do and cost s not hing t o get running. What you'll need: ● ● ● ● ● ●
A DSL or cable connect ion Music ( MP3) QuickTim e St ream ing Server ( free from Apple's web sit e) Prom o m usic and m icrophone iMovie iTunes
26.1 Step 1: Calculate Bandwidth The first t hing you need t o do is calculat e t he adequat e server bandwidt h for your st at ion. I f you figure t o provide your st ream at t he sam e rat e t o all visit ors, t he basic calculat ion for t his ( via Apple's Knowledge Base) is t o m ult iply t he m axim um num ber of users you expect by t he bit rat e you plan t o st ream . So, for your own privat e use, if you plan on serving up t o t hree connect ions at 128 kbps over t he I nt ernet , you need an upload connect ion speed great er t han 384 kbps t o keep a st ut t er- free connect ion. I f you plan t o run your st at ion over a LAN connect ion ( st ream ing playlist s t o m ult iple t erm inals in your hom e) , you could probably sust ain as m any as 50 t o 60 connect ions on a 10Mbps net work ( not t aking net work t raffic int o considerat ion) . As you can see, if you plan on running a com m ercial or nonprofit st at ion for t he public, you'll need a fat pipe. A DSL or cable connect ion isn't fast enough t o support a lot of visit ors, but it is usually adequat e for serving your personal use. Before you st art st ream ing, be sure t hat it doesn't violat e t he service agreem ent wit h your I SP.
26.2 Step 2: Install/Configure QuickTime Streaming Server The next t hing you need t o do is download t he QT St ream ing Server ( QTSS) from Apple's sit e ( ht t p: / / www.apple.
com / quickt im e/ product s/ qt ss/ ) and inst all it . Once t he inst all is com plet e, you'll find t he inst aller placed an icon in your Applicat ions folder t hat looks like Figure 3- 30. Figu r e 3 - 3 0 . Apple 's QTSS icon
Since t he server can be configured and cont rolled t hrough a web browser, t his icon will always t ake you t here. Go ahead and configure t he server for t he first t im e wit h t he default s in place. You m ay need t o m ake som e adj ust m ent based on your own net work set t ings or personal preferences. Figures Figure 3- 31, Figure 3- 32, and Figure 3- 33 show various set t ings being changed in t he Set up Assist ant . Figu r e 3 - 3 1 . You r a dm in u se r n a m e a n d pa ssw or d
Figu r e 3 - 3 2 . Se t t in g a n a dm in ist r a t or pa ssw or d
Figu r e 3 - 3 3 . For m ost pe ople , a SSL con n e ct ion w on 't be n e ce ssa r y
The QTSS requires t hat you use one folder as t he m ain source of your m edia. Most people use iTunes and t he m usic is locat ed in t he Music folder. You m ay wish t o change t he default locat ion, because m oving all your m edia ( as shown in Figure 3- 34) isn't pract ical. The pat h t o your iTunes folder should resem ble t his: / Users/
yourusernam e/ Music/ iTunes/ iTunes Music. Figure 3- 35 shows a set t ing t hat could int erfere wit h Apache or ot her web servers running on your m achine. Figu r e 3 - 3 4 . Th e loca t ion of you r m u sic file s
Figu r e 3 - 3 5 . A se t t in g t h a t cou ld in t e r fe r e w it h Apa ch e or ot h e r w e b se r ve r s r u n n in g on you r m a ch in e
26.3 Step 3: Create a Promotional Spot Depending on t he level of professional spit and polish you want on your st at ion, you m ay want t o put t oget her a prom o spot t o let people know who you are. There is a really sim ple way t o pull t his off using som e royalt y- free iMovie m usic, a m icrophone, and iMovie. You can use som e of t he free m usic Apple provides in your iDisk, but of course you m ust have a .Mac subscript ion for t hat . I f you don't belong t o .Mac, all you really need is a short piece of m usic in MP3 form at , or you can skip t he m usic port ion of your spot com plet ely. Open iMovie and im port your m usic clip, t hen head over t o t he Audio t ab of iMovie ( shown in Figure 3- 36) and record t he vocals of your prom o spot . Since I don't have any call let t ers, I set t led for, " You're list ening t o O'Reilly Radio." Figu r e 3 - 3 6 . You 'll fin d t h e r e cor d bu t t on in t h e Au dio t a b
Drag t he m usic clip int o one of t he m usic t racks down below. Your vocal spot should already be wait ing for you. Then j ust m ove t he t wo t racks so t hat t hey fit t oget her in a m anner t hat sounds good t o you ( see Figure 3- 37) . Figu r e 3 - 3 7 . Fit t in g t h e a u dio t r a ck s t oge t h e r
Once you're done edit ing your audio t rack, export t he m ovie as QuickTim e. We need t o m ake som e changes t o our file as we export it . When you choose t o export t he file as QuickTim e, you'll get an opt ion t o alt er t he form at . Select t he Expert set t ing in t his m enu ( see Figure 3- 38) . Figu r e 3 - 3 8 . Se le ct Ex pe r t
Now click Prepare for I nt ernet
Quickt im e St ream ing Server ( see Figure 3- 39) . Figu r e 3 - 3 9 . Pr e pa r e for I n t e r n e t . . .
Finally, change t he com pression set t ings t o MPEG- 4 and export ( see Figure 3- 40) . Figu r e 3 - 4 0 . Ex por t in g a s M PEG- 4
You now need t o convert t he m ovie file from MPEG- 4 t o MP3 before you can use it wit h t he ot her m usic files. This is very easy. First open iTunes and drag t he file int o your library ( see Figure 3- 41) .
Figu r e 3 - 4 1 . Tim e t o e dit t h e pr om o son g in for m a t ion
The next st ep is t o edit t he prom o spot song inform at ion, so t hat when you convert t his file t o MP3, it will aut om at ically creat e a prom o folder where we can collect fut ure files. Sim ply highlight t he file and select File Get I nfo. At t he t op of t he window, t ype a t it le for t his spot , like Prom o Spot 1. Under Art ist , t ype som et hing like My Prom ot ional Spot s. I n t he Album field, nam e it Prom o Spot s, and now you have a folder in which t o place all fut ure prom o files.
To convert t he file t o MP3, highlight it and select Advanced Convert Select ion t o MP3. Now you can delet e t he old file from t he library and m ove on t o get t ing your st at ion up and running.
26.4 Step 4: QTSS General Settings Open t he server and j um p on over t o General Set t ings. Here we want t o double- check t hat our m edia direct ory m at ches our iTunes folder. You can set your m axim um num ber of connect ions and your m axim um t hroughput . Rem em ber t o calculat e your required bandwidt h. When your t raffic exceeds t he m axim um t hroughput , t he server will not allow any m ore connect ions. I f you want t o run t he server 24/ 7, check " St art Server at Syst em St art up," as shown in Figure 3- 42. Figu r e 3 - 4 2 . QTSS Ge n e r a l Se t t in gs
26.5 Step 5: Build a Playlist You can creat e playlist s using m ost t ext edit ors, but m ost people will find it easier t o creat e a playlist t hrough t he server's web int erface. Our m ain QTSS screen looks like Figure 3- 42. Jum p t o t he Playlist s link t o t he left . At t he Playlist s screen, click on t he but t on t o creat e a new MP3 playlist , as shown in Figure 3- 43. Figu r e 3 - 4 3 . Pla ylist
Creat ing t he act ual playlist ( see Figure 3- 44) is quit e sim ple, alt hough t here are a few quirks:
Figu r e 3 - 4 4 . Cr e a t in g t h e pla ylist
Nam e Ent er t he nam e of your st at ion: what ever nam e you ent er here will be displayed in t he client 's m usic player. Mount Point Part of t he URL locat ion t hat your users will use t o t une int o your st at ion. By ent ering different m ount point s for different playlist s, you could run m ore t han one act ive playlist for different genres and list eners could list en t o different t ypes of m usic. Genre
Sim ply t he genre of t he m usic. Play Mode The order in which t o play t he m edia. You can specify t he following opt ions: Sequent ial
Plays t he m edia in t he order t hey appear in t he playlist . When t he last file is done playing, t he broadcast st ops.
Sequent ial Looped
St ream s m edia in t he order it appears in t he playlist file. When t he last file is done, t he playlist rest art s in t he sam e order.
Weight ed Random
St ream s m edia in random , using t he specified weight s t o decide how oft en t o play an it em . The higher t he weight num ber, t he m ore t he it em is played. The m edia plays unt il you st op it .
Repet it ion Set s t he num ber of files t hat play before a file repeat s. Available Media Select t he t racks you want t o appear in your playlist and drag t hem over t o t he Playlist colum n ( labeled " 6." in Figure 3- 44) t o t he right . You can Shift - click it em s, but unfort unat ely you cannot - click t hem . You can ent er any folder in t he m edia list by double- clicking. Also in t his list ing you will find t he folder wit h your prom o spot s in it . Aft er creat ing your playlist , drag and drop your prom o spot s wherever you wish for it t o play. Log t his playlist 's act ivit y Select if you want t o keep a log of t his playlist s act ivit y. Save Changes Save your set t ings and we're alm ost ready t o t une in.
26.6 Step 6: Finish Up You have a few sm all it em s t o finish up before you are ready t o go. First , go back t o t he m ain Playlist s m enu using t he link t o t he left . Now, m ake sure t hat your QTSS is running by clicking t he St art but t on in t he upperleft hand corner ( see Figure 3- 45) . Figu r e 3 - 4 5 . Th e QTSS se r ve r is r u n n in g
Next , you need t o st art t he playlist . Click on t he Play but t on in t he Playlist window ( see Figures Figure 3- 46 and Figure 3- 47) . Figu r e 3 - 4 6 . Ju st pr e ss t h e bu t t on . . .
Figu r e 3 - 4 7 . N ot ice t h e ch a n ge in st a t u s . . .
26.7 Step 7: Tune In We've inst alled our server, creat ed our prom os, configured our server, built our playlist s, and st art ed our server. Now it is t im e t o t est our st at ion by t uning in.
Open up iTunes and select Advanced Open St ream ( - U) . Ent er your I P address or URL followed by t he port num ber and finally t he m ount point . I t should look som et hing like 19 2. 16 8 . 2. 9 : 8 0 00 / or e i l l y ( where t he I P address or URL is your own) . I f everyt hing goes well, you should hear som e t unes blast ing from your speakers.
26.8 Step 8: Administer Remotely
One handy feat ure of t he QTSS is rem ot e adm inist rat ion. You can m ake changes t o t he server or your playlist regardless of your locat ion. Access t he server by t yping your I P address or URL and specifying port 1220.
26.9 Step 9: Getting Help Apple has an ext ensive help file associat ed wit h QTSS. You can access it via t he server's int erface, but you can also find it here: ht t p: / / helpqt .apple.com / qt ssWebAdm inHelpR4/ qt ssWebAdm in.help/ English.lproj / QTSSHelp.ht m There are t ons of excit ing t hings you can do wit h t he QTSS and Mac OS X. St ream ing can be a com plicat ed t ask, but hopefully t his will get you st art ed. —Alan Graham
[ Team LiB ]
[ Team LiB ] Hack 27 Sharing Your Listening Preferences
iTu n e s a n d a lit t le h a ck e r y m a k e sh a r in g you r cu r r e n t ly pla yin g t r a ck a sn a p. List ening t o m usic while you work is a given for a large port ion of t he com put ing populace. Wit hout m usic, t he halls and cubicles seem a lit t le lonelier, t he days seem a lit t le slower, and eat ing is m ore lifeless t han usual. Music is a part of our com put ing lives, and being wit hout it can be t raum at izing. Just as we enj oy list ening, we also lust aft er m ore m usic t o whet our audit ory ensem bles. Hearing an unknown art ist , falling in love, and t hen orchest rat ing a search for MP3s or used CDs is a part of m any of our lives as well. Suggest ions from friends is a crucial part of our discovery process. Wit h iTunes, t elling people what you list en t o is easier t han you t hink. Ut ilit ies like t he donat ionware Kung- Tunes ( ht t p: / / www.kung- foo.t v/ it t i.php) publish inform at ion on your current ly playing iTunes t rack on your web sit e, allowing t he world t o t une in t o your m usical enj oym ent . Alt ernat ively, use t he freeware Moa Tunes ( ht t p: / / beam . t o/ woodenbrain) t o alt er t he signat ure of your Ent ourage or Eudora em ail m essages wit h t he m usic t hat accom panied your response. Even I nt er- Relay Chat ( I RC) program s are get t ing int o t he act , as t he shareware Snak ( ht t p: / / www.snak.com / ) provides a MusicalOSX script t hat will display t racks in I RC channels. I f t hat 's not enough, and you want iTunes int egrat ion wit h every inst rum ent you use daily, check out t he following piece of AppleScript , which will put t he current ly playing song, art ist , and album int o t he clipboard. Sim ply run, past e, and seduce!
t el l s et s et s et e nd t
a ppl i c a t i na me t i ar t i s t i a l bum el l
i o n " i Tu n e s " o n a me o f c u r r e n t t r a c k t o a r t i s t of c ur r e nt t r a c k t o a l bum of c ur r e nt t r a c k
t el l s et & i s et e nd t
a ppl i c a t mus i c t a l bu m & t he c l i el l
i o n " Fi n d e r " o " \ " " & i n a me & " \ " b y " & i a r t i s t & " o n t h e a l b um \ " " RETURN "\ ". " p b o a r d t o t h e mu s i c
Figure 3- 48 shows t he result of running t his script . Figu r e 3 - 4 8 . Pa ssin g on you r list e n in g pr e fe r e n ce s
I f you're not an AppleScript roadie, you could use a bit of Perl t o ft p t he last 10 songs you've heard t o your web sit e. The following code uses t he MacOSX: : iTunes ( ht t p: / / sourceforge.net / proj ect s/ brian- d- foy) m odule:
#! / us r / bi n / p e r l - w us e s t r i c t ; us e Ma c : : i Tu n e s ; us e Ne t : : FTP; # r a t he r s e l f - e x p l a n a t o r y s e t t i n g s my $i t une s _ l i b r a r y = " / Us e r s / mo r b u s / Mu s i c / i Tu n e s / i Tu n e s 3 Mu s i c Li b r a r y" ; my $i t une s _ p l a y l i s t = " Re c e n t l y Pl a y e d " ; my $f t p_h o s t = " f t p . d i s o b e y . c o m" ; my $f t p_u s e r n a me = " a n o n y mo u s " ; my $f t p_p a s s wo r d = " mo r b u s \ @d i s o b e y . c o m" ; my $f t p_p a t h = " / i n c o mi n g " ; my $f t p_f i l e = " i t u n e s . h t ml " ; # da t a c ol l op e n( FI LE, pr i nt FI LE pr i nt FI LE
e c t or " >$ f t p _ f i l e " ) o r d i e " c o u l d n ' t c r e a t e t e mp f i l e : $! " ; " i Tu n e s , $ i t u n e s _ p l a y l i s t " ; " i Tu n e s , $ i t u n e s _ p l a y l i s t " ;
# o ur l i b r a r y o b j e c t my $i t une s = Ma c OSX: : i Tu n e s - >r e a d ( $ i t u n e s _ l i b r a r y ) ; di e " c oul d n o t l o a d t h e i Tu n e s l i b r a r y " u n l e s s r e f $ i t u n e s ; # a nd our p l a y l i s t . We l o o p t h r o u g h t r a c k s , a d d i n g t o o u t p u t . my $pl a yl i s t = $ i t u n e s - >g e t _ p l a y l i s t ( $ i t u n e s _ p l a y l i s t ) ; f o r e a c h my $ t r a c k ( $ p l a y l i s t - >i t e ms ) { p r i nt FI LE " " , $ t r a c k - >a s _ s t r i n g , " " ;
} pr i nt FI LE ' ' ; c l o s e FI LE; # a nd now s e n d t o o u r FTP s i t e . my $c onn = Ne t : : FTP- >n e w( $ f t p _ h o s t ) o r d i e " c o u l d no t c o n n e c t t o ho s t : $ ! " ; $f t p- >l og i n ( $ f t p _ u s e r n a me , $ f t p _ p a s s wo r d ) ; $f t p- >mkd i r ( $ f t p _ p a t h , 1 ) ; $f t p- >c wd ( $ f t p _ p a t h ) ; $f t p- >put ( $ f t p _ f i l e ) o r d i e " c o u l d n o t u p l o a d f i l e : $ ! " ; $f t p- >qui t ; iTunes has st ruck a chord wit h m any m usic lovers, and t hese hacks can help ot hers get in on your groove. ( Yes, we know. There were far t oo m any m usical innuendos in t his hack for it t o be considered good t ast e. Blam e t he com poser, not t he m aest ro.)
[ Team LiB ]
[ Team LiB ] Hack 28 Controlling iTunes with Perl
Th e M a c::iTu n e s m odu le m e a n s t h a t con t r ollin g iTu n e s fr om a cr oss t h e r oom or a cr oss t h e w or ld is on ly a Pe r l scr ipt a w a y. I creat ed t he Mac: : iTunes Perl m odule t o cont rol iTunes from m y script s and from ot her m achines. Everyt hing t hat I present in t his hack com es wit h eit her t he Mac: : iTunes or Apache: : iTunes dist ribut ion ( ht t p: / / search.cpan. org/ aut hor/ BDFOY/ ) , available on t he Com prehensive Perl Archive Net work ( CPAN) . Once I have a back end, I can creat e alm ost any int erface t o iTunes t hat I like — and I do.
28.1 iTunes Is AppleScriptable Apple's MP3 player, iTunes ( ht t p: / / www.apple.com / it unes/ ) , has been AppleScript - aware since Version 2 ( t he lat est version is 3.0.1) . This gives m e a lot of freedom t o cont rol how I use iTunes. I can use Script Edit or t o creat e a script , but I can also use t he os a s c r i pt com m and- line t ool from a Term inal window. I can use t he - e swit ch t o run a short script on t he com m and line:
% o s a s c r i p t - e ' t e l l a p p l i c a t i o n " i Tu n e s " a c t i v a t e ' Or, I can st ore t he script in a file and pass it t o t he os a s c r i pt on t he com m and line:
- - i Tune s s c r i p t " q u i t _ i t u n e s " - - r un a s " o s a s c r i p t q u i t _ i t u n e s " t e l l a ppl i c a t i o n " i Tu n e s " qu i t e nd t e l l % os a s c r i pt qui t _i t une s Once I liberat e m yself from Script Edit or, I have m ore flexibilit y. Script s for iTunes can aut om at e a lot of m y com m on t asks. Apple has a collect ion of script s ( ht t p: / / www.apple. com / AppleScript / it unes/ ) , and Doug's AppleScript s for iTunes & SoundJam ( ht t p: / / www.m alcolm adam s.com / it unes/ scrxcont .sht m l) has several m ore good ones.
28.2 iTunes and Perl Alt hough I like AppleScript for very sim ple t hings, I t hink it get s t edious for com plicat ed script s. The language is verbose and does not have a good ext ension m echanism . Perl, on t he ot her hand, does, but at t he m om ent it does not have good access t o Aqua applicat ions, even t hough it can cont rol t he usual Unix applicat ions in Mac OS
X, j ust as it can on ot her Unix plat form s. When I st art ed t o work wit h iTunes AppleScript s, I want ed it t o be as easy t o do as writ ing Perl script s, even t hough it was not . Aft er a while, I decided t o fix t hat by writ ing a Perl m odule t o handle t he AppleScript port ions of iTunes. I already had a MacOSX: : iTunes Perl m odule t hat I used t o parse t he binary form at of t he iTunes Music Library file. I needed t o add AppleScript support t o it . On t he suggest ion of Chris Nandor, t he caret aker of MacPerl and aut hor of Mac: : Carbon, I changed t he nam e of m y dist ribut ion t o Mac: : iTunes and added t he Mac: : iTunes: : AppleScript m odule, which wrapped com m on AppleScript s in Perl funct ions. The m eat of t he m odule was t he _o s a s c r i pt rout ine, which creat es an AppleScript st ring and calls o s a s c r i p t j ust as I did earlier:
s u b _os a s c r i p t { my $s c r i p t = s h i f t ; r e qui r e I PC: : Op e n 2 ; my( $r e a d , $ wr i t e ) ; my $pi d = I PC: : Op e n 2 : : o p e n 2 ( $ r e a d , $ wr i t e , ' o s a s c r i p t '
);
p r i nt $ wr i t e q q ( t e l l a p p l i c a t i o n " i Tu n e s " \ n ) , $ s c r i p t , q q ( \ n e nd t e l l \ n ) ; c l os e $ wr i t e ; my $da t a = d o { l o c a l $ / ; } ; r e t ur n $ d a t a ; } The Mac: : iTunes: : AppleScript works m uch like t he os a s c r i pt com m and- line t ool. I ndeed, t he first version sim ply creat ed a script st ring ( called o s a s c r i p t ) , and capt ured t he out put , if any, for parsing. About t he sam e t im e I finished t he first version, Nat han Torkingt on needed Perl access t o AppleScript and convinced Dan Sugalski t o writ e Mac: : AppleScript . Wit h t hat m odule, Perl could work wit h AppleScript wit hout calling an ext ernal program . I replaced t he _ o s a s c r i p t rout ine wit h t e l l ( ) , which uses t he Run App l e Sc r i p t funct ion from Mac: : AppleScript :
s ub t e l l { my $s e l f = s h i f t ; my $c omma n d = s h i f t ; my $s c r i p t = q q ( t e l l a p p l i c a t i o n " i Tu n e s " \ n $ c o mma n d \ n e n d t e l l ) ; my $r e s u l t = Ru n Ap p l e Sc r i p t ( $ s c r i p t ) ; i f ( $@ ) { c a r p $ @; r e t ur n ; } r e t ur n 1 i f ( d e f i n e d $ r e s u l t a n d $ r e s u l t e q ' '
);
$ r e s ul t =~ s / ^ " | " $ / / g ; r e t ur n $ r e s u l t ; } Once I have t e l l ( ) , I sim ply feed it an AppleScript st ring, which it runs and t hen ret urns t he result . For exam ple, iTunes can play I nt ernet st ream s. The AppleScript way t o say t his uses o pe n l o c a t i on :
t e l l a ppl i c a t i o n " i Tu n e s " o pe n l o c a t i o n " h t t p : / / www. e x a mp l e . c o m/ s t r e a mi n g . mp 3 " e nd t e l l I n Mac: : iTunes: : AppleScript , I wrapped t his lit t le script in a m et hod, nam ed o pe n _u r l ( ) , which t akes a URL as an argum ent and uses t e l l ( ) t o run it :
s u b ope n_ u r l { my $s e l f = s h i f t ; my $ur l = s h i f t ; $ s e l f - >t e l l ( q q | o p e n l o c a t i o n " $ u r l " |
);
} Most of t he AppleScript com m ands for iTunes have a corresponding m et hod in Mac: : iTunes: : AppleScript . Now I can use t he full power of Perl, even t hough I am really using AppleScript behind t he scenes.
28.3 iTunes, Perl, and Terminal Just as I ran AppleScript s from t he Term inal window wit h os a s c r i pt , I can now run Perl program s t hat int eract wit h iTunes. I want t o play st ream ing m edia wit h very few keyst rokes and wit hout going t o t he iTunes Open St ream ing . . . m enu it em ; it 's j ust t oo m uch work when I do not want t o swit ch applicat ions. I creat ed a sim ple program , nam ed s t r e a m, using Mac: : iTunes. I creat e an iTunes cont roller obj ect , t hen call t he o pe n _u r l ( ) m et hod wit h t he first com m and- line argum ent . Perl t ells iTunes t o play t he MP3 st ream , and even t hough iTunes st art s t o do som et hing, it st ays in t he background while I cont inue what ever I am doing. I can even use t his program from shell script s.
#! / us r / bi n / p e r l us e Ma c : : i Tu n e s ; my $c ont r o l l e r = Ma c : : i Tu n e s - >c o n t r o l l e r ; $c o nt r ol l e r - >o p e n _ u r l ( $ ARGV[ 0 ] ) ; % s t r e a m h t t p : / / www. e x a mp l e . c o m/ s t r e a mi n g . mp 3 Sm all script s do not have m uch of an advant age over t he equivalent AppleScript s, but as t hings get m ore com plex, Perl st art s t o shine.
28.4 iTunes, Perl, and Apache I have been using Apple's AirPort for a while. We swear by it in m y household, and m y guest s like t o bring t heir
lapt ops and wireless cards when t hey visit . The AirPort has raised our com put er expect at ions; we want t o be able t o do any t ask from anywhere in t he house. However, when it com es t o playing m usic, we have a problem . Which com put er is hooked up t o t he st ereo? I do not like list ening t o m usic on t he built - in speakers of m y lapt op, so I have anot her Mac hooked up t o m y st ereo and a very large ext ernal hard drive filled wit h MP3s. Wit h all of t hat , I cannot carry t hat com put er around m y apart m ent . Even if I could, I want it t o j ust play m usic and perhaps perform ot her silent t asks. I should not have t o int errupt m y m usic because I decide t o change som et hing on t he Mac I am working on. I want t he m usic t o keep playing even if I rest art t he iTunes on m y lapt op, which I do frequent ly while developing Mac: : iTunes. I need t o cont rol t his cent ral MP3 player rem ot ely. I could creat e a com m and- line t ool t o cont rol iTunes and t hen log in t he m achine wit h s s h , but not everyone who want s t o cont rol iTunes likes using t he Term inal. I need a m ore pleasing int erface. Since Mac OS X com es wit h t he Apache web server ( which runs by default ) , I can writ e a CGI script t o cont rol iTunes:
#! / us r / bi n / p e r l us e s t r i c t ; us e CGI q w( : s t a n d a r d ) ; us e Ma c : : i Tu n e s ; us e Te xt : : Te mp l a t e ; my $Te mpl a t e = ' / Us e r s / b r i a n / De v / Ma c OSX/ i Tu n e s / h t ml / i Tu n e s . h t ml ' ; =h e a d1 NAME i Tu ne s . c g i - c o n t r o l i Tu n e s f r o m t h e we b =h e a d1 SYNOPSI S =h e a d1 DESCRI PTI ON Th i s i s o n l y a p r o o f - o f - c o n c e p t s c r i p t . =h e a d1 AUTHOR br i a n d f o y , E =h e a d1 COPYRI GHT Co p yr i ght 2 0 0 2 b r i a n d f o y , Al l r i g h t s r e s e r v e d =c u t my $c ont r o l l e r = Ma c : : i Tu n e s - >n e w(
) - >c o n t r o l l e r ;
my $c omma n d = p a r a m( ' c o mma n d ' ) ; my $pl a yl i s t = p a r a m( ' p l a y l i s t ' ) | | ' Li b r a r y ' ; my $s e t _p l a y l i s t = p a r a m( ' s e t _ p l a y l i s t ' ) ; i f ( $c omma n d ) { my %Comma n d s = ma p { $ _ , 1 } q w( p l a y s t o p p a u s e b a c k _ t r a c k) ;
$ c ont r o l l } e l s i f ( $s e t { $ c ont r o l l $ pl a yl i s t }
e r - >$ c o mma n d i f e x i s t s $ Co mma n d s { $ c o mma nd } ; _pl a yl i s t ) e r - >_ s e t _ p l a y l i s t ( $ s e t _ p l a y l i s t ) ; = $s e t _pl a yl i s t ;
my %va r ; $v a r { ba s e } = ' h t t p : / / 1 0 . 0 . 1 . 2 : 8 0 8 0 / c g i - b i n / i Tu n e s . c g i ' ; $v a r { s t a t e } = $ c o n t r o l l e r - >p l a y e r _ s t a t e ; $v a r { c ur r e n t } = $ c o n t r o l l e r - >c u r r e n t _ t r a c k _ n a me ; $v a r { pl a y l i s t } = $ p l a y l i s t ; $v a r { pl a y l i s t s } = $ c o n t r o l l e r - >g e t _ p l a y l i s t s ; $v a r { t r a c k s } = $ c o n t r o l l e r - >g e t _ t r a c k _ n a me s _ i n _ p l a yl i s t ( $ p l a y l i s t ) ; my $ht ml = Te x t : : Te mp l a t e : : f i l l _ i n _ f i l e ( $ Te mp l a t e , HASH => \ %v a r ) ; pr i nt he a d e r (
) , $ h t ml , " \ n " ;
On t he first run wit hout input , t he script creat es an iTunes cont roller obj ect , set s t he st art ing playlist t o Li b r a r y ( t he iTunes virt ual playlist t hat has everyt hing iTunes knows about ) , t hen asks iTunes for a lot of st at e inform at ion, including t he nam es of t racks in t he playlist s, t he nam es of t he playlist s, and what iTunes is current ly doing ( e.g., playing or st opped) . The script uses Text : : Tem plat e t o t urn all of t his int o HTML, which it sends back t o a web browser. The t em plat e file I use is in t he ht m l direct ory of t he Mac: : iTunes dist ribut ion, and t hose wit h any sort of design skills will surely want t o change it t o som et hing m ore pleasing. The code is separat ed from t he present at ion. Figure 3- 49 shows t he iTunes Web I nt erface. Figu r e 3 - 4 9 . iTu n e s W e b I n t e r fa ce
I have a sm all problem wit h t his approach. To t ell an applicat ion t o do som et hing t hrough AppleScript , t he t elling program has t o be running as a logged- in user. The web server is set up t o run as t he unprivileged pseudouser nobody, so t his CGI script will not work from t he st ock Apache configurat ion. This is not m uch of a problem , since I can m ake Apache run under m y user. On m y m achine, I run a second Apache server wit h t he sam e configurat ion file, except for a couple of changes. First , I have t o m ake t he web server run as m y user, so I change t he Us e r direct ive. Along wit h t hat , I have t o choose anot her port , since only t he root user can use port num bers below 1024, and Apache expect s t o use port 80. I choose port 8080 inst ead. I will have t o pass t his nonst andard port along in any URLs, but m y CGI script already does t hat . As long as I use t he web int erface wit hout t yping int o t he web browser's locat ion box, I will not have t o worry about t hat .
Us e r br i a n Po r t 8080 I also have t o change any file pat hs t hat Apache expect s t o writ e t o. Since Apache runs as m y user, it can creat e files only where I can creat e files.
Pi d Fi l e " / Us e r s / b r i a n / h t t p d - b r i a n . p i d " Once everyt hing is set up, I access t he CGI script from any com put er in m y hom e net work, Mac or not , and I can cont rol m y cent ral iTunes.
28.5 iTunes, Perl, Apache, and mod_perl CGI script s are slow. Every t im e I run a CGI script , t he web server has t o launch t he script and t he script has t o load all of t he m odules t hat it needs t o do it s work. I have anot her problem wit h Mac: : iTunes, t hough. The first call t o Mac: : AppleScript 's Ru n Ap p l e Sc r i p t ( ) seem s t o be slower t han subsequent calls. I pay a first - use penalt y for t hat . To get around t hat , I want t o keep m y iTunes cont roller running so I do not have t o pay t his overhead over and over again. I creat ed Apache: : iTunes t o do j ust t hat . I could run m y CGI script under Apache: : Regist ry, but I like t he nat ive Apache int erface bet t er. I configured m y web server t o hand off any request s of a URL st art ing wit h / iTunes t o m y m odule. I use Pe r l Se t En v direct ives t o configure t he lit eral dat a I had in t he CGI version.
Se t Ha ndl e r p e r l - s c r i p t Pe r l Ha ndl e r Ap a c h e : : i Tu n e s Pe r l Modul e Ma c : : i Tu n e s Pe r l I ni t Ha n d l e r Ap a c h e : : St a t I NC Pe r l Se t En v APACHE_ I TUNES_ HTML / we b / t e mp l a t e s / i Tu n e s . h t ml Pe r l Se t En v APACHE_ I TUNES_ URL h t t p : / / www. e x a mp l e . c o m: 8 0 8 0 / i Tu ne s Pe r l Se t En v APACHE_ I TUNES 1
The out put , shown in Figure 3- 50, looks a lit t le different from t he CGI version because I used a different t em plat e t hat included m ore feat ures. I can change t he look- and- feel wit hout t ouching t he code. Figu r e 3 - 5 0 . Apa ch e ::iTu n e s in t e r fa ce
I t end t o like t he mo d _ p e r l int erface m ore. I nst ead of passing variables around in t he query st ring, t he URL it self is t he com m and and is sim ple, short , and wit hout funny- looking charact ers:
ht t p: / / www. e x a mp l e . c o m/ i Tu n e s / p l a y ht t p: / / www. e x a mp l e . c o m/ i Tu n e s / s t o p 28.6 iTunes, Perl, and Tk As I was working on Apache: : iTunes, I was also working on a different proj ect t hat needed t he Tk ( ht t p: / / www. lns.cornell.edu/ ~ pvhp/ pt k/ pt kFAQ.ht m l) widget t oolkit . I was program m ing t hings on FreeBSD, but I like t o work on m y Mac. That 's easy enough, since I have XonX ( t hat 's t he com binat ion of XDarwin ( ht t p: / / www.xdarwin.org) and OrobosX ( ht t p: / / oroborosx.sourceforge.net / ) ) inst alled. Under Mac OS X 10.2 t hese work wit hout a problem , alt hough if you use 10.1 you have t o perform a lit t le bit of surgery on your syst em , following St eve Lidie's inst ruct ions ( ht t p: / / www.lehigh.edu/ ~ sol0/ Macint osh/ X/ pt k/ ) . Since I had been away from t he Tk world for awhile, I was referring t o O'Reilly's Mast ering Perl/ Tk quit e a bit . As I was flipping t hrough t he pages on m y way t o t he next t hing I needed t o read, I not iced a screenshot of iTunes. I t was not really iTunes t hough — St eve Lidie had t aken t he iTunes look- and- feel as a front end for his MP3 player exam ple. I already had all of t he back- end st uff t o cont rol iTunes and none of it was t ied t o a part icular int erface. Even m y CGI script could out put som et hing ot her t han HTML, like plain t ext or even a huge im age. I could easily add a Tk int erface t o t he sam e t hing — or so I t hought .
Cont rolling iTunes is easy. Cont rolling it from a web page is easy. Cont rolling it from Tk, which has a persist ent connect ion t o what ever it hooks up t o, was harder. Since I had t he persist ent connect ion, I could reflect changes in iTunes inst ant aneously. I n t he web versions, if som ebody else changed t he st at e, like changing t he song or m ut ing t he volum e, t he web page would not show t hat unt il I reloaded. The Tk int erface ( shown in Figure 3- 51) could show it alm ost inst ant aneously. I n realit y, I could get t he Tk int erface t o poll iTunes for it s st at e only every t hree and a half seconds or so before it t ook a big drop in perform ance, but t hat is good enough for m e. Figu r e 3 - 5 1 . Tk iTu n e s in t e r fa ce
The t k- it unes.pl script com es wit h Mac: : iTunes. Som eday I m ight develop a skins m echanism for it ; all I , or som ebody else, need t o do is m ake t he colors configurable. The script already uses a configurat ion file, alt hough I can configure only a few t hings at t he m om ent .
28.7 Final Thoughts Perl can int eract wit h Aqua applicat ions t hrough AppleScript . Wit h Mac: : iTunes as a back end, I can creat e m ult iple int erfaces t o iTunes t hat I can use on t he sam e com put er or on ot her com put ers on t he sam e net work. Everyone in m y house, or wit hin range of m y AirPort , can cont rol m y iTunes. —brian d foy
[ Team LiB ]
[ Team LiB ] Hack 29 iCal Calling iTunes
W ou ldn 't it be n ice t o ch oose t r a ck s fr om iCa l, r e m in din g you r se lf t o e x e r cise w it h t h e in spir in g t h e m e fr om Fla sh da n ce ? You give people an inch, t hey'll want t o t ake a m ile. I n t his corner, Apple's iTunes, MP3 player suprem e wit h sm art playlist s, XML export s, rat ings, play count , I D3 support , and m ore. And in t he ot her, Apple's iCal wit h alert s, m ult iple calendar coloring, web- based subscript ions, t o- do list s, and drill- down views. Bot h free, powerful, and useful. Are people happy wit h t he birds on t heir doorst eps? " Not wit hout int egrat ion," t hey sing, and int egrat ion com es in t he form of a free AppleScript from Doug Adam s. There's no inst allat ion; j ust st ick t he applicat ion any place you'd like ( as is t ypical of m ost AppleScript s) . Wit h proper configurat ion, iCal Calling iTunes can t rigger t he st art of any iTunes playlist , shuffle t hat playlist , or likewise st op t hat playlist at any dat e or t im e. Configurat ion is sim ple. First , creat e a new calendar called iTunes. I t 's here t hat you'll configure all your sound event s ( you can configure ot her event s, but as we'll see, t heir st at us will be m arked as Tent at ive) . To int egrat e iCal wit h iTunes, define an event nam ed aft er one of your iTunes playlist s, and configure t he dat es as you would norm ally. Aft er t hat , sim ply double- click t he iCal Calling iTunes AppleScript , and it 'll resolut ely play t racks from t he m at ching play list when t he event t riggers. To st op a playlist , set t he To dat e of t he event for when you want t he lit any t o halt , and change t he st at us t o Confirm ed. Ot her st at us changes also exist : if t he iTunes playlist could not be found, t he event 's st at us will change t o Tent at ive, and skipping event s is as easy as changing t he st at us t o Cancelled. Shuffling playlist s can be accom plished by appending an ast erisk t o t he event nam e. The possibilit ies of t his int egrat ion are widespread: configure a day's wort h of m usic, st art ing wit h slow- t em po progressive, speeding up t o DJs in t he aft ernoon, overt aking wit h digit al hard- core in t he evening, and t hen easing int o m indlessness wit h night t im e t rance. Or t rigger a playlist of rom ant ic songs on your anniversary, a pinch t o grow an inch on your birt hday, and a wee bit o' sham rockery on St . Pat rick's Day.
29.1 See Also ●
Doug's AppleScript s ( ht t p: / / www.m alcolm adam s.com / it unes/ )
[ Team LiB ]
[ Team LiB ] Hack 30 Publishing and Subscribing to iCal Calendars
Pu blish you r ow n iCa l ca le n da r s on .M a c or a n y W e bD AV- e n a ble d w e b se r ve r for su bscr ipt ion . iCal, Apple's calendaring applicat ion for Mac OS X, is already being used by hundreds of people who are publishing t heir own calendars for subscript ion. Apple's sit e has a bunch of calendars for obvious t hings like sport ing event s, t elevision season prem ieres, and st at e and religious holidays. iCalShare ( ht t p: / / www.icalshare. com ) has even m ore.
30.1 Publishing Publishing a calendar t o a WebDAV server [ Hack # 95] is j ust about as sim ple as publishing t o .Mac, since t he lat t er, in fact , uses WebDAV. Choose t he calendar you wish t o publish in t he t op- left iCal pane and select Calendar Publish . . . I n t he Publish Calendar dialog box ( shown in Figure 3- 52) , select " Publish on a web server" rat her t han " Publish on .Mac" ; t he box will expand t o accom odat e t hree new fields: URL, Login, and Password. You'll need t o fill in t he appropriat e locat ion and aut hent icat ion inform at ion specific t o your WebDAV [ Hack # 95] set up. I n t he URL box, be sure t o put only t he pat h where t he calendar should be kept on t he WebDAV server; iCal will fill in a filenam e for you ( e.g., Hom e.ics for a calendar called Hom e) . I f you'd like t o have your published calendar updat ed live each t im e you m ake an alt erat ion t o t he local copy, be sure t o check t he " Publish changes aut om at ically" box. When you're ready, click t he Publish but t on and away your calendar goes. Figu r e 3 - 5 2 . Pu blish in g a ca le n da r t o W e bD AV
The pat h on your WebDAV- enabled web server will differ. I 've used a pat h and account creat ed in [ Hack # 95] .
I f you decide not t o enable aut oupdat ing, you can always m anually push t he lat est using Calendar Updat e. And if you decide t o t ake t he calendar down aft er an event has passed or t he local t heat er season is over, sim ply select Calendar
Unpublish.
30.2 Subscribing You subscribe in t he sam e way t o a published calendar, whet her it was published t o .Mac, pushed t o a WebDAV server, or export ed t o an .ics file m ade available on a web server.
Subscribe . . . t o bring up t he Subscribe t o Calendar dialog box. Type or past e t he Select Calendar published calendar's URL, including t he filenam e ( ending in .ics) . I f you believe t he calendar will be updat ed regularly, check Refresh and select an appropriat e frequency at which iCal should revisit t he calendar and grab
t he lat est . I t 's up t o you whet her or not you want t o rem ove alarm s and t o- do it em s from t he published calendar; sim ply click t he associat ed checkbox t o check or uncheck it . I f t he calendar has rest rict ed access, click t he disclosure t riangle next t o " Advanced opt ions" , check t he " Needs aut hent icat ion" checkbox, and fill in an aut horized login and password. The screenshot in Figure 3- 53 shows aut hent icat ed access t o a password- prot ect ed calendar in act ion. Figu r e 3 - 5 3 . Su bscr ibin g t o a ca le n da r
Click t he Subscribe but t on and you should see t he calendar slot it self nicely int o your own iCal view of t he world.
You can m ake subscript ion easier on your audience by providing a link direct ly t o t he . ics file, available via em ail or on your web sit e, allowing t hem t o sim ply click on a link t o launch iCal and subscribe.
—Erik T. Ray
[ Team LiB ]
[ Team LiB ] Hack 31 Using Bluetooth for SMS and Phone-Call Handling
W it h Blu e t oot h - e n a ble d ce ll ph on e s a n d M a c OS X's Blu e t oot h su ppor t , you ca n se n d a n d r e ce ive SM S m e ssa ge s a n d h a n dle ce llph on e ca lls r igh t fr om you r k e yboa r d. Apple is popularizing Bluet oot h ( ht t p: / / www.apple.com / bluet oot h/ ) m uch as it did USB, 802.11b, and FireWire t echnologies. Alt hough Apple has done a good j ob support ing Bluet oot h t echnology — and, indeed, baking it right in — not m uch has been done t o educat e users about what it can do. Recent ly, I was pleasant ly surprised t o see t hat t he nift y lit t le Address Book in Mac OS X has built - in Bluet oot h funct ionalit y t hat allows you t o send and receive Short Message Service ( SMS) m essages t hrough your Bluet oot h- enabled phone, all via your com put er! I f you've ever ham m ered out an SMS not e using t he but t ons on your t iny cell phone, t hen you know it would be m uch easier t o use your full- sized com put er keyboard inst ead. I n t his hack, I will show you how t o use Mac OS X t o send SMS m essages easily. You will need a Bluet oot h adapt er, such as t he D- Link USB Bluet oot h Adapt er ( available at ht t p: / / st ore.apple. com / 1- 800- MY- APPLE/ WebObj ect s/ AppleSt ore?product LearnMore= T4728G/ B) , for your Mac, and a Bluet oot henabled phone, such as t he Ericsson T68i ( ht t p: / / www.ericsson.com / m obilit yworld/ sub/ open/ devices/ t 68i/ index. ht m l ) .
31.1 Pairing Up Your Phone with Address Book Wit h your Address Book powered up, t he first t hing t o do is t o pair it up wit h your Bluet oot h- enabled m obile phone. To do so, you need t o t urn on t he Bluet oot h radio on your phone, and t hen click on t he Bluet oot h icon on t he Address Book ( see Figure 3- 54) . Figu r e 3 - 5 4 . Th e Blu e t oot h icon con n e ct s t o you r Blu e t oot h - e n a ble d ph on e
I f t he pairing is successful, you should see t he icon in blue; ot herwise, it will appear grayed out .
31.2 Sending SMS Messages Wit h t he pairing done, you are now ready t o send an SMS m essage! To send som eone in your Address Book an SMS m essage, select t he nam e and click on t he phone num ber of t he user. Three opt ions will be displayed, as
shown in Figure 3- 55. Figu r e 3 - 5 5 . Se n din g a n SM S m e ssa ge u sin g Addr e ss Book
You can display t he num ber in huge font s, send t he person an SMS m essage, or m ake a call t o him . I f you select SMS Message, you can key in t he m essage ( m axim um of 160 charact ers) and click Send ( see Figure 3- 56) . Tired fingers are now a t hing of t he past ! Figu r e 3 - 5 6 . Typin g a n SM S m e ssa ge on t h e M a c
31.3 Receiving SMS Messages Besides sending SMS m essages, your Address Book will also inform you of incom ing SMS m essages, as shown in Figure 3- 57. Figu r e 3 - 5 7 . Re ce ivin g a n in com in g SM S m e ssa ge on you r M a c
When an incom ing m essage is received, Address Book will prom pt a window displaying t he m essage. You can save t he m essage t o t he Address Book ( m ore on t his lat er) or reply t o t he m essage. Address Book will aut om at ically m at ch t he num ber of t he caller ( supplied by your m obile phone, which requires caller I D service) wit h it s nam e list and display t he person's nam e. To reply t o t he m essage, sim ply click t he Reply but t on. You can now reply t o a SMS m essage direct ly on t he Mac, as shown in Figure 3- 58. Figu r e 3 - 5 8 . Re plyin g t o a SM S m e ssa ge fr om t h e M a c
31.4 Handling Incoming Calls When your phone rings, Address Book will not ify you and provide t hree opt ions ( as shown in Figure 3- 59) : reply t o t he caller via SMS, act ivat e voice m ail on t he m obile phone ( t he phone will t hen st op ringing) , or sim ply answer t he call. Figu r e 3 - 5 9 . I n com in g ca ll displa ye d on t h e M a c
I f you click SMS Reply, you can t hen send an SMS m essage t o t he caller, perhaps t o inform him t hat you will call him lat er.
31.5 Saving Incoming Messages When you receive an incom ing m essage, you can save it t o your Address Book for archiving. Clicking on t he Save t o Not e but t on in t he I ncom ing SMS Message window will append t he m essage t o t he cont act inform at ion, as shown in Figure 3- 60. Figu r e 3 - 6 0 . SM S m e ssa ge s ca n be a r ch ive d in Addr e ss Book
—Wei- Meng Lee
[ Team LiB ]
[ Team LiB ] Hack 32 iSync via Bluetooth
Blu e t oot h m e a n s n e ve r h a vin g t o plu g in a ca ble w h e n syn ch r on izin g you r ph on e or PD A w it h you r M a c. Apple's iSync, t he synchronizat ion soft ware based on t he SyncML prot ocol ( ht t p: / / www.syncm l.org/ ) , synchronizes t he cont act and calendar inform at ion on your m obile devices wit h your Macint osh. I n addit ion, if you have m ore t han one Mac, it will also help t o synchronize t he inform at ion in your Address Book and iCal calendars ( .Mac ( ht t p: / / www.m ac.com / ) m em bership is required) . The m obile devices support ed by iSync include t he lat est GPRS, Bluet oot h- enabled ( ht t p: / / www.apple.com / bluet oot h/ ) phones ( such as t he popular Ericsson T68 and t he Sony Ericsson T68i) and Palm OS devices ( such as t he Palm m 515) . iSync even synchronizes t he inform at ion on your iPod wit h your Mac. To download iSync, go t o ht t p: / / www.apple.com / isync/ . The download is about 7MB. You need t o have t he lat est Mac OS X 10.2 Jaguar running.
32.1 Installing iSync I nst alling iSync is a snap, provided you already have iCal inst alled. iCal is required for iSync t o work. You can download a free copy of iCal from ht t p: / / www.apple.com / iCal/ . iSync cont ains t wo packages: iSync and iSync_Palm . The lat t er is required for synchronizat ion wit h Palm devices. For t his hack, I have t ried iSync using m y Ericsson T68 and m y Palm m 515. I will walk you t hrough t he st eps t o get t he devices connect ed as well as t o set up Bluet oot h on your Mac so t hat t he synchronizat ion can be done wirelessly.
32.2 Adding the T68 Using Bluetooth For Bluet oot h connect ivit y on m y Mac, I used t he Billiont on USB Bluet oot h adapt er. Anot her popular adapt er is t he D- Link. Wit h built - in Bluet oot h or a plugged- in USB Bluet oot h adapt er, you should see a Bluet oot h icon in your Syst em Preferences window, as shown in Figure 3- 61. Figu r e 3 - 6 1 . Blu e t oot h icon in Syst e m Pr e fe r e n ce s
Clicking on t he Bluet oot h icon reveals t he four t abs for configuring Bluet oot h access. As I want ed t o est ablish a connect ion bet ween m y Mac and m y Ericsson T68, I went t o t he Paired Devices t ab ( see Figure 3- 62) and clicked on New . . . . Figu r e 3 - 6 2 . Pa ir e d D e vice s t a b
You also need t o t urn on t he Bluet oot h radio on your phone and set it t o be Bluet oot h Discoverable. This allows your phone t o be seen in t he Bluet oot h et her; an undiscoverable phone is an invisible phone. Once your Mac finds t he phone, click Pair t o est ablish a relat ionship bet ween t he phone and t he Mac ( see Figure 3- 63) . Each side of t he pairing needs t o be sure t hat t he ot her is aut horized t o pair. This is accom plished by a t hrowaway passkey ( read: one- t im e password) . Anyt hing will do, even 12 34 . You should be prom pt ed by bot h your Mac and your phone t o ent er t he sam e passkey. I f all goes t o plan, t he devices should be paired and handle all furt her aut hent icat ion and so fort h wit hout needing anyt hing m ore from you. Figu r e 3 - 6 3 . Pa ir in g a n e w ly de t e ct e d de vice
Once t he devices are paired, you will be prom pt ed wit h anot her screen, allowing you t o choose t he services t hat you can use wit h t his phone ( see Figure 3- 64) . Figu r e 3 - 6 4 . Ch oosin g t h e se r vice s t o u se w it h t h e ph on e
Once t his st ep is com plet ed, you should be able t o see your T68 icon in t he iSync window ( see Figure 3- 65) . To st art syncing, sim ply click on t he Sync but t on, shown in Figure 3- 66. To cust om ize synchronizat ion, click t he phone icon and select t he relevant syncing opt ions ( see Figure 3- 67) . Figu r e 3 - 6 5 . Th e ph on e a ppe a r s in t h e iSyn c w in dow
Figu r e 3 - 6 6 . Th e Syn c bu t t on
Figu r e 3 - 6 7 . Syn c opt ion s for t h e ph on e
iSync will synchronize t he Cont act s and Calendars inform at ion on t he T68 wit h t he Address Book and iCal on your Mac, respect ively.
I found t hat if you have an awful lot of dat a, iSync can get st uck t rying t o synchronize all t he dat a from bot h t he Address Book and iCal on t he first sync. This is exascerbat ed if you insist ( as I do) on keeping t wo weeks' wort h of dat a on your phone. A workaround is t o skip your cont act s t he first t im e ( uncheck t he Cont act s box in sync opt ions for your phone) , adding it back in aft er t he init ial large sync.
32.3 Adding the Palm m515 The Palm used for t his hack is an m 515, shown in Figure 3- 68. I t com es wit h a Secure Digit al ( SD) slot for SD cards. I use t he SD Bluet oot h card ( m ade by Toshiba) wit h t he m 515 for Bluet oot h connect ivit y. Figu r e 3 - 6 8 . Pa lm m 5 1 5 w it h SD Blu e t oot h ca r d
Adding Palm devices t o iSync is not as st raight forward as adding a phone, wit h t hree ext ra st eps along t he way. The first st ep is t o inst all Palm Hot Sync Manager for Mac OS X ( ht t p: / / www.palm .com / soft ware/ deskt op/ m ac. ht m l) . I t works in concert wit h iSync t o keep your Palm up- t o- dat e. Wit h t hat inst alled and t est ed — m ake sure you can Hot Sync in t he st andard Palm way before proceeding — you should inst all t he second iSync package, iSync_Palm .pkg. As wit h t he phone, you'll need t o pair up your Mac and Palm device via Bluet oot h. Next , you need t o inform Hot Sync Manager t hat you want t o use t he Bluet oot h connect ion as a serial port for syncing purposes in addit ion t o using t he cradle. Do so by checking bot h t he bluet oot h . . . and USB boxes in Hot Sync's Connect ion Set t ings dialog box, shown in Figure 3- 69. Figu r e 3 - 6 9 . En a blin g t h e Blu e t oot h se r ia l por t for syn cin g
Now you'll need t o alt er your Conduit Set t ing ( from t he Hot Sync m enu) so t hat Hot Sync's default is t o do not hing wit h t he Address Book, Dat e Book, and To Do List , leaving t hese up t o iSync t o handle: 1. Set t he act ion for Address book t o Do Not hing. 2. Set t he act ion for Dat e Book t o Do Not hing. 3. Set t he act ion for To Do List t o Do Not hing. Figure 3- 70 shows t he result ing set t ings. Figu r e 3 - 7 0 . Con figu r in g Con du it Se t t in gs
Finally, configure t he set t ing for iSync Configurat ion so t hat iSync knows which it em s t o synchronize wit h your Palm device. Wit h iSync Conduit select ed, click t he Conduit Set t ings but t on at t he t op- left of t he window. I n t he result ing dialog box ( see Figure 3- 71) , check bot h Synchronize Cont act s and Synchronize Calendars ( To Do List s are part of Calendars) and click OK. Figu r e 3 - 7 1 . Se le ct in g it e m s t o syn ch r on ize u sin g iSyn c
You should now see t he Palm device in iSync, as shown in Figure 3- 72. Figu r e 3 - 7 2 . Th e Pa lm sh ow s u p in t h e iSyn c w in dow
When you've com plet ed all t he preceding st eps, t he next t im e you use Hot Sync t o synchronize your Palm device t he Address Book, Dat e Book, and To Do List will be synchronized wit h t he Mac's Address Book and iCal, respect ively. To t est t his out , I set up som e it em s in iCal ( see Figure 3- 73) and used iSync t o sync it wit h m y Palm m 515. To sync, j ust click iSync's Sync Now but t on. As a precaut ion, you will be alert ed t o any changes you m ake t o your devices ( see Figure 3- 74) , so t hat you can decide t o proceed or t o cancel t he operat ion. Not e t hat t here are t wo ways t o sync your Palm devices. You can eit her use t he Bluet oot h connect ion ( in which case you have t o use t he Hot Sync icon on t he device) or you can use t he cradle. I f you are using t he cradle, you need t o press t he Hot Sync but t on on t he cradle. Clicking on t he syncing but t on on iSync does not synchronize Palm devices. Figu r e 3 - 7 3 . M y ca le n da r in iCa l
Figu r e 3 - 7 4 . Con fir m in g ch a n ge s t o be m a de
iSync will synchronize t he Address Book, Dat e Book, and To Do List on Palm devices; it won't , unfort unat ely, t ouch t he Not epad.
—Wei- Meng Lee
[ Team LiB ]
[ Team LiB ] Chapter 4. The User Interface
Sect ion 4.1. Hacks # 33- 47 Hack 33. Finding Your Way Back t o t he Deskt op Hack 34. Alt - Tab Alt - Ternat ives Hack 35. Put t ing Things in t he Apple Menu Hack 36. Keeping Your Snippet s Organized Hack 37. LaunchBar, a Dock Alt ernat ive Hack 38. DockSwap, Anot her Dock Alt ernat ive Hack 39. Tinkering wit h Your User I nt erface Hack 40. Ext ending Your Screen Real Est at e wit h Virt ual Deskt ops Hack 41. Top Screenshot Tips Hack 42. Checking Your Mac's Pulse Hack 43. Screensaver as Deskt op Hack 44. Dipping Your Pen int o I nkwell Hack 45. Speakable Web Services Hack 46. Using AppleScript in Cont ext ual Menus Hack 47. Prying t he Chrom e Off Cocoa Applicat ions
[ Team LiB ]
[ Team LiB ] 4.1 Hacks #33-47 Mac users have a long hist ory of t weaking t he Mac OS graphical user int erface. Som e regard t he Mac OS X GUI as a panacea for all t he ills of int erface design over t he years, a breat h of fresh air in a world dom inat ed by dust y windows and quivering m ice. Som e find OS X j ust enough like Mac OS 9 t o get by, perhaps even grow t o love. Then t here are t hose who find it an abom inat ion, fixable by sheer will and det erm inat ion, som et hing t o bend, spindle, and hack unt il it looks " j ust as it should." Regardless of which of t hese cam ps you find yourself in, t here's m ore t han enough power beneat h t he hood and m yriad t ools and t ricks t o cust om ize t he OS X GUI t o your heart 's cont ent . This chapt er provides a collect ion of inspiring hacks and point ers t o t hird- part y applicat ions for t weaking t he lookand- feel, ext ending t he funct ionalit y t hat 's already t here, and t eaching your Mac t o behave j ust as it should.
[ Team LiB ]
[ Team LiB ] Hack 33 Finding Your Way Back to the Desktop
Pu sh t h a t clu t t e r of w in dow s a side a n d ge t you r se lf ba ck t o you r D e sk t op. A com m on com plaint of new OS X users ( part icularly t hose com ing from t he Windows world) is t he inabilit y t o get t o t he Deskt op wit hout having t o m inim ize or hide applicat ions one by one. Mac OS X sport s a couple of ways t o hide a handful of applicat ions and t heir associat ed windows in one fell swoop.
Mac OS 9 users will probably be fam iliar wit h Applicat ion Nam e Hide Ot hers, where Applicat ion Nam e is t he nam e of t he current ly act ive applicat ion. The Finder is considered an applicat ion like any ot her, so t his works as expect ed. To hide everyt hing but t he Deskt op and any open Finder windows, Cont rol- click on t he Deskt op or Finder icon in t he Dock and select Finder
Hide Ot hers.
Modified Dock clicks abound, providing various subt let ies when swit ching or launching applicat ions. Opt ion- click ( holding down t he Opt ion key while clicking on a Dock icon) hides t he applicat ion previously in t he foreground. - click hides all but t he select ed applicat ion. Opt ionThe second- short est but best pat h I 've found t o t he Deskt op ( int roduced in Mac OS X 10.2, Jaguar) is t o click on - H for Hide Ot hers. The absolut e short est pat h is t o Opt ion- click t he Finder t he Deskt op and press Opt ion( Mac OS sm iley- face logo) in t he Dock; while t his hides all applicat ions ot her t han t he Finder, it does have t he unfort unat e side effect of opening a Finder window right in t he m iddle of t he Deskt op. Show Deskt op ( ht t p: / / www.everydaysoft ware.net / syst em / ) , as it s nam e suggest s, is a popular piece of freeware serving t o hide all applicat ions and show your Deskt op at t he click of an icon. Show Deskt op can live in eit her your m enu bar or Dock, as shown in Figure 4- 1. Figu r e 4 - 1 . Sh ow D e sk t op in a ct ion
[ Team LiB ]
[ Team LiB ] Hack 34 Alt-Tab Alt-Ternatives
W h ile M a c OS X Ja gu a r m a r k e dly im pr ove d ple n t y of r oom for e n h a n ce m e n t . I t 's such an innocent key com binat ion:
- Ta bbin g you r w a y be t w e e n a pplica t ion s, t h e r e 's st ill
- Tab. Easy t o say, easy t o do, easy t o t ype. I nnocent it m ay be, but
em broiled wit h cont roversy is t his lit t le key com m and; sure, it swit ches you t o t he next open applicat ion ( and Shift - Tab sends you t o t he previous one) , but st ill people clam or for m ore. They want a sm art swit cher — one t hat goes in order of applicat ion usage, not Dock order, or even one t hat underst ands individual windows wit hin a single applicat ion.
I n previous versions of OS X, it was easy for soft ware t o override t he - Tab behavior, allowing previous usage order t o be m im icked wit h t hird- part y soft ware. To add m ore fat t o t he fire com es t his warning from Keyboard Maest ro's lat est release: Apple has disabled Keyboard Maest ro's ( and any ot her t hird- part y applicat ion's) - Tab keyst roke from t he Dock and replace it wit h ot her abilit y t o override t he funct ionalit y.
I n fact , it 's not t he Alt - Tab, per se, t hat 's at issue. I t 's t he Mac concept of windows belonging t o applicat ions rat her t han exist ing sem iaut onom ously t hat causes unrest . While hopping from Mail t o I nt ernet Explorer ( I E) t o BBEdit is a snap, it 's sim ply im possible t o alt ernat e bet ween, say, Google residing in it s own I E windows and - ~ in bot h I E and Mail Docum ent 1 in Word. Som e applicat ions do provide t heir own local keyboard short cut — — but t his is a rarit y and varies from applicat ion t o applicat ion. Ot her applicat ions assign windows t o but who t he heck can bear all t hat in m ind while act ually t rying t o get som e work done. At heart , t here are t wo issues: Jaguar ( but not previous releases of OS X) allows you t o previously used applicat ion, and applicat ions, not t he windows wit hin t hem , are at t em pt s have been m ade t o alt er
- # keys,
- Tab t o go t o your
- Tab dest inat ions. Som e
- Tab behavior. Here are a few of t he highlight s:
Lit eSwit chX ( ht t p: / / www.prot eron.com / lit eswit chx/ )
- Tab in 10.1.x and below, Lit eSwit chX, from Prot eron soft ware, is a freeware applicat ion swit cher ( via or a configurable com binat ion) and com es wit h window layering cont rols, allowing t he user t o duplicat e previous versions of t he Mac OS. One such opt ion ( t here are four) is Classic Finder Windows, which m akes all of t he Finder windows com e forward t oget her ( i.e., click on t he Deskt op and have all your Finder windows pop t o t he front ) . Along wit h window layering, t he - Tab applicat ion overlay ( which looks sim ilar t o t he Microsoft Windows overlay) can be resized up or down and support s drag- and- drop and cont ext ual m enu it em s.
AppSwit cher ( ht t p: / / www.uwm .edu/ ~ m ikeash/ appswit cher/ ) AppSwit cher, by Michael Ash, is no longer being act ivit ely developed and is usable only under 10.1.x and below. I t brings up a horizont al overlay window ( like Microsoft Windows and Lit eSwit chX) , which shows your applicat ions sort ed by front t o back, in usage order. Like Lit eSwit chX, it 's free. Keyboard Maest ro ( ht t p: / / www.keyboardm aest ro.com / ) Keyboard Maest ro com es in a lim it ed Lit e edit ion and a full version at $20. I t 's m ore t han a sim ple applicat ion swit cher, as it allows m ult iple clipboards and hot keys wit h m ult iple act ions. Like t he ot her soft ware list ed earlier, it can sort running applicat ions in usage order, but also includes t he abilit y t o define applicat ions t hat should always or never be allowed in t he list . You can also t weak t he overlay window t o display vert ically, as opposed t o t he m ore com m on horizont al display. QuicKeys ( ht t p: / / www.cesoft .com / ) Finally, t here's t he popular QuicKeys from CESoft , which does far m ore t han m ere applicat ion swit ching, allowing you t o define m acros, hot keys, t ext insert ion, new float ing palet t es — t he list goes on and on. Available for $79.95, it includes t he abilit y t o swit ch applicat ions, giving you t he opport unit y t o set up a - Tab) t hat can swit ch forward, backward, or t o t he previously running applicat ion. hot key ( ot her t han Pricey t o som e, it encom passes t he abilit ies of a num ber of ot her ut ilit ies.
[ Team LiB ]
[ Team LiB ] Hack 35 Putting Things in the Apple Menu
Th e Fr u it M e n u h a x ie r e st or e s t h e a bilit y t o a dd fa vor it e a pplica t ion s, folde r s, a n d ot h e r t h in gs t o t h e Apple m e n u — a n d m or e . Alt hough Mac users are a t ried- and- t rue bunch, st alwart t o t he end, t here are oft en out cries when som et hing doesn't funct ion exact ly as users expect . Such m oaning was heard when OS X was released: " Where are m y beloved Apple m enu it em s?" Prior t o OS X, t he Macint osh had a feat ure t hat m any of us enj oyed: t he abilit y t o put it em s int o t he Apple m enu, be t hey folders, files, AppleScript s, or what have you. Thankfully, Unsanit y has ( re) delivered t his funct ionalit y wit h an excellent piece of soft ware called Fruit Menu ( ht t p: / / www.unsanit y.com / ) t hat 's j ust t he t icket ( see Figure 4- 2) . Figu r e 4 - 2 . Ch oosin g it e m s for you r Fr u it M e n u
Fruit Menu is a sm all download but packs a decent wallop, im m ediat ely becom ing a part of m any a user's essent ial soft ware downloads. Just as it suggest s, Fruit Menu allows you t o cust om ize t he Apple m enu, including cust om izat ion of cont ext ual m enus. And we're not j ust t alking about files and folders, eit her. The lat est version of Fruit Menu support s adding AppleScript s and shell script s t o your m enus, t he abilit y t o show your I P address ( and upon select ion, t o copy it t o t he clipboard, which is an im m ense t im e saver for dial- up users) , t he abilit y t o show current ly running applicat ions ( m uch like t he Syst em m enu from previous OSs) , inm enu pict ure previews ( like OS X's Preview pane) , as well as a Move To opt ion, allowing easy organizing across folders you define. To t op it off, you can also assign hot keys t o m ost of your Fruit Menu opt ions. The sim ilarit ies t o t he excellent FinderPop from OS 9 don't end t here eit her; m uch as you could order t he m enu it em s of FinderPop by nam ing your files and folders a cert ain way, Fruit Menu support s t he sam e synt ax, allowing you t o organize your power any way you wish. For only $7, Fruit Menu — along wit h t he m any ot her haxies t hat Unsanit y develops — is an excellent addit ion t o t he power user's arsenal.
[ Team LiB ]
[ Team LiB ] Hack 36 Keeping Your Snippets Organized
D r opD r a w e r s is on e of t h ose a pplica t ion s you h a ve t o t r y t o be lie ve . I t 'll k e e p a ll t h ose bit s a n d bobs lit t e r in g you r D e sk t op n e a t ly t u ck e d a w a y u n t il you n e e d t h e m a n d h e lps st a m p ou t st ick ie s pr olife r a t ion . Are you one of t hose people whose deskt op, bot h real and virt ual, is lit t ered wit h colorful st icky not es t oo num erous t o act ually see m uch of anyt hing else? While Jaguar's st ickies ( Applicat ions St ickies) provide disposable spaces int o which t o drop t hought s, URLs, phone num bers — anyt hing you can past e — it 's not part icularly well int egrat ed wit h your ot her applicat ions. A URL past ed int o a st icky can't , for inst ance, be doubleclicked and opened in your web browser. Even an alias t o a folder dragged int o a st icky doesn't m ean t he folder is j ust a double- click away. DropDrawers ( ht t p: / / www.sigsoft ware.com / dropdrawers/ ) ( $20; fully funct ional dem o available for download) by Sig Soft ware provides m uch- needed cubby holes for st owing and organizing t hose bit s and bobs t hat ot herwise clut t er up your Deskt op, browser's bookm ark list , or proliferat ion of yellow st ickies: file and folder aliases, URLs, script s, snippet s of t ext , and what have you. I f you can drag and drop it , you can st uff it in a DropDrawer. I nst all DropDrawers and you're provided som e sam ple drawers t o get you going: ● ● ● ● ● ●
A Processes drawer ( see Figure 4- 3) displays all t he applicat ions t hat are current ly act ive. The Launcher holds applicat ion short cut s. Web Sit es cont ains a collect ion of URLs. Text Clips is a clipboard for blocks of t ext . Miscellaneous is a reposit ory for m iscellaneous t ext snippet s, sound clips, and t he like. An onboard t ut orial provides quick- st art help for using DropDrawers. Figu r e 4 - 3 . Th e Pr oce sse s dr a w e r in t h e D ock
The drawers can be posit ioned anywhere on t he four edges of t he screen. They're opened by clicking on or m oving your m ouse ( configurable) over t heir t abs. Figure 4- 4 shows t he t abs for ot her sam ple draws. Figu r e 4 - 4 . Th e ot h e r sa m ple dr a w e r s
36.1 Launcher Drawer The Launcher provides short cut s t o com m only used applicat ions, as shown in Figure 4- 5. To creat e a short cut , drag an applicat ion icon ont o t he drawer. To launch an applicat ion, j ust click t he alias icon. Figu r e 4 - 5 . Th e La u n ch e r
36.2 Processes Drawer The Processes drawer displays a list of applicat ions current ly running. You can swit ch t o an app by clicking it s icon. Cont rol- click ( or right - click) t he icon and select Reveal, as shown in Figure 4- 6, t o display t he folder cont aining t he applicat ion.
Figu r e 4 - 6 . Sw it ch in g t o a n a pp w it h t h e Pr oce sse s dr a w e r
The Launcher and Processes drawers t oget her provide a decent st and- in for t he Dock — for t hose who dislike t he Dock, t hat is.
36.3 Creating More Drawers I f you run out of drawer space, you can creat e addit ional drawers at any t im e by select ing File as shown in Figure 4- 7.
New Drawer,
Figu r e 4 - 7 . Cr e a t in g a n e w dr a w e r
Every new drawer you creat e will be saved in t he Drawers folder, Library/ Preferences/ Drawers in your hom e direct ory.
36.4 Everything's Active and Configurable The m agic of DropDrawers is t hat everyt hing's act ive and double- clickable. Sounds and m ovies play, short cut s open t heir t arget s, URLs launch in your default browser, and t ext can be copied, past ed, edit ed, and st yled using t he built - in edit or.
DropDrawers is also configurable t o t he nt h degree. Every drawer has it s own Drawer Opt ions . . . ( see Figure 48) and Arrange Drawer . . . cont ext m enu. Figu r e 4 - 8 . D r a w e r Opt ion s . . . m e n u
—Wei- Meng Lee
[ Team LiB ]
[ Team LiB ] Hack 37 LaunchBar, a Dock Alternative
La u n ch Ba r pu t s j u st a bou t a n yt h in g e lse you m igh t w a n t w it h in e a sy r e a ch fr om you r k e yboa r d. More t han sim ply a Dock alt ernat ive, LaunchBar ( ht t p: / / www.obdev.at / product s/ launchbar/ ) is an int egral part of any alpha geek's t ricked- out OS X deskt op. You're j ust a keyst roke or t hree away from your files, apps, favorit e web sit es, em ail addresses, and j ust about anyt hing else you m ight want wit hin easy reach. I E launches I nt ernet Explorer, M swit ches m e t o Mail, NYT direct s m y browser t o The New York Tim es on t he Web. LaunchBar's engine suggest s closest m at ches according t o a com binat ion of it s own innat e sense ( read: adapt ive algorit hm s) of what your keyst rokes m ight m ean and what you've ended up choosing on previous occasions. I M m ight suggest Net I nfo Manager as t he t op choice t he first t im e you give it a whirl, but choose iMovie from t he list and you've t aught LaunchBar not t o m ake t he sam e m ist ake t wice. Figure 4- 9 shows t he LaunchBar in act ion. Figu r e 4 - 9 . La u n ch Ba r in a ct ion
Beyond what it s nam e suggest s, LaunchBar is quit e t he Alt - Tab st and- in, affording fast swit ching bet ween running apps. Assign single charact er short cut s t o your oft - used apps — M for Mail, O for Om niWeb, A for AI M, X for Excel — and you'll never visit t he Dock bet ween applicat ions again. Feeding LaunchBar's suggest ions is a default set of folders and files t o peek at upon st art up; each is associat ed wit h part icular file t ypes or at t ribut es t o m em orize: all applicat ions in Applicat ions, HTML links in I nt ernet Explorer Favorit es, sound files in your Music folder, and anyt hing in your hom e direct ory. You can, and indeed should, alt er t his list t o suit your fancy and aid LaunchBar in it s powers of suggest ion ( see Figure 4- 10) . Figu r e 4 - 1 0 . Con figu r in g La u n ch Ba r
LaunchBar is a com m ercial applicat ion ( $19.95 for personal use, $39.00 for business at t he t im e of t his writ ing) yet sport s a liberal evaluat ion license, t he only const raint being t he num ber of different it em s accessed via LaunchBar per session. While seven's t he lim it , you can act ually go a lit t le furt her if you don't m ind t he occasional nags. That said, it doesn't t ake long t o decide t hat LaunchBar is a m ust - have applicat ion.
[ Team LiB ]
[ Team LiB ] Hack 38 DockSwap, Another Dock Alternative
Avoid D ock bloa t w it h m u lt iple con figu r a ble D ock s. Whet her you love it or hat e it , OS X's Dock has been lam bast ed for being a user int erface night m are ( by an exApple int erface designer, no less) , while at t he sam e t im e receiving heart y cheers from fans of t abbed folders from OS 9. Eit her way, you m ay find yourself falling vict im t o Dock bloat , a sin m any consider wort hy of a few chuckles. Myself, I 'm a fan of t he Dock. I 've got m y recent ly used I nt ernet applicat ions first , t hen t ext edit ors, followed by m y file- sharing program s, t hen graphics, ut ilit ies, gam es, and folder pop ups. What I 'd really love would be t o get som e m ore of t hose vert ical lines in t here so t hat I can m ore clearly different iat e which applicat ions are in what cat egory. As you can im agine, m y Dock is pret t y full, pret t y sm all, and m agnifies grat uit ously. Needing a bet t er solut ion for m y Dock m adness, I cracked open DockSwap ( ht t p: / / www.pidog.com / OSX/ ) from piDog Soft ware and im m ediat ely st art ed having a blast organizing. You sim ply creat e a new Dock, swit ch t o it , and add and rem ove it em s at will unt il it 's j ust t he way you want it ( see Figure 4- 11) . Figu r e 4 - 1 1 . Th e D ock Sw a p m a in w in dow
Swit ch Docks via cont ext m enu ( ( Cont rol- Esc) .
- click on t he DockSwap Dock icon, as shown in Figure 4- 12) or key com m and
Figu r e 4 - 1 2 . Sw it ch in g D ock s u sin g t h e con t e x t m e n u
Wit h DockSwap, you can have a Dock for every occasion, and m ult iple Docks I soon did have. Here's m y current set up, swit chable wit h a m ouse click or key com m and: I nt ernet Tweakery I ncludes all m y browsers ( for t est ing web designs and accessing nonst andard sit es) , BBEdit , various filesharing program s ( like Hot line, Carracho, Acquisit ion, xNap, Fet ch, et c.) , diagnost ic ut ilit ies ( t he OS X Net work Ut ilit y, shell files for t cpdum p, et c.) , and various ot her applicat ions ( iCam Mast er, Snak, MTNewsWat cher, et c.) . Writ ing Cont ains various t ext edit ors — like BBEdit , Microsoft Word, and Text Edit ( wit h Ant iWordService [ Hack # 12] ) — and a healt hy dose of bookm arks for dict ionaries, t hesauri, clichés, word m eanings, and so on. I t also includes Sherlock for t hose quick encyclopedic/ knowledge- of- t he- Net searches. Gam es Rarely used because m y ext ra t im e is nonexist ent , but cont ains such favorit es as Snood, iColum ns, JewelToy, Solit aire Till Dawn, and m ore. I t includes a few bookm arks for quick searching at gam ers.com , gam efaqs.com , and MobyGam es. Having t hese out of t he way in a separat e Dock helps m e resist t he t em pt at ion t o procrast inat e accident ally. I could go on and on about m y Developm ent , Miscellany, and EveryDay Docks, but I t hink you get t he pict ure. DockSwap is yet anot her excellent RealBasic ut ilit y, available for a suggest ed shareware fee of $12.
[ Team LiB ]
[ Team LiB ] Hack 39 Tinkering with Your User Interface
Be a u t ify you r M a c's look - a n d- fe e l w it h t h e fr e e w a r e Tin k e r Tool Pr e fe r e n ce Pa n e . Despit e t he plet hora of built - in cust om izat ions, t weaks, beaut ificat ions, and alt erat ions t o t he look- and- feel of your Mac, t here are t im es when you want t o t ake t hings j ust t hat lit t le bit furt her. TinkerTool ( ht t p: / / www.bresink.de/ osx/ TinkerTool2.ht m l) ( freeware) gives you m uch t o t inker wit h. While som e of it s funct ionalit y has been subsum ed int o Mac OS X 10.2 ( Jaguar) , t here's st ill m uch you can do wit h TinkerTool t hat sim ply can't be done ot herwise. The lat est version has, in t urn, pulled in som e m ore of Jaguar's funct ionalit y, providing a one- st op cust om izat ion shop for your Mac GUI . TinkerTool's Preference Pane I nst aller ( see Figure 4- 13) drops t he app int o place sim ply and cleanly, allowing you t o choose whet her it 's available t o all users or j ust you. Figu r e 4 - 1 3 . Ru n n in g t h e Pr e fe r e n ce Pa n e I n st a lle r
There are several areas of set t ings t hat TinkerTool allows you t o cust om ize: ●
● ● ●
Feat ures relat ed t o t he Finder, such as t he effect s of opening files, num ber of lines shown for filenam es, and so fort h ( see Figure 4- 14) Dock placem ent , drop- shadows, t ransparent hidden applicat ions General posit ioning of scrollbar arrows, st art up/ login language Font s and font sm oot hing used by t he syst em and applicat ions Figu r e 4 - 1 4 . Usin g Tin k e r Tool
Som e of t he TinkerTool feat ures are grayed out in Jaguar, since t hey're applicable only t o t hose st ill running Mac OS X 10.1.
Som e feat ures require you t o rest art t he Finder, while ot hers require you t o rest art t he applicat ion before you can see t he changed effect . Fort unat ely, t he handy Relaunch Finder but t on m akes it easy t o rest art wit hout needing t o log out and back in again. Here's an overview of a few of t he m ore int erest ing TinkerTool feat ures.
39.1 Dock Position While Jaguar allows you t o place your Dock on t he left , right , or bot t om ( default ) of your screen, TinkerTool let s you define whet her it 's anchored in t he m iddle, st art , or end of t he screen. Figure 4- 15 is a screenshot of m y Dock t ied t o t he t op right . Figu r e 4 - 1 5 . D ock in g t h e D ock
39.2 Removing Arrows When you view a folder in colum n view, Jaguar displays an arrow next t o each it em . I f t hese arrows bot her you — as t hey do som e users — you can ask TinkerTool t o rem ove t hem ( see Figure 4- 16) . Figu r e 4 - 1 6 . Re m ovin g folde r a r r ow s in colu m n vie w
39.3 Displaying Multiple Lines of a Filename By default , t he Finder displays a m axim um of t wo lines for filenam es. TinkerTool allows you t o display up t o t hree lines, as shown in Figure 4- 17. This is useful if you t end t o use rat her long filenam es. Figu r e 4 - 1 7 . D ispla yin g lon g file n a m e s
39.4 Shadowing the Dock While windows in Jaguar have nice drop- shadows, int erest ingly enough, t he Dock does not . I f t his confuses your sense of perspect ive, go ahead and let TinkerTool add a shadow t o your Dock ( see Figure 4- 18) . Figu r e 4 - 1 8 . Givin g t h e D ock a n ice sh a dow
39.5 Changing the System Fonts Tired of t he syst em font ? You can change t he font s used by t he syst em as well as your applicat ions, as shown in Figure 4- 19. Figu r e 4 - 1 9 . Ch a n gin g fon t s
Be careful wit h t he font s you choose; inappropriat e font s can yield som e unpredict able result s, such as cropped sent ences, as shown in Figure 4- 20. Figu r e 4 - 2 0 . I n a ppr opr ia t e ch oice of fon t s
—Wei- Meng Lee
[ Team LiB ]
[ Team LiB ] Hack 40 Extending Your Screen Real Estate with Virtual Desktops
St r e t ch you r scr e e n r e a l e st a t e u p t o 1 0 0 t im e s it s size a n d or ga n ize diffe r e n t vie w s of you r w or k spa ce w it h vir t u a l de sk t op soft w a r e . Ever wish t hat you had a larger m onit or? While not everyone can afford t he 23- inch Apple Cinem a HD Display ( ht t p: / / www.apple.com / displays/ acd23/ ) , you can act ually achieve t he sam e effect ( wow! fact or not included) for as lit t le as $0 t o get . . . well . . . near t o unlim it ed screen real est at e!
40.1 CodeTek VirtualDesktop The CodeTek Virt ualDeskt op ( ht t p: / / www.codet ek.com / php/ virt ual.php) ( $40; t rial available) is an applicat ion t hat enhances your screen real est at e t hrough soft ware em ulat ion. I t does so by creat ing virt ual deskt ops, each cont aining what ever you put int o it and organized how you left it last . Keep your writ ing ( Word, BBEdit , Sherlock Thesaurus, and a browser window) on one screen, your m ail on anot her, and coding ( Applicat ion Builder, I nt erface Builder, Script Edit or, Term inal windows) in st ill anot her. Swit ching bet ween t hem is j ust a m at t er of a m ouse click. While t he t rial version allows for only t wo virt ual screens, it 's m ore t han enough t o get t he idea. Pay for Virt ualDeskt op and you can have up t o 100 virt ual screens! I nst alling CodeTek Virt ualDeskt op is st raight forward. Sim ply double- click on t he applicat ion icon and you are ready t o go. The first t hing you'll not ice is a m iniwindow known as t he pager. The pager displays t he virt ual deskt ops available t o you, organized on a grid, as shown in Figure 4- 21. You'll not ice t hat t he deskt op on t he left holds a browser window while t he one on t he right is st ill em pt y. Figu r e 4 - 2 1 . Th e Vir t u a lD e sk t op pa ge r
You can change t he skin ( appearance) of t he pager by creat ing one yourself or downloading one from CodeTek's sit e ( ht t p: / / www.codet ek.com / php/ virt ual_skins. php) .
There are so m any ways t o swit ch deskt ops, one or m ore of t hem will likely appeal. Click on a window in t he pager and you're t ransport ed t here inst ant ly. Mouse bet ween one deskt op and t he ot her by m oving off t he edge of t he screen in t he direct ion ( according t o t he grid layout ) of t he dest inat ion deskt op. Hot - key left , right , up, or down bet ween screens. Or use t he handy m enu- bar icon t o swit ch bet ween open applicat ion windows or hop t o anot her deskt op, as shown in Figure 4- 22. Figu r e 4 - 2 2 . Sw it ch in g via t h e m e n u ba r
Not only can you m ove yourself from one deskt op t o t he next , you can also drag applicat ions bet ween deskt ops. Eit her grab t he window you want and m ouse over t o t he appropriat e deskt op. Or drag and drop t he icon represent ing t he applicat ion in t he pager, as shown in Figure 4- 23. Figu r e 4 - 2 3 . M ovin g a w in dow fr om on e vir t u a l de sk t op t o a n ot h e r
CodeTek Virt ualDeskt op is ult raconfigurable. Pin part icular applicat ions down so t hat t hey appear on every deskt op; I do t his wit h iChat and iPulse [ Hack # 42] . Alt er t he pager's appearance, set hot keys, and configure t he layout of your virt ual deskt op grid ( see Figure 4- 24) . Figu r e 4 - 2 4 . Tw e a k in g pr e fe r e n ce s
Virt ualDeskt op is a m ust - have for t he m ult it asking geek in you.
40.2 Project Space.app I f you are not up for paying $40 for CodeTek Virt ualDeskt op, or if you are willing t o set t le for som et hing sim pler wit hout all t he bells and whist les, t hen Space.app ( ht t p: / / sourceforge.net / proj ect s/ space/ ) is a decent alt ernat ive. I t is free for personal and com m ercial use and dist ribut ed under t he open source GPL license. Space.app offers a user int erface sim ilar t o t hat of t he CodeTek, offering up t o 16 workspaces ( nam eable) and a float ing pager ( see Figure 4- 25) . Figu r e 4 - 2 5 . Th e Spa ce .a pp pa ge r sh ow in g n in e w or k spa ce s
Rat her t han creat ing act ual virt ual screens, Space.app operat es by rem em bering which applicat ion is shown or hidden in each view ( a.k.a. screen) . While it 's a decent st and- in for Virt ualDeskt op and t he price can't be beat , t he difference in feel and funct ionalit y is subst ant ial. You cannot , for inst ance, have t wo windows from t he sam e applicat ion open in t wo different spaces; it 's t he ent ire app or not hing at all. The refresh when swit ching from screen t o screen is also a lit t le j erky, as applicat ions are hidden and shown before your very eyes. —Wei- Meng Lee
[ Team LiB ]
[ Team LiB ] Hack 41 Top Screenshot Tips
Th e se scr e e n - ca pt u r e t ips pr ovide bu ilt - in a n d a dd- on solu t ion s t o j u st a bou t a n yt h in g you m igh t w ish t o sn a p. Capt uring good screenshot s in Mac OS X requires som e experim ent at ion. I f you sim ply want t o capt ure t he screen for reference lat er on, you can do it easily wit h t he built - in screen- capt ure t ool. However, if you are a professional writ er or a st udent preparing t hat t erm paper and need great - looking screen shot s, you have t o spend a lit t le m ore t im e exploring your opt ions. These screen capt ure t ips provide built - in and add- on solut ions t o j ust about anyt hing you m ight wish t o snap.
41.1 Built-Ins Mac OS X Jaguar com es wit h a built - in capabilit y for capt uring screenshot s. To capt ure t he ent ire screen, sim ply press - Shift - 3 and a PDF grab of your current view will appear on your deskt op. Screenshot s are num bered sequent ially, such as Pict ure 1.pdf, Pict ure 2.pdf, and so on. - Shift - 4 and highlight — using click- and- drag — what ever To capt ure a part icular region of t he screen, t ype port ion of t he screen you'd like, as shown in Figure 4- 26. Figu r e 4 - 2 6 . Ca pt u r in g a por t ion of t h e scr e e n
An ext ension t o region grabbing is snagging a pict ure of a part icular window or dialog box. Press - Shift - 4, t hen t he spacebar; any window you run your m ouse over will be highlight ed. Click t o capt ure it . You can t oggle back and fort h bet ween region and window m odes by pressing t he spacebar.
To change your m ind and cancel screen capt ure, press t he Escape ( Esc) key on your keyboard.
While t he built - in screen- capt ure t ool is good enough for j ust about all purposes, it has a couple of drawbacks. I t doesn't capt ure t he m ouse point er in any of t he screenshot s — not even opt ionally ( see Figure 4- 27) . This is a bust for t echnical writ ers explaining t he operat ion of m enus, but t ons, and so fort h. Second, while PDF is t he beall and end- all of all t hings GUI under Mac OS X, I need m y screenshot s in PNG or TI FF. Sure, I can convert t hem using Preview or t he like [ Hack # 51] , but t hat 's an ext ra st ep I sim ply shouldn't have t o t ake. Figu r e 4 - 2 7 . Th e cu r sor is n ot ca pt u r e d u sin g scr e e n ca pt u r e
41.2 Grab Ut ilit ies Grab) which support s t hree m odes of Mac OS X bundles a lit t le ut ilit y called Grab ( Applicat ions screen capt ure: screen, select ion ( a.k.a. region) , and t im ed screen ( capt ures t he ent ire screen aft er a specific t im e int erval) . Unlike it s built - in count erpart , Grab saves t o TI FF form at and opt ionally includes m ouse point ers in it s capt ures; it even allows you t o specify a preferred point er ( Grab
Preferences) , as shown in Figure 4- 28.
Figu r e 4 - 2 8 . Usin g t h e t im e d scr e e n m ode t o ca pt u r e a ct ion , m ou se poin t e r in clu de d
There is one problem t hat I not iced wit h t he select ion capt ure. I n order t o capt ure an act ive window using t he select ion m ode, you need t o swit ch t o Grab first . Yet doing so m akes t he window inact ive and fall t o t he background. Now, when I do a select ion grab, I want t o capt ure t he window in it s act ive st at e. The select ion grab will also display t he size of t he im age you are capt uring at t he bot t om right corner of t he select ion region. This is useful if you need t o capt ure im ages of an exact size. One gripe t hough: you can't creat e a region of a part icular size and t hen m ove it about .
Oddly, while Capt ure funct ional.
Window is list ed, it 's grayed out and doesn't appear t o be
41.3 Using Snapz Pro X The ult im at e screen- capt ure ut ilit y is Snapz Pro X ( $29, $49 wit h m ovie- capt ure support ; 30- day dem o available) from Am brosia Soft ware I nc. ( ht t p: / / www.am brosiasw.com / ut ilit ies/ snapzprox/ ) . I t sport s cust om izabilit y and m ult iple out put form at s, and it grabs t he screen as you see it , including or excluding t hat pesky m ouse arrow, at will.
Set up your shot and press - Shift - 3 ( cust om izable) t o freeze t he screen and t ake care of t he det ails, as shown in Figure 4- 29. You can choose t he ent ire screen, obj ect s ( windows or icons) , or a region, even during Quickt im e and DVD m ovie playback ( t he built - in screen capt ure feat rure is disabled while DVD Player is act ive) . Figu r e 4 - 2 9 . Ta k in g ca r e of Sn a pZ Pr o X scr e e n sh ot de t a ils
Select ion capt ure, com ing aft er you've set up your screen j ust t he way you like it ( see Figure 4- 30) , allows you t o t ake your t im e t o m ark out and alt er t he region before double- clicking it t o t ake t he final shot . Figu r e 4 - 3 0 . Ca pt u r in g a por t ion of t h e scr e e n
Snapz Pro X can even capt ure t he drop- shadows beneat h a window. Sim ply change t he Border opt ion under I m age Opt ions t o Drop Shadow. Prior t o Snapz Pro X, I 'd always have t o swit ch t he background t o whit e t o capt ure t he nice shadow around t he window wit hout including a slice of m y deskt op im age. There's so m uch m ore t o Snapz Pro X — like recording screen act ivit ies as a QuickTim e m ovie for purposes such as product dem os — t hat it 's difficult t o do it j ust ice in t his quick overview. Download t he 30- day t rial and give it a whirl yourself.
41.4 Screen Capture with Terminal Term inal [ Hack # 48] com es wit h a com m and- line version of t he built - in screen- capt ure ut ilit y, apt ly nam ed
s c r e e n c a p t u r e . For usage inst ruct ions, sim ply invoke it on t he com m and line: % s c r e e nc a p t u r e s c r e e nc a p t u r e : i l l e g a l u s a g e , f i l e r e q u i r e d i f n o t g o i n g t o c l i pb oa r d us a ge : s c r e e n c a p t u r e [ - i c mws Wx ] [ f i l e ] [ c u r s o r ] -i c a p t u r e s c r e e n i n t e r a c t i v e l y , b y s e l e c t i on o r wi n d ow c ont r ol ke y - c a us e s s c r e e n s hot t o go t o c l i pboa r d s pa c e ke y - t o g g l e b e t we e n mo u s e s e l e c t i o n a n d wi n d o w s e l e c t i o n mo d e s e s c a pe ke y - c a nc e l s i nt e r a c t i ve s c r e e n s hot -c f or c e s c r e e n c a pt ur e t o go t o t he c l i pboa r d -m o n l y c a p t u r e t h e ma i n mo n i t o r , u n d e f i n e d i f - i i s s e t -w o n l y a l l o w wi n d o w s e l e c t i o n mo d e -s o n l y a l l o w mo u s e s e l e c t i o n mo d e -W s t a r t i n t e r a c t i o n i n wi n d o w s e l e c t i o n mo de -x do not pl a y s ounds file wh e r e t o s a v e t h e s c r e e n c a p t u r e To capt ure t he ent ire screen, t ype s c r e e n c a p t ur e ~/ De s k t op / i ma g e . p df , where ~ / Deskt op/ im age.pdf is t he pat h and filenam e t o which you wish it saved. To capt ure t he screen int eract ively in regional or window m ode, use s c r e e n c a p t u r e - i i ma g e . p d f , as shown in Figure 4- 31.
Figu r e 4 - 3 1 . Usin g scr e e n ca pt u r e on t h e com m a n d lin e
I f you prefer t he out put t o go right t o t he clipboard rat her t han an im age file, use s c r e e n c a pt u r e - c . Of course, you can use t hese various com m and- line opt ions in t andem ; s c r e e nc a pt u r e - i c , for exam ple, is an int eract ive screen- capt ure session, sending t he result t o t he clipboard.
You can grab a screenshot of a rem ot e Mac's deskt op — or even t he login screen — t hanks t o s c r e e n c a p t u r e and som e not - so- fancy rem ot e access foot work [ Hack # 71] . Sim ply log in t o t he ot her Mac rem ot ely, run s c r e e n c a pt u r e on t he com m and line, and copy t he result ing screenshot s back over t o your local Mac.
—Wei- Meng Lee
[ Team LiB ]
[ Team LiB ] Hack 42 Checking Your Mac's Pulse
iPu lse pr ovide s a qu ick , color fu l ove r vie w of w h a t 's goin g on w it h you r M a c's CPU, m e m or y, dr ive s, a n d n e t w or k a ct ivit y u n de r t h e h ood. The I confact ory's ( ht t p: / / www.iconfact ory.com / ) iPulse ( ht t p: / / www.iconfact ory.com / ip_hom e.asp) ( $9 shareware) provides a visually appealing view of your Mac's vit als as your drives hum , m em ory churns, and net work flows away under your fingert ips ( see Figure 4- 32) . Figu r e 4 - 3 2 . Syst e m m on it or in g w it h iPu lse
Yes, it does st rike us as a lit t le esot eric and m ore t han a lit t le unnecessary at first blush. However, it 's well wort h t he few m inut es it t akes t o decipher it s int erface and t he few cycles it t akes t o leave it running in an unused corner of your deskt op. iPulse's gauges ( refer t o Figure 4- 32) m onit or:
● ●
● ●
CPU ut ilizat ion ( inner blue circle) , bot h user and syst em space Mem ory usage ( m iddle ring bet ween nine and t hree o'clock) in percent age used/ unused and page swapping in/ out ( out erm ost ring bet ween nine and t hree o'clock) Disk- space usage ( m iddle ring bet ween t hree and nine o'clock) wit h disk- full warning Net work t raffic ( out erm ost ring bet ween t hree and nine o'clock) , bot h in ( red) and out ( green)
Each gauge, along wit h it s graphical represent at ion, displays an absolut e value num erically for quick perusal. iPulse even sport s a nift y analog clock wit h second hand ( t hat black dot in Figure 4- 32) and day of m ont h ( t hat " 9" at t he t op of t he clock face) . iPulse is fully configurable via a set of preference panes, from which you can t urn part icular guages on and off, alt er t heir degree of granularit y, and fine- t une t he overall display. You can even choose not t o show iPulse as a float ing window, using inst ead it s t iny m irrored display in t he Dock icon. Don't dism iss iPulse out of hand as no m ore t han eye candy. Having spent five years as a syst em adm inist rat or,
I 've done m y share of syst em m onit oring via a plet hora of Term inal windows running t op , n e t s t a t , d f , and t he like — not t o m ent ion t he count less m onit oring script s firing em ail m essages at m e day and night like so m any part y favors. Figure 4- 33 gives you j ust a m ild t ast e. Figu r e 4 - 3 3 . Syst e m m on it or in g t h e old- fa sh ion e d w a y
Blech! I sure could have used iPulse for a quick updat e on how a part icular m achine was faring. Here's a neat idea for t hose wit h a Mac- based server farm : place iPulse at t he cent er of your deskt op and use Jaguar's fabulous screen zoom accessibilit y t o zoom it t o full screen for a passing glance at how your web, m ail, - 8 t urns on screen zoom ing; Opt ion- = zoom s in on t he m ouse point er or ot her server is coping. Opt ionand Opt ion-
- - ( t hat 's a m inus sign) zoom s back out again.
I t also m akes one heck of a st and- in for count ing sheep. ; - )
[ Team LiB ]
[ Team LiB ] Hack 43 Screensaver as Desktop
D r ive you r se lf t o dist r a ct ion by t u r n in g you r D e sk t op in t o a flu r r y of color or a n a ct ive slide sh ow . Som e hacks are j ust t oo cool t o bot her rat ionalizing. This is j ust such a hack. Type t he following int o a Term inal [ Hack # 48] window:
% / Sys t e m/ Li b r a r y / Fr a me wo r k s / Sc r e e n Sa v e r . f r a me wo r k / Re s o u r c e s / Sc r e e nSa v e r En g i n e . a p p / Co n t e n t s / Ma c OS/ Sc r e e n Sa v e r En gi n e - b a c k gr o un d Now lean back, press t he Ret urn key, and prepare t o be am azed. No, you're not im agining t hings; t hat is indeed your preferred screensaver running right sm ack dab on your Deskt op, behind and bet ween your running applicat ions ( see Figure 4- 34) . Figu r e 4 - 3 4 . Th e scr e e n sa ve r r u n n in g a s de sk t op
Probably t he m ost useful part of t his hack is t urning it off and ret urning your Deskt op t o it s unchanging self. To do so, t ype Cont rol- C in t he sam e Term inal window from which you st art ed t he screensaver running.
While any of t he screensavers will do, perhaps t he grooviest is Flurry, shown in Figure 4- 34. More serene, but no less im pressive, is one of t he slideshows: Forest , Cosm os, or Abst ract . Of course, a hom em ade slideshow com posed of snapshot s in your Pict ures folder will keep t hose near and dear t o you even nearer.
This hack is not for t he faint of CPU and RAM. While it 's possible t o keep t he screensaver running while get t ing t hings done — aside, of course, from t he ut t er dist ract ion it causes — it 'll eat up quit e a bit of your com put er's brainpower, slowing t hings t o a crawl on anyt hing but t he lat est hardware wit h plent y of m em ory.
As you m ight expect , t here are a num ber of freeware apps ( ht t p: / / www.versiont racker.com / m p/ new_search.m ? product DB= m ac&m ode= Quick&OS_Filt er= MacOSX&search= screensaver+ deskt op) available t o t urn t he deskt op screensaver on and off wit hout needing a visit t o t he com m and line.
[ Team LiB ]
[ Team LiB ] Hack 44 Dipping Your Pen into Inkwell
I n k w e ll, Apple 's h a n dw r it in g- r e cogn it ion t e ch n ology, h a s t h e pot e n t ia l t o pu t som e of t h e j oy ba ck in t o w r it in g by h a n d. The recent launch of t he Microsoft Tablet PC was accom panied by m aj or fanfare, hailing writ ing as a whole new way of using t he com put er. The Tablet PC is basically a not ebook equipped wit h a graphics t ablet built in t o allow users t o scribble not es on it . Behind t he hardware is t he Microsoft Windows XP Tablet PC edit ion, a souped- up version of Windows XP wit h handwrit ing- recognit ion capabilit ies. Unknown t o m any, surprisingly enough t o any longt im e Apple devot ee, Apple also possesses sim ilar handwrit ing recognit ion t echnology, dat ing from t he days of t he now- discont inued Newt on m essage pad ( ht t p: / / www.panix. com / ~ clay/ newt on/ ) . I n Mac OS X Jaguar, Apple has quiet ly shipped t he handwrit ing- recognit ion t echnology known as I nkwell ( ht t p: / / www.apple.com / m acosx/ j aguar/ inkwell.ht m l) . Let 's dip our pens int o I nkwell and see how it m easures up and how you can m ake use of it . First and forem ost , t o use I nkwell you need a graphics t ablet ; unfort unat ely, you cannot use a m ouse t o sim ulat e handwrit ing st rokes. Perhaps t his is one reason why I nkwell has not been widely used, as not everyone has a graphics t ablet . For m y experim ent at ion, I used t he I nt uos2 graphics t ablet from Wacom ( ht t p: / / www.wacom . com / ) , shown in Figure 4- 35. Figu r e 4 - 3 5 . A gr a ph ics t a ble t
The package com es wit h a t ablet , a pen, and a m ouse. For m ost of t he st uff t hat I am going t o show you, using t he pen is sufficient . But you m ay want t o consider using t he bundled m ouse; it 's wireless and glides nicely on t he t ablet . To invoke I nkwell, you need t o plug in your t ablet and inst all t he drivers provided by Wacom . A required rest art and you should find a new I nk icon under t he Hardware sect ion of your Syst em Preferences, as shown in Figure 436. Figu r e 4 - 3 6 . Th e I n k Syst e m Pr e fe r e n ce s icon
Before you st art using I nkwell, you need t o do a lit t le configurat ion. Click t he I nk icon. Under t he Set t ings t ab ( see Figure 4- 37) , you can configure I nkwell t o let you writ e anywhere on t he screen or only wit hin I nkPad ( m ore on t his in a m om ent ) . You can also set your handwrit ing st yle and fine- t une your writ ing st yle by clicking t he Opt ions... but t on. Figure 4- 38 shows t he I nk opt ions. Figu r e 4 - 3 7 . I n k Se t t in gs
Figu r e 4 - 3 8 . I n k Opt ion s
I n m y t est , I found t hat if you are a slow writ er, it is useful t o increase t he delay for handwrit ing recognit ion. The next t ab, Gest ures, cont ains support for gest ures. Anyone who's used a PDA — part icularly a Palm — will find t hese fam iliar. They're essent ially scribbled short cut s for com m on act ions you'd norm allly find under t he m enu bar's Edit m enu: Cut , Copy, Past e, Undo, Select All, and so fort h, as shown in Figure 4- 39. Figu r e 4 - 3 9 . I n k Ge st u r e s
The last t ab is Word List ( see Figure 4- 40) , which allows you t o ent er unusual words t hat you use oft en. I nkwell uses a built - in dict ionary, com paring words t hat you writ e against known com m on words and except ions you've added yourself. To speed up t he process, you should add words t hat are not found in t he dict ionary on t he fly ( I nkwell will t ell you if a word is found in t he dict ionary) . Figu r e 4 - 4 0 . I n k W or d List
Wit h configurat ion out of t he way, let 's get down t o work. Make sure t hat you have t urned on handwrit ing recognit ion, as shown in Figure 4- 41. Figu r e 4 - 4 1 . H a n dw r it in g r e cogn it ion
Whenever handwrit ing recognit ion is t urned on, t he I nkBar ( Figure 4- 42) will be float ing about som ewhere on your screen. Figu r e 4 - 4 2 . Th e floa t in g I n k Ba r
Of int erest are t he four icons: Com m and, Shift , Opt ion, and Cont rol. These icons allow you t o input special charact ers or com m ands wit hout using t he m ouse. For exam ple, if I want t o cut out a specific segm ent of t ext , I
can highlight t he t ext ( using t he ot her t ip of t he pen) and t ap on t he Com m and icon, t hen writ e x . You can input t ext int o your applicat ion wit h t he pen in t wo ways: using t he I nkPad or writ ing direct ly on t he applicat ion. To use t he I nkPad, click on t he I nkPad but t on and st art writ ing on your t ablet , as shown in Figure 443. Figu r e 4 - 4 3 . St a r t w r it in g on t h e t a ble t
The I nkPad is a t em porary writ ing space, not unlike a st icky. I n Figure 4- 43, I have opened a Text Edit docum ent and used t he I nkPad for writ ing. When you are done wit h t he writ ing, you can t ransfer your writ ing t o t he applicat ion by clicking t he Send but t on at t he bot t om of t he window. The Clear but t on clears t he cont ent of t he I nkPad. To creat e a drawing, you can click on t he Drawing but t on ( see Figure 4- 44) . Figu r e 4 - 4 4 . Cr e a t in g a dr a w in g
This is useful for signat ures or when you want t o insert drawings int o your docum ent s, as shown in Figure 4- 45.
Besides using t he I nkPad, you can also writ e direct ly ont o t he docum ent . I n t his case, you need t o set I nkwell t o writ e anywhere, as shown in Figure 4- 46. When you m ove your pen int o your applicat ion and st art writ ing, a yellow writ ing pad will be shown. The writ ing pad will expand as you writ e t o accom m odat e t he t ext t hat you are ent ering. Figu r e 4 - 4 5 . Sign a t u r e s
44.1 Makes You Wonder . . . While t he abilit y t o writ e direct ly int o m y applicat ion sounds cool, I am quit e skept ical of it s pract ical use. I am bet t er at t yping using m y keyboard, as it is definit ely m uch fast er t han scribbling ont o a t ablet . Furt herm ore, t he handwrit ing recognit ion requires you t o print t he charact ers in order t o achieve t he best result . I f you writ e like a doct or ( read: illegibly) , I nkwell is going t o have a lot of t rouble deciphering your handwrit ing. I n m y t est , it works quit e well when I print slowly. Cursive writ ing is definit ely not recom m ended. While I nkwell has t he pot ent ial t o bring back som e of t he j oy of writ ing t o t he keyboard- addict ed geek, as yet it is of lim it ed pract ical use. Figu r e 4 - 4 6 . W r it in g a n yw h e r e
—Wei- Meng Lee
[ Team LiB ]
[ Team LiB ] Hack 45 Speakable Web Services
Ex plor e M a c OS X's spe e ch r e cogn it ion a n d it s su it a bilit y for bu ildin g u se fu l, voice - dr ive n com m a n ds t h a t in vok e e x t e r n a l a s w e ll a s loca l w e b se r vice s. When Scot t y t ried t o t alk t o a Macint osh t hrough it s m ouse in St ar Trek I V ( 1986) , t he j oke was on Apple. Why couldn't t his fam ously easy- t o- use com put er accept t he m ost nat ural form of input ? Over t he years, I dabbled now and t hen wit h voice com m and syst em s, but t hey never seem ed wort h t he t rouble — unt il now. I 've been exploring t he speech t echnologies in Mac OS X on an 800MHz TiBook, and I 'm really im pressed. Apple has done a m arvelous j ob wit h t he recognit ion and cont rol syst em s, and now t hat you can script t he I nt ernet so easily in OS X, it 's st raight forward t o build useful voice- driven com m ands t hat invoke ext ernal as well as local services. Consider t his dialog: Me: " Tem perat ure" Com put er: " 36 degrees" There are, of course, a m illion ways t o look up t he t em perat ure on t he Web. Most of t hem st art wit h t he browser. You fire it up and go t o a bookm ark, which in m y case is ht t p: / / www.weat her.com / weat her/ local/ 03431. There are at least t wo problem s wit h t his scenario. First , you have t o t ranslat e t he request int o an applicat ion cont ext ( t he browser) and a procedure ( go t o bookm arks, select Local Weat her) . Second, you dest roy your original cont ext . For exam ple, I 'm t yping t hese words in t he Em acs Term inal- based t ext edit or. I 'd like t o keep on t yping, and reading what I am writ ing, even as I ask for and receive t he t em perat ure. Speaking t he request and hearing t he response is an ideal solut ion. Here are a few ways t o im plem ent it .
45.1 Perl and AppleScript Working Together I st art ed wit h a Perl script t hat uses SOAP: : Lit e t o hit a web service at XMet hods ( ht t p: / / www.xm et hods.com ) , like so:
#! / us r / b i n / p e r l - w us e s t r i c t ; us e SOAP: : Li t e ; my $t e mp = SOAP: : Li t e - > s e r v i c e ( ' h t t p : / / www. x me t h o d s . n e t / s d / 2 0 0 1 / Te mp e r a t u r e Se r vi c e . ws d l ' ) - > ge t Te mp ( ' 0 3 4 3 1 ' ) . " d e g r e e s " ; ` o s a s c r i p t - e ' s a y " $ t e mp " ' ` ; Here, we're using Perl's backt ick evaluat ion t o run a com m and- line t ool, os a s c r i p t , which runs AppleScript code — in t his case, t o speak t he result of t he SOAP call. Use of t he t ext - t o- speech engine int roduces som e fascinat ing subt let ies. For exam ple, if you om it t he leading space in degrees, t he answer will sound like: t hree six period zero dee eee gee are eee eee ess
I t would be handy if you could j ust save t his as a file called Tem perat ure in t he Speakable I t em s folder ( for exam ple, / Users/ j ohn/ Library/ Speech/ SpeakableI t em s) and launch it by speaking t he nam e " t em perat ure." But so far as I 've been able t o det erm ine, script ed speakable it em s ( as opposed t o t hose t hat invoke key- driven com m ands) have t o be writ t en in AppleScript and, furt her, saved from t he script edit or as t ype applicat ion ( not t ext or com piled script ) . Fort unat ely, AppleScript can invoke t he Unix shell, which can invoke t he Perl script . Let 's refact or slight ly, and have t he Perl script sim ply ret urn a bare value, suit able for downst ream use in any kind of applicat ion, whet her voice- enabled or not :
#! / us r / b i n / us e s t r i c t ; us e SOAP: : Li pr i nt SOAP: : - > s e r vi c e ( ' - > ge t Te mp ( '
pe r l - w t e; Li t e h t t p : / / www. x me t h o d s . n e t / s d / 2 0 0 1 / Te mp e r a t u r e Se r v i c e . ws dl ' ) 03431' ) ;
I saved t hat script as / Users/ j on/ Tem perat ure and t hen saved t he following AppleScript applicat ion as / Users/ j on/ Library/ Speech/ SpeakableI t em s/ Tem perat ure:
s e t t he Re s u l t t o d o s h e l l s c r i p t " / Us e r s / j o n / Te mp e r a t u r e " s a y t he Re s u l t & " d e g r e e s " a s s t r i n g Now, t he t ext ual result of t he Te mp e r a t u r e script is spoken by AppleScript . You can, alt ernat ively, do t he whole t hing in AppleScript , like so:
t e l l a ppl i c a t i o n " h t t p : / / s e r v i c e s . x me t h o d s . n e t : 8 0 / s o a p / s e r v l e t / r p c r o ut e r " s e t t he Re s u l t t o c a l l s o a p { me t h o d n a me : " g e t Te mp " , \ pa r a me t e r s : { z i p c o d e : " 0 3 4 3 1 " } , me t h o d n a me s p a c e \ ur i : " u r n : x me t h o d s - Te mp e r a t u r e " , SOAPAc t i o n : " / Te mp e r a t u r e Se r vi c e " } e nd t e l l s a y t he Re s u l t & " d e g r e e s " a s s t r i n g This is easier in one way, harder in anot her. I t 's easier if you're not a Perl program m er or if you haven't added SOAP: : Lit e and it s required subst rat e ( e x p a t , XML: : Parser) t o t he Perl kit t hat com es wit h Mac OS X. But when a web service is described by a Web Services Descript ion Language ( WSDL) file, it 's easier t o use SOAP: : Lit e t han AppleScript , since t he form er can use t he WSDL file t o sim plify access. I t 's ideal when t here's a web service t hat will give you t he answer you're looking for, but when t hat 's not t he case, t here's always good old HTML screen- scraping. I n t hat case, a language like Perl or Pyt hon will run rings around AppleScript . Here's a script t hat speaks m y weblog's current rank and page- view count for t oday:
! / us r / bi n / p e r l - w us e s t r i c t ; us e LWP: : Si mp l e ; my $r e s = g e t " h t t p : / / www. we b l o g s . c o m/ r a n k i n g s By Pa ge Re a d s . h t ml " ; $r e s =~ m# ( . +) J o n ' s Ra d i o ( \ d +) &n bs p; # ; my $pr e f a c e = $ 1 ; my $c ount = $ 2 ; $p r e f a c e =~m# " >( \ d +) \ . &n b s p ; # ; my $r a nk = $ 1 ;
' o s a s c r i p t - e ' s a y " Ra n k $ r a n k , c o u n t $ c o u n t " ' ' ; I n t his case, it 's m ore t rouble t han it 's wort h t o ret urn raw result s from Perl and form at t hem for speech out put in AppleScript . I have t o confess I 'm st ill t em pt ed t o dism iss t his speech st uff as an am using parlor t rick. But it m ay finally be reaching a t ipping point . Look, Dad's t alking t o t he com put er, m y kids snickered. When I showed m y son he could play GnuChess using voice com m ands, t hough, he was rivet ed. I t 's a case- by- case t hing, but when an applicat ion has a lim it ed cont rol vocabulary ( " pawn a2 t o a4" ) , t he Mac's speaker- independent speech recognit ion can give you hands- free cont rol t hat 's accurat e and m ore effect ive t han m ouse cont rol. Well, t o be honest , m ost ly accurat e. I 'm having a lit t le t rouble get t ing GnuChess t o dist inguish bet ween " d" and " e" — a problem t hat could be solved by also support ing " delt a" and " echo." Not m any of t he XMet hods services are likely candidat es for voice t reat m ent . Com plex input s and out put s don't m ake m uch sense. You can build I VR- st yle ( int eract ive voice response) m enus, like so:
t e l l a ppl i c a t i o n l oc a l c h o i c e s s e t c ho i c e s t o s e t t he Pr o mp t t try s e t t h e Re s u l t up a f t e r 1 0 s a y ( do s he l l e nd t r y e nd t e l l
" Sp e e c h Re c o g n i t i o n Se r v e r " { " Te mp e r a t u r e " " Bl o g St a t s " } o " Wh a t d o y o u n e e d t o k n o w? " t o l i s t e n f o r c h o i c e s wi t h p r o mp t t h e Pr o mp t g i v i n g RETURN s c r i p t " / Us e r s / J o n / " & t h e Re s u l t )
Unless you really want t o inflict voice t rees on yourself, t hough, you'll probably soon t ire of t his approach, once t he novelt y wears off. Com plex out put is a nonst art er as well. I t 's fast er t o read t han t o hear m ore t han a word or short phrase, t he Mac's synt hesized voices work best on short snippet s, and t here's no way for t he com put er t o usefully speak st ruct ured out put .
45.2 Namespace Management The nam espace m ode of t he files in t he Speakable I t em s folder is act ive syst em wide. There are separat e perapplicat ion nam espaces. For exam ple, t he Speakable I t em s/ I nt ernet Explorer subfolder defines voice com m ands j ust for MSI E. You can, in fact , ext end t hat nam espace in a hands- free m anner, using t he " m ake t his page speakable" voice com m and. I f t he current page is ht t p: / / news.google.com , for exam ple, t hen " m ake t his page speakable" prom pt s wit h t he page's HTML doct it le, Google News. When t he prom pt is act ive, t he valid speech com m ands are " save" and " cancel." I f you say " save," you will creat e a voice- act ivat ed bookm ark t riggered by t he phrase " Google News." Pret t y darned slick! I t 's I E- specific, t hough, and t hat 's a sham e because I prefer Mozilla on t he Mac t o t he I E version ( 5.2) t hat cam e wit h t he TiBook. The per- applicat ion nam espaces are segregat ed from one anot her, but as you ext end t he m ain nam espace, you'll st art t o run int o conflict s. New com m ands t hat sound t oo m uch like exist ing ones will cause m isrecognit ion. The problem is easily solved, t hough. Just open t he Speakable I t em s folder and renam e files — eit her preexist ing it em s or your new it em s — in order t o st ep around t hese conflict s. As you build up vocabularies, it 's easy t o forget t hat t he recognit ion engine is speaker- independent , not languagedependent . For exam ple, I 've been enj oying Brent Sim m ons' Huevos [ Hack # 85] , a nift y lit t le t ool t hat can float
in a sm all window and send a search t erm t o any of a user- defined set of web sit es. The voice com m and t o launch it — " swit ch t o Huevos" — works best when I anglicize t he nam e as " Hoo- eee- vos." Apple's sit e says t hat a Spanish recognizer is available but , for now, I 'm st ill t rying t o decide whet her t o m angle t he pronunciat ion of " Huevos" or renam e it for speech purposes. Speech cont rol of com put ers is m ainly considered t o be an assist ive t echnology. I n m y case, t here's cert ainly an elem ent of t hat . Aft er t oo m any years of t yping and m ousing, m y wrist s are chronically sore, and I 'm happy t o avoid all keyst rokes and m ouse clicks t hat I can. Most of t hat wear and t ear is from writ ing and program m ing, t hough, so unt il I can com e t o t erm s wit h dict at ion ( as, I 'm t old, t he prolific aut hor David Pogue has done) , voice cont rol won't help m uch. But Apple's im plem ent at ion has m ade m e ret hink t he m ixed- m ode user int erface. Consider, for exam ple, t he m echanism for picking one of t he 50 U.S. st at es in a web form . Som e sit es ask you t o t ype t he t wo- let t er abbreviat ion, but m ost offer a picklist . Scanning a list of 50 it em s is unproduct ive. I can use com plet ion t o skip t o t he N sect ion of t he list , but adding an H t akes m e t o Hawaii, not New Ham pshire. Here's a well- defined nam espace t hat could probably be accessed using speech m ore quickly and nat urally t han by any ot her m et hod. I suspect t he sam e holds t rue for m any m ult iple- choice sit uat ions in dat a ent ry form s and elsewhere. Consider anot her Brent Sim m ons applicat ion, t he popular RSS newsreader Net NewsWire [ Hack # 87] . I t 's already m ore usefully speakable t hen m ost OS X apps I 've t ried. Along wit h m enu navigat ion, you can speak t he crucial com m ands " next unread," " m ark all as unread," and " open in browser." These are m ore m nem onic t han t heir - G, - Shift - K, and - B) and, especially in t he case of - Shift - K, m ore accessible keyboard equivalent s ( t oo. An int erest ing refinem ent would be t o voice- enable random access t o feeds, j ust as MSI E allows spoken random access t o it em s on t he Go and Favorit es m enus. I 've got 128 subscript ions, for exam ple. I t would be cool t o say " Sam Ruby" and j um p st raight t o Sam 's blog. Or t o say " Jerem y" and j um p t o a com plet ion list showing Allaire and Zawodny, and speak one of t hose surnam es t o finalize t he select ion. As soft ware services m ult iply, so do t heir cont rol vocabularies. XML m anages t his proliferat ion using nam espaces. Per- applicat ion or per- service speech- enabling can use t he sam e st rat egy t o reduce t he hard problem of openended speech recognit ion t o an easier one t hat can be solved in useful and pract ical ways. —Jon Udell
[ Team LiB ]
[ Team LiB ] Hack 46 Using AppleScript in Contextual Menus
Ra n ch e r o's BigCa t is a plu g- in t o M a c OS X, a llow in g you t o r u n Apple Scr ipt s via a n e w Scr ipt s it e m in you r con t e x t u a l m e n u s. Back in t he old days, t here was a m agical lit t le ut ilit y called FinderPop ( ht t p: / / www.finderpop.com / ) . FinderPop was pre- OS X, and m any users saw t hat it was good . . . very good, in fact . Along wit h a healt hy dose of ot her feat ures, you could add a num ber of new abilit ies t o your cont ext ual m enu, including t he abilit ies t o browse com pressed archives, change file t ypes, run AppleScript s, and m ore. FinderPop, sadly, won't ever exist for OS X, but what else do we have? Ent er BigCat from Ranchero Soft ware ( ht t p: / / www.ranchero.com / ) . Wit h one sim ple 185K free download ( read t hat again, eh? 185K! ) , you can inst all a plug- in for OS X t hat will allow you t o run AppleScript s via a new Script s it em in your cont ext ual m enus. True t o it s purpose, BigCat operat es on cont ext . When you inst all t he BigCat script s, t here are t wo subfolders: one for Text , which includes such basic exam ples as Copy, Google Search, and Open Select ion in BBEdit , and t he ot her called Files, cont aining Copy Pat h, Open in Text Edit , and St uff ( i.e., Archive wit h St uffit ) . Even t hough t here are t wo folders, you'll see only one based on — you guessed it — cont ext . Got som e t ext highlight ed? You'll see only t he script s in t he Text folder will be shown. Select ed a bunch of files? Only t hose in t he Files folder. This is an im port ant advant age over ot her ut ilit ies like Script Menu, now shipped by default wit h Jaguar. Sure, you can run AppleScript s on t he current select ion via Script Menu, but you'll also see all t he script s t hat have no effect on t he current select ion ( Current Dat e and Tim e, et c.) . BigCat m akes hit t ing t he right script a lot easier. And what about changing file t ypes and creat ors [ Hack # 6] ? For a pure AppleScript solut ion, changing a file's info t o t hat of a com m on GI F is done like t his:
t e l l a ppl i c a t i o n " Fi n d e r " s e t f i l e l i s t t o s e l e c t i on a s l i s t e nd t e l l t e l l a ppl i c a t i o n " Fi n d e r " r e pe a t wi t h i i n f i l e l i s t s e t f i l e t y p e o f i t o " GI Ff " s e t c r e a t or t ype of i t o " ogl e " e nd r e p e a t e nd t e l l Or, if you want ed t o run a shell script , you could wrap it in an AppleScript as well. Here's t he sam e script as before, only using t he ut ilit ies provided wit h t he Developer Tools CD:
t e l l a ppl i c a t i o n " Fi n d e r " s e t f i l e l i s t t o s e l e c t i on a s l i s t
e nd t e l l t e l l a ppl i c a t i o n " Fi n d e r " r e pe a t wi t h i i n f i l e l i s t s e t ma c Fi l e Pa t h t o ( i a s a l i a s ) s e t u n i x Fi l e Pa t h t o POSI X p a t h o f ma c Fi l e Pa t h s e t c o mma n d t o " / De v e l o p e r / To o l s / Se t Fi l e - c o g l e - t GI Ff " & RETURN uni xFi l e Pa t h do s h e l l s c r i p t c o mma n d e nd r e p e a t e nd t e l l
[ Team LiB ]
[ Team LiB ] Hack 47 Prying the Chrome Off Cocoa Applications
M e t a llifize r pa in t s a n d st r ips t h e br u sh e d- m e t a l a ppe a r a n ce of a n y Cocoa a pplica t ion . There are t wo t ypes of Mac users: t hose who find t he brushed- m et al look- and- feel of iTunes, Address Book, iChat , and t he like j ust plain fab and t hose who wonder what som e of t hese app designers are t hinking wit h all t his fut urist ic nonsense. Thank heavens for Met allifizer ( ht t p: / / www.unsanit y.com / download.php? product = m et allifizer) ( freeware) , anot her t errific haxie from t he folks at Unsanit y. Give any Cocoa applicat ion t hat brushed- m et al appearance if you're so inclined. Or pry t he default chrom e right off t hat ot herwise- favorit e app.
Perhaps a quick recap of t he t hree Mac OS X applicat ion t ypes is in order. Classic refers t o applicat ions built pre- Mac OS X; t hese run in Classic m ode, effect ively a Mac OS 9 em ulat or. Carbon applicat ions have been m odified t o run under bot h Mac OS X and Mac OS 9; exam ples include: iMovie, I nt ernet Explorer, QuickTim e, and iTunes. Cocoa applicat ions — like iChat , iPhot o, and t he Address Book — are built specifically for Mac OS X. Met allifizer works only on t he last cat egory of applicat ions.
47.1 Installation Met allifizer is a m odule for Unsanit y's Applicat ion Enhancer ( APE) haxie ( ht t p: / / www.haxies.com / ape/ ) . You'll need t o download and inst all it before you can use Met allifizer. Figure 4- 47 shows t he APE preference pane. Figu r e 4 - 4 7 . Th e APE pr e fe r e n ce pa n e
Wit h APE inst alled, download and inst all Met allifizer by dragging it int o your Library/ Applicat ion Enhancers folder, as shown in Figure 4- 48. I f t he folder doesn't yet exist , go ahead and creat e it . Figu r e 4 - 4 8 . I n st a llin g M e t a llifize r
You'll need t o log out and back in again before t he Met allifizer will work. Once you've done so, open t he Syst em Preferences
APE Manager preference pane, shown in Figure 4- 49. Figu r e 4 - 4 9 . M e t a llifizin g a n d de m e t a llifizin g a pplica t ion s
You'll not ice t hat t he Met allifizer plug- in is in operat ion; it s checkbox should be checked. Alt ering t he appearance of an applicat ion is t hen j ust a m at t er of adding it t o or rem oving it from t he APE Manager and select ing Met allifize ( add t he brushed- m et al effect ) or Dem et allifize ( rem ove t he brushed- m et al effect ) .
Figure 4- 50 shows what iSync looks like before and aft er dem et allifizing. Figure 4- 51 shows a before and aft er com posit e for Text Edit , t he ubiquit ous Mac OS X t ext edit or — not m et allifized by default . Figu r e 4 - 5 0 . iSyn c be for e a n d a ft e r
Figu r e 4 - 5 1 . Te x t Edit be for e a n d a ft e r
—Wei- Meng Lee
[ Team LiB ]
[ Team LiB ] Chapter 5. Unix and the Terminal
Sect ion 5.1. Hacks # 48- 65 Hack 48. I nt roducing t he Term inal Hack 49. More Term inal Tricks and Tips Hack 50. Becom ing an Adm inist rat or for a Mom ent Hack 51. Edit ing Special Unix Files Hack 52. Set t ing Shell Environm ent Variables Hack 53. Scheduling wit h Syst em Tasks and Ot her Event s Hack 54. Opening Things from t he Com m and Line Hack 55. I nt roducing and I nst alling t he Mac OS X Developer Tools Hack 56. Top 10 Mac OS X Tips for Unix Geeks Hack 57. Turning a Com m and- Line Script int o an Applicat ion Hack 58. I nst alling Unix Applicat ions wit h Fink Hack 59. Mirroring Files and Direct ories wit h rsync Hack 60. Using CVS t o Manage Dat a on Mult iple Machines Hack 61. Downloading Files from t he Com m and Line Hack 62. Soft ware Updat e on t he Com m and Line Hack 63. I nt eract ing wit h t he Unix Shell from AppleScript Hack 64. Running AppleScript s on a Regular Basis Aut om at ically Hack 65. Running Linux on an iBook
[ Team LiB ]
[ Team LiB ] 5.1 Hacks #48-65 Beneat h t he sleek, elegant , Technicolor — and, yes, at t im es whim sical — candy coat ing of Mac OS X's graphical user int erface beat s t he heart of an honest - t o- goodness Unix operat ing syst em . I t 's a world of high- cont rast plain t ext , at first blush not ent irely unlike t he m uch- m aligned DOS shell of t he Windows world. While m uch of a Mac user's life is lived above t he deskt op abst ract ion, an occasional dip beneat h t he surface brings powers unim aginable and sim ply not possible wit h a point - and- click int erface. There are servers t o run, rem ot e m achines t o m anipulat e, set t ings t o t weak, event s t o schedule, and m ore. Many of t he hacks in t his book are best dealt wit h on t he com m and line. This chapt er provides a gent le int roduct ion t o t he com m and- line environm ent : how t o m ove around and m anipulat e files and folders ( t hey're called direct ories down here) . Wit h t hat under your belt , we'll show you how t o t hread som e of t he built - in Unix applicat ions and funct ions t oget her t o creat e new funct ionalit y and const ruct com m and- line applicat ions t o m eet your needs. You'll edit special Unix files, t ransfer files t o and from ot her com put ers on t he I nt ernet , schedule event s for regular invocat ion, and even becom e t he all- powerful adm inist rat ive, or root , user for a m om ent or t wo.
[ Team LiB ]
[ Team LiB ] Hack 48 Introducing the Terminal
Th is br ie f t ou r of t h e Te r m in a l in t r odu ce s you t o som e of t h e m or e ba sic com m a n ds r e qu ir e d t o fin d ou t w h e r e you a r e , m ove a bou t , m a n ipu la t e file s a n d dir e ct or ie s, a n d ge t ba ck ou t a ga in w h e n you 've h a d e n ou gh . This brief t our of t he Term inal assum es you're eit her an old- t im e Mac hand who's been t hanking your lucky st ars you've never been near a com m and- line int erface ( CLI ) or a recent Windows swit cher who's been previously scared away by t he com plexit y or unim pressed by t he funct ionalit y of t he rat her ill- equipped DOS shell. I t is m eant as a quick- st art guide, int roducing you t o som e of t he m ore basic com m ands required t o find out where you are, m ove about , m anipulat e files and direct ories, and get back out again when you've had enough. Com e on in, t he wat er's fine!
48.1 Launching the Terminal To invoke t he Term inal, choose Applicat ions
Ut ilit ies
Term inal, as shown in Figure 5- 1.
Figu r e 5 - 1 . La u n ch in g t h e Te r m in a l
A few Dock bounces lat er and you'll have a fresh Term inal window in which t o work ( see Figure 5- 2) . The Term inal inform s you about t he dat e of your last visit and welcom es you t o Darwin, t he Unix core of Mac OS X.
Need anot her Term inal window? Sim ply click File anot her will m ake it self available t o you.
New Shell or
Figu r e 5 - 2 . A fr e sh Te r m in a l w in dow
- N and
All t hat [ Ap p l e - s - Co mp u t e r : ~] we i me n g l e e % j azz is known as t he prom pt and provides som e useful inform at ion about your current working environm ent . The bit before t he : is your com put er's nam e ( set in t he Syst em Preferences Sharing pane) . Aft er t he : is your current pat h, or whereabout s on your hard drive. I n t his case, I 'm in m y hom e direct ory, referred t o coloquially as ~ ( t hat 's a t ilde, found on t he t op left of your keyboard) ; were I in t he Applicat ions folder, m y locat ion would read as : / Ap pl i c a t i on s . The bit j ust before t he % is your usernam e — we i me n g l e e , in m y case. You'll be issuing all your com m ands at t he prom pt , wit h t he cursor — t hat black block — keeping t rack of your t yping in m uch t he sam e way t he I - beam does in your t ext edit or. Typing fingers ready? You're ready t o issue your first com m and.
48.2 Current Working Directory Let 's m ake sure we know where we are, shall we? Type pwd , short for " print working direct ory" :
[ Ap pl e - s - Co mp u t e r : ~] we i me n g l e e % p wd / Us e r s / we i me n g l e e Unless you've gone anywhere since opening your Term inal window, you should be in your hom e direct ory, / Users/ login, where login is your Short Nam e [ Hack # 1] on t he syst em . Again, t his is t he sam e as t he ~ short cut . That 's all well and good, but where exact ly is / Users/ weim englee wit h respect t o t he folders in t he m ore fam iliar Finder? The screenshot in Figure 5- 3 should help you t o get your bearings. Figu r e 5 - 3 . Th e cu r r e n t w or k in g dir e ct or y in t h e Fin de r
While in t he Finder we have folders, in Term inal we call t hem direct ories. Subdirect ories are delim it ed by a / ( forward slash) charact er. Swit chers, not e t hat Windows uses \ ( backslash) t o delim it subdirect ories, as in c: \ m ydocu~ 1. Rem em ber t o use / on t he Mac com m and line.
Backslash, under Unix, has m agical propert ies of it s own. I t 's used t o escape or call out special charact ers like spaces, quest ion m arks, or t he like. You'll m ost likely use it for dealing wit h files cont aining spaces on t he com m and line, let t ing Unix know t hat you're st ill t alking about t he sam e file and haven't m oved on t o anot her. Not ice t he sem ant ic difference bet ween t he file t his\ is\ one\ file versus file1 file2 file3.
48.3 List Files and Folders Now t hat you know your whereabout s, let 's t ake a gander at t he cont ent of t he current direct ory. The l s ( list ) com m and displays t he cont ent of a part icular direct ory:
[ Ap pl e - s - Co mp u t e r : ~] we i me n g l e e % l s De s kt op Do c u me n t s Li b r a r y Mo v i e s Mu s i c Pi c t u r e s Pu b l i c Si t e s The l s com m and in t his exam ple displays t he cont ent of t he current direct ory. You can also ask l s t o list t he cont ent s of a specific direct ory and display t he result in a part icular form at by passing it com m and- line opt ions and a direct ory nam e. I n t he Term inal, com m ands are in t he form at Co mma nd - o pt i on s pa r a me t e r . Opt ions are prefixed by a ( hyphen) ; when t here are m ore t han one, t hey're pushed t oget her. As shown in Figure 5- 4, l s - a l
Do c u me n t s asked l s t o list all ( - a ) t he files using a longer ( - l ) list ing form at
in t he Do c u me n t s direct ory. Figu r e 5 - 4 . Ou t pu t ge n e r a t e d by ls - a l
By default , files beginning wit h . ( dot ) will not be displayed by l s . To display t hem , use t he - a opt ion. The t wo files list ed wit h nam es . and . . are special files known as t he current and parent direct ory, respect ively. Occasionally, you m ay have a long file list ing, wit h out put flowing off t he t op of t he screen. To page t hrough, one screenful at a t im e, send — known as piping because of it s use of t he | ( pipe) charact er — t he out put t o t he mor e com m and:
[ Ap pl e - s - Co mp u t e r : ~] we i me n g l e e % l s - a l |
mo r e
48.4 Clearing the Screen Aft er t rying out t hese com am nds, your screen will no doubt be full of files and direct ories. To clear t he screen, t ype c l e a r or press Cont rol- L.
48.5 Changing Directories To m ove about , issue a c d , or change direct ory, com m and, specifying a direct ory as t he param et er. This is akin t o opening a folder in t he Finder. For exam ple, let 's m eander over t o t he Public direct ory:
[ Ap pl e - s - Co mp u t e r : ~] we i me n g l e e % c d Pu b l i c [ Ap pl e - s - Co mp u t e r : ~/ Pu b l i c ] we i me n g l e e % Not ice how t he current direct ory — t he bit aft er t he : in your prom pt — changes t o ~ / Public. This is a const ant rem inder of where you are at any m om ent in t im e; no need t o keep t yping c wd t o find out . Rem em ber t hat t he ~ refers t o your hom e direct ory; so, in t his case I 'm act ually in / Users/ weim englee/ Public. There are t wo ways of specifying a part icular direct ory. The first is t o use t he absolut e or full pat h ( e.g., c d / Us e r s / we i me n g l e e / Pu b l i c ) . The second, m uch short er when you're m oving down t he pat h relat ive t o your current locat ion, is t o use t he relat ive pat h ( e.g., c d Publ i c ) . Assum ing you're in your hom e direct ory, t hese exam ples are equivalent . Let 's now t urn our at t ent ion t o t he cont ent s of t he Public folder:
[ Ap pl e - s - Co mp u t e r : ~/ Pu b l i c ] we i me n g l e e % l s Dr o p Box I nside of Public, t here is one subdirect ory, Drop Box, and no files. Change t o t he Drop Box direct ory by t yping c d Dr op \ Bo x . You can also use t ab com plet ion t o save yourself a lit t le t yping; sim ply t ype c d D and press t he Tab key. Bingo! The direct ory nam e is aut om at ically com plet ed for you. This works on bot h files and folders, relat ive and absolut e pat hs. I f t here's anot her file or folder wit h t he sam e init ial let t er, t ype t he second let t er and press Tab — and so on, t yping as m uch of t he nam e necessary t o dist inguish it from ot hers.
48.6 Moving On Up To m ove up one st ep in t he direct ory hierarchy, use . . t o refer t o t he special parent direct ory:
[ Ap pl e - s - Co mp u t e r : ~/ Pu b l i c / Dr o p Bo x ] we i me n g l e e % c d . . [ Ap pl e - s - Co mp u t e r : ~/ Pu b l i c ] we i me n g l e e % Move up m ult iple levels by com bining . . and / , like so:
[ Ap pl e - s - Co mp u t / Us e r s / we i me n g l [ Ap pl e - s - Co mp u t [ Ap pl e - s - Co mp u t / Us e r s /
er : ee/ er : er :
~/ Pu b l i c ] we i me n g l e e % p wd Pu b l i c ~/ Pu b l i c ] we i me n g l e e % c d . . / . . / Us e r s ] we i me n g l e e % p wd
c d . will have no effect , changing t he current direct ory t o, well, t he current direct ory. But . will com e in handy in a m om ent when we st art copying files.
To go t o t he t op of t he direct ory ( known as t he root direct ory) , use / all by it self:
[ Ap pl e - s - Co mp u t e r : / Us e r s ] we i me n g l e e % c d / [ Ap pl e - s - Co mp u t e r : / ] we i me n g l e e % To ret urn t o your hom e direct ory, sim ply use t he c d com m and wit h no param et ers, t he equivalent of c d ~ and c d / Us e r s / l o g i n ( where l o g i n is your Short Nam e) :
[ Ap pl e - s - Co mp u t e r : / ] we i me n g l e e % c d [ Ap pl e - s - Co mp u t e r : ~/ ] we i me n g l e e % 48.7 Creating Directories To creat e a new direct ory, use t he mk d i r ( m ake direct ory) com m and, followed by t he direct ory nam e — eit her relat ive or absolut e pat h. Not e t hat if your new direct ory nam e cont ains spaces, you need t o escape t hem or enclose t he ent ire direct ory nam e in " " ( double quot es) . Ot herwise mk di r will t hink t hat you m ean t o creat e m ult iple direct ories, as t he following failed at t em pt t o creat e a new folder called Tem p Folder shows:
[ Ap pl e - s - Co mp u t e r : ~] we i me n g l e e % mk d i r Te mp Fo l d e r [ Ap pl e - s - Co mp u t e r : ~] we i me n g l e e % l s - a l t ot a l 0 dr wxr - xr - x 6 we i me n g l s t a f f 2 0 4 De c 1 1 0 8 : 5 0 . dr wxr - xr - x 1 3 we i me n g l s t a f f 4 4 2 De c 1 0 1 7 : 5 8 . . - r w- r - - r - - 1 we i me n g l s t a f f 0 De c 9 1 7 : 0 8 . l o c a l i z e d dr wxr - xr - x 2 we i me n g l s t a f f 6 8 De c 1 1 0 8 : 5 0 Fo l d e r dr wxr - xr - x 2 we i me n g l s t a f f 6 8 De c 1 1 0 8 : 5 0 Te mp Eit her of t he following t wo versions will work as expect ed:
mk d i r Te mp \ Fo l d e r mk d i r " Te mp Fo l d e r " 48.8 Removing Directories To rem ove a direct ory, use r md i r ( rem ove direct ory) , t he polar opposit e of mkd i r . The space issue applies as expect ed; eit her of t he following will do:
r md i r Te mp \ Fo l d e r r md i r " Te mp Fo l d e r " 48.9 Copying Files
To copy a file, use t he c p ( copy) com m and, followed by t he file t o copy and it s int ended dest inat ion. Use eit her a relat ive or absolut e pat h for each. For exam ple, let 's copy t he file index.ht m l from t he direct ory Sit es t o Docum ent s:
[ Ap pl e - s - Co mp u t e r : ~] we i me n g l e e % c p Si t e s / i n d e x . h t ml Do c u me n t s [ Ap pl e - s - Co mp u t e r : ~/ Do c u me n t s ] we i me n g l e e % c d Do c u me n t s [ Ap pl e - s - Co mp u t e r : ~/ Do c u me n t s ] we i me n g l e e % l s i n d e x. ht ml To copy a file t o t he current direct ory, use t he special . filenam e, like so:
[ Ap pl e - s - Co mp u t e r : ~/ Do c u me n t s ] we i me n g l e e % c p Si t e s / i n d e x . h t ml . 48.10 Deleting Files To delet e a file, use t he r m ( rem ove) com m and. The following exam ple delet es t hat index.ht m l we j ust copied t o Docum ent s:
[ Ap pl e - s - Co mp u t e r : ~/ Do c u me n t s ] we i me n g l e e % r m i n d e x. h t ml 48.11 Moving Files To m ove a file from one direct ory t o anot her, use t he mv ( m ove) com m and, followed by t he space- separat ed nam e and dest inat ion pat h. The following exam ple m oves t he file index.ht m l from t he direct ory Sit es t o Docum ent s:
[ Ap pl e - s - Co mp u t [ Ap pl e - s - Co mp u t [ Ap pl e - s - Co mp u t i ma ge s [ Ap pl e - s - Co mp u t [ Ap pl e - s - Co mp u t i n d e x. ht ml
e r : ~] we i me n g l e e % mv Si t e s / i n d e x . h t ml Do c u me n t s e r : ~] we i me n g l e e % c d Si t e s / e r : ~/ Si t e s ] we i me n g l e e % l s e r : ~/ Si t e s ] we i me n g l e e % c d . . / Do c u me n t s e r : ~/ Do c u me n t s ] we i me n g l e e % l s
The mv com m and is also used for renam ing files. The following exam ple renam es t he file from index.ht m l t o index.t xt :
[ Ap pl e - s - Co mp u t e r : ~/ Do c u me n t s ] we i me n g l e e % mv i n d e x. h t ml i n d e x . t x t [ Ap pl e - s - Co mp u t e r : ~/ Do c u me n t s ] we i me n g l e e % l s i n d e x. t xt
Let 's put everyt hing back, shall we? Type mv i nde x. t xt and all should be as it was when we st art ed t his ride.
48.12 Viewing the Content of a Text File
~/ Si t e s / i n d e x . ht ml ,
At t im es, you m ay want t o t ake a quick peek at t he cont ent s of a t ext file. To do so, use c a t ( concat enat e) , specifying t he file or files t o display, like so:
% c a t . l popt i ons De f a ul t _ 1 9 2 _ 1 6 8 _ 2 5 4 _ 1 4 9 48.13 Copy and Paste, Drag and Drop The st andard edit ing suit e, select all, copy, and past e, works as expect ed in t he Term inal, whet her invoked wit h - A, - C, and - V or pulled down from t he Edit m enu. A nice bit of int eract ion bet ween com m and line and GUI is t he abilit y t o drag a file, direct ory, or bookm ark from anywhere you m ay be in t he Finder right ont o t he com m and line. Want t o edit a file in a Term inal- based edit or [ Hack # 51] wit hout navigat ing t he direct ory hierarchy t o get t o it ? Type pi c o ( or t he like) , followed by a space, and drag t he file right int o t he Term inal window. I t 's a short cut t hat com es in handy m ore oft en t han you'd t hink.
48.14 Consulting the Manpages There is only so m uch I can cover in t his quick t our of t he Term inal. You'll encount er a plet hora of com m ands and applicat ions on t he com m and line. Whenever you need any help, t ry consult ing t he m anual. Sim ply t ype ma n ( as in m anual, not oh, m an! ) , followed by t he com m and nam e. Your average m anpage looks som et hing like Figure 55. Figu r e 5 - 5 . Th e a ve r a ge m a n pa ge
48.15 Getting Off the Command Line
At any point you can always close t he Term inal window as you would any ot her. I t is far m ore polit e — not t o m ent ion cleaner — t o log out of t he shell session you're running by t yping e x i t or l og o ut :
% l ogout [ Pr oc e s s c o mp l e t e d ] —Wei- Meng Lee and Rael Dornfest
[ Team LiB ]
[ Team LiB ] Hack 49 More Terminal Tricks and Tips
So m a n y com m a n ds, so lit t le t im e t o le a r n t h e m a ll. H e r e a r e a fe w m or e com m a n d- lin e t ips a n d t r ick s t h a t you a r e su r e t o fin d u se fu l. Wit h a plet hora of com m ands and various ways in which t o com bine t hem and st ring t hem t oget her, you can do virt ually unlim it ed t hings on t he com m and line. Here are a few m ore t ips and t ricks you'll find useful while working your way t hrough som e of t he hacks in t his book.
Of course, t his crash course com bined wit h [ Hack # 48] barely scrat ches t he surface of t he powerful Unix operat ing syst em . For a m ore in- dept h t reat m ent , we highly recom m end Unix Power Tools ( ht t p: / / www.oreilly.com / cat alog/ upt 3/ ) .
49.1 Customizing Your Terminal Over t im e, you will no doubt be bored wit h Term inal's plain black- on- whit e set t ings. Here are som e t ips for adding som e spice t o your Term inal windows. Longt im e Unix users would be fam iliar wit h t he green- on- black set t ings. Those were t he days when dum b t erm inals ruled and a color m onit or was m ore a luxury t han a necessit y. I n Mac OS X, you can change t he color of your Term inal window t o m im ic t he good old days.
To change t he color of your Term inal window, click on Term inal
Window Set t ings..., as shown in Figure 5- 6.
Figu r e 5 - 6 . Ch a n gin g t h e a ppe a r a n ce of you r Te r m in a l w in dow
The Term inal I nspect or window will appear ( see Figure 5- 7) ; it 's from here t hat you m ay m ake various changes t o your Term inal window configurat ion. Figu r e 5 - 7 . Ch a n gin g t h e color of a Te r m in a l w in dow
I f you sim ply want all Term inal windows t o adopt t he set t ings you have j ust creat ed, select File As Default s.
To save your m odified set t ings wit hout applying t hem globally, select File t erm preference file, as shown in Figure 5- 8.
Use Set t ings
Save As... t o save t hem t o a .
Figu r e 5 - 8 . Sa vin g Te r m in a l se t t in gs t o a .t e r m file
You can creat e m ult iple .t erm files represent ing various different configurat ions. To open a Term inal window wit h a part icular set t ing, select it from File Library, select File Open..., and choose t he appropriat e .t erm file, or drag it t o your Dock and click it whenever you want a Term inal window of t hat t ype. By default , .t erm files are saved t o your Library/ Applicat ion Support / Term inal direct ory. You can even have a part icular .t erm file run a specific com m and when it opens. Open a .t erm file in your favorit e plain- t ext edit or [ Hack # 51] and look for t his:
. . . Ex e c u t i o n St r i n g . . . Alt er t he value of t he elem ent t o be what ever you'd like run on t he com m and line when t he Term inal window opens. I have a shell script for port - forwarding m y m ail [ Hack # 70] , called ma i l f o r wa r d . s h , which I run every t im e I com e online aft er being off for a while sim ply by double- clicking m y m ailforward.t erm file in m y Dock. That .t erm file's Ex e c u t i o n St r i n g looks like t his:
. . . Ex e c u t i o n St r i n g ~/ b i n / ma i l f or wa r d . s h . . . 49.2 Switching Terminal Windows Oft en, you m ay have m any Term inal windows lying about . Swit ching bet ween t hem using m ouse clicks can be m ore t rouble t han it 's wort h. Thankfully, t here are a few keyboard short cut s. Press - 1 t o swit ch t o t he first window,
- 2 for t he second, and so on. I f you want t o loop t hrough t he open Term inal windows, t ype
arrow or
- left arrow for forward and backward, respect ively.
49.3 Learning from History
- right
At t im es, you m ay want t o reuse t he com m ands t hat you've t yped previously, especially if a com m and has lengt hy opt ions and param et ers; you wouldn't want t o t ype everyt hing again, now would you? You can always use t he up and down arrow keys t o navigat e previously used com m ands, but when you're reaching back a num ber of com m ands ago, t here's a bet t er way t han wearing away your fingerprint hit t ing t hat up arrow repeat edly. Use t he h i s t o r y com m and t o display t he list of previously execut ed com m ands:
% 1 2 3 4 5
h i s t or y 1 1: 34 c a l 2 0 0 3 1 1: 34 l s - a l 1 1: 34 c l e a r 1 1: 34 ma n o p e n 1 1: 34 h i s t o r y
The h i s t o r y com m and even list s t he t im e at which t he com m and was execut ed. To reuse a part icular com m and, t ype ! ( exclam at ion point or " bang" in hacker- speak) , followed by t he num ber list ed alongside t he com m and you want t o reuse, t hen press t he Ret urn key. Here, for exam ple, I run t he second it em in t he list :
% !2 l s - al { a l ong- f o r ma t l i s t i n g o f a l l f i l e s i n t h e l o c a l d i r e c t o r y } I f you have a long hist ory list — I always do — you can also use t he first few let t ers of t he com m and line inst ead of t he com m and num ber, like so:
% !ls l s - al { a l ong- f o r ma t l i s t i n g o f a l l f i l e s i n t h e l o c a l d i r e c t o r y } This can, however, be dangerous and unpredict able if you end up running som et hing t hat st art ed wit h t he sam e let t ers but wasn't quit e t he sam e com m and you had in m ind. Think about running r m * ( rem ove all files in t he current direct ory) when you t hink you're running r m n ot e s . t xt ( rem ove t he not es.t xt file) . You can get hi s t o r y t o show you what it t hinks you m ean by adding a : p t o t he end of t he hist ory reference, whet her it be by num ber or first few charact ers:
% !l s: p l s - al % !ls l s - al { a l ong- f o r ma t l i s t i n g o f a l l f i l e s i n t h e l o c a l d i r e c t o r y } You can also use : p t o recall and t hen slight ly alt er an earlier com m and by pressing t he up arrow right aft erward, edit ing t he com m and line, and pressing Ret urn:
% ! r m: p r m a . t xt b . t x t c . t x t { h i t t he Up a r r o w} % r m a . t xt b. t xt d. t xt
49.4 Listing All the Commands The m an ( m anual) com m and [ Hack # 48] allows you t o check for t he usage of a com m and. But how do you know which com m ands are available t o you in t he first place? You can t ake a gander at t he ent ire list of available com m ands by pressing Cont rol- X, Cont rol- D.
49.5 Changing Permissions with chmod The Unix com m and c h mo d ( change m ode) alt ers perm issions on files and direct ories, allowing you t o fine- t une access cont rol and prot ect files from unaut horized users or accident al delet ion ( hey, it happens! ) . Perm issions are perhaps best explained by exam ple. First , creat e a new direct ory nam ed m y_folder:
% mkdi r my _ f o l d e r Change int o t he newly creat ed direct ory and list all t he files t herein; t here shouldn't be anyt hing aside from . ( t his direct ory) and . . ( t he parent direct ory) :
% c d my_f o l d e r % l s - al t ot a l 0 dr wxr - xr - x 2 we i me n g l s t a f f 6 8 De c 1 3 0 9 : 3 1 . dr wxr - xr - x 1 8 we i me n g l s t a f f 6 1 2 De c 1 3 0 9 : 3 1 . . Next , creat e a new t ext file. One of t he sim plest ways t o creat e a quick t est file is by e c h o ing som e t ext t o it , lit erally sending som e t ext t oward t he file, indicat ing t oward using t he > redirect ion operat or:
% e c ho " So me t e x t " > f i l e 1 . t x t Take a look at t he default perm issions for t he file we j ust creat ed; t hey're at t he left m argin associat ed wit h file1. t xt :
% ls -l t ot a l 8 - r w- r - - r - - 1 we i me n g l s t a f f 1 0 De c 1 3 0 9 : 3 3 f i l e 1 . t x t Perm issions com e in t hree set s of t hree: owner, group, and world, each wit h an associat ed read, writ e, and execut e perm ission. Our file1.t xt is readable and writ eable ( r w- ) by t he owner ( t hat 's you) , readable ( r - - ) by t he group ( t hat 's anyone who's in t he s t a f f group along wit h you) , and readable ( r - - ) by anyone else. We will concern ourselves only wit h owner perm issions at t his point . Let 's change t he perm issions on file1.t xt so t hat it is not writ able by you, t hus prot ect ing it against accident al overwrit ing:
% c hmod u - w f i l e 1 . t x t The param et er u - w t ells c h mo d t o rem ove t he writ e perm ission from t he user ( owner) . To confirm , t ake anot her look:
% ls -l t ot a l 8 - r - - r - - r - - 1 we i me n g l s t a f f 1 0 De c 1 3 0 9 : 3 3 f i l e 1 . t x t Try delet ing t he file. You'll be prom pt ed t o override t he perm ission set t ings. I f you weren't t he owner, however, you'd sim ply be denied perm ission alt oget her:
% r m f i l e 1. t xt ov e r r i de r - - r - - r - - we i me n g l / s t a f f f o r f i l e 1 . t x t ? Try appending som e t ext t o t he file ( >> m eans append rat her t han writ e t o) . Since you've denied yourself writ e perm ission, you'll fail:
% e c ho " So me mo r e t e x t " >> f i l e 1 . t x t f i l e 1 . t x t : Pe r mi s s i o n d e n i e d . To grant yourself writ e perm ission again, do t he inverse of t he previous c h mo d using + , like so:
% c hmod u +w f i l e 1 . t x t Now let 's ret urn t o t he hom e direct ory and exam ine t he perm ission set t ings for t he m y_folder direct ory:
% cd ~ % ls -l t o t a l 40 ... dr wxr - xr - x 3 we i me n g l s t a f f 1 0 2 De c 1 3 0 9 : 3 9 my Fo l de r ... Try rem oving t he execut e ( x ) perm ission from t he direct ory for yourself, t he owner. Then t ry visit ing it again using c d :
% c hmod u - x my _ f o l d e r % c d my_f o l d e r my _ f ol de r : Pe r mi s s i o n d e n i e d . Why are you locked out ? Direct ories are special files requiring execut e perm issions before allowing you int o or across t heir borders. Since you don't have execut e perm ission, you're barred. Put back t he execut e perm ission while at t he sam e t im e rem oving writ e perm ission and c d int o m y_folder again:
% c hmod u +x my _ f o l d e r % c hmod u - w my _ f o l d e r % c d my_f o l d e r All appears back t o norm al; you should have landed j ust fine inside m y_folder. Try t o creat e anot her file in your now unwrit able direct ory:
% e c ho " So me t e x t " > f i l e 2 . t x t f i l e 2 . t x t : Pe r mi s s i on d e n i e d . As you m ight have guessed, while you can visit t he folder t hanks t o execut able perm ission, you can't alt er it in any way wit hout writ e perm ission. You can't creat e, m ove, or delet e anyt hing. You can, however, st ill edit file1. t xt , since a file's perm issions t ake precedence when dealing direct ly wit h it .
There is also a way t o refer t o perm issions num erically ( e.g., c hmo d 7 5 5 s c r i pt . c g i ) , but we'll leave t hat t o a m ore advanced Unix t ext .
49.6 Changing Owner and Group with chown and chgrp This is all well and good, given t hat all t he files in your direct ory ( presum ably) belong t o you. But what of files t hat aren't yours yet need som e dealing wit h? That 's where c h own ( change owner) and c hg r p ( change group) com e in. Take a quick look at t he docum ent direct ory for your onboard Apache web server [ Hack # 88] :
% c d / Li b r a r y / We b Se r v e r / Do c u me n t s / % l s - al t o t a l 376 dr wxr wxr - x 3 8 r o o t a d mi n 1 2 9 2 De c 1 3 0 0 : 2 4 . dr wxr wxr - x 5 r o o t a d mi n 1 7 0 De c 1 0 1 7 : 3 9 . . - r w- r w- r - - 1 r o o t a d mi n 3 7 2 6 J u l 2 7 1 4 : 3 1 Po we r e d ByMa c OSx . g i f - r w- r w- r - - 1 r o o t a d mi n 3 1 9 5 8 J u l 2 7 1 4 : 3 1 Po we r e d By Ma c OSx La r g e . g i f - r w- r w- r - - 1 r o o t a d mi n 2 3 2 6 Ap r 1 4 1 9 9 9 a p a c h e _ p b . g i f - r w- r w- r - - 1 r o o t a d mi n 1 8 8 4 Oc t 1 7 2 0 0 1 i n d e x . h t ml . c a ... - r w- r w- r - - 1 r o o t a d mi n 1 0 6 2 J u n 1 9 1 8 : 2 3 i n d e x . h t ml . z h l r wxr wxr - x 1 r o o t a d mi n 3 8 De c 1 3 0 0 : 2 4 ma n u a l - > / Li b r a r y / Doc u me nt a t i on / Se r v i c e s / a pa c h e Not ice t hat , by default , t hey're all owned by t he root user [ Hack # 50] and adm in group. I 'm not root , but I am an adm in user, as shown by t he wh o a mi and g r ou ps com m ands:
% whoa mi we i me ngl % g r oups s t a f f a dmi n Given t he perm issions on t he files and t he direct ory t hey're in, I should be able t o creat e, edit , m ove, and rem ove anyt hing I need t o in order t o t end t his m achine's web sit e. But what of t he nonadm inist rat ive users I have helping m e? There has t o be som e way t o give t hem ownership of som e of t hese files. And t here m ust be som e way t o claim ownership of a file and block adm in access t o it — except by t he root user, of course. The c h o wn com m and does j ust t hat . Perhaps you'd like t o t ake ownership of index.ht m l.ca and horde writ e perm ission:
% s udo c h o wn we i me n g l i n d e x . h t ml . c a Pa s s wor d: % c hmod g - w i n d e x . h t ml . c a % l s - l i n d e x . h t ml . c a - r w- r - - r - - 1 we i me n g l a d mi n 1 8 8 4 Oc t 1 7 2 0 0 1 i n d e x . h t ml . c a Now t he file is owned by you, and nobody but you has writ e perm ission t o it .
Since you can't sim ult aneously be t he owner of t he file as it st ands and t he owner you're about t o give it , c h own requires becom ing t he root user for a m om ent [ Hack # 50] .
Perhaps you want t o give writ e perm ission t o everyone working on t he web sit e. You could change perm issions so t hat all t he files are world writ able ( c h mo d o +w) , but t hat 's generally regarded as bad form . I nst ead, you could sim ply change t he group ownership ( c h g r p ) of t he part icular files you'd like t hem t o all share, in t his case, all t he index.ht m l files:
% s udo c h g r p s t a f f i Pa s s wor d: % l s - a l i n d e x . h t ml . - r w- r w- r - - 1 r o o t s t ... - r w- r w- r - - 1 r o o t s t
n d e x . h t ml * * a f f 1 8 8 4 Oc t 1 7 2 0 0 1 i n d e x . h t ml . c a a f f 1 0 6 2 J u n 1 9 1 8 : 2 3 i n d e x . h t ml . z h
Being pedant ic, it 's act ually best t o creat e a new group, webadm in, for exam ple, int o which t o put all t hose folks working on t he sit e. This is bet t er t han giving writ e access t o anyone you happen t o let log in t o your m achine. But , since t his was m eant as a quick dem onst rat ion of c h gr p , we glossed over t hose det ails.
I f you have som e reason t o change bot h owner and group at t he sam e t im e, you can com bine t hese act ions int o one com m and: c h o wn o wn e r . g r o u p .
49.7 Counting Files Unlike Windows ( or DOS, in part icular) , t he l s com m and in Unix does not display t he t ot al num ber of files displayed. Consider t he following exam ple:
[ Ap pl e - s - Co mp u t e r : ~] we i me n g l e e % l s t o t a l 220 0 dr wx- - - - - - 1 2 we i me n g l s t a f f 408 dr wx- - - - - - 6 we i me n g l s t a f f 204 dr wx- - - - - - 2 4 we i me n g l s t a f f 816 dr wx- - - - - - 3 we i me n g l s t a f f 102 dr wx- - - - - - 3 we i me n g l s t a f f 102 dr wx- - - - - - 4 we i me n g l s t a f f 136
-l De c 1 2 1 1 : 3 5 De c 1 1 2 0 : 1 7 De c 9 2 1 : 0 9 De c 9 1 7 : 0 8 De c 9 1 7 : 0 8 De c 9 2 0 : 3 6
De s k t o p Doc u me n t s Li b r a r y Mov i e s Mus i c Pi c t u r e s
dr wxr - xr - x dr wxr - xr - x - r w- r - - r - - r w- r - - r - - r w- r - - r - -
4 5 1 1 1
we i we i we i we i we i
me n g l me n g l me n g l me n g l me n g l
st st st st st
af f 136 af f 170 a f f 380235 a f f 412280 a f f 328970
De c De c De c De c De c
11 11 11 11 11
08: 09: 15: 15: 15:
53 05 17 48 38
Pub l i c Si t e s f oo . p d f i ma g e . p d f t e s t . pdf
For direct ories wit h few files, t his generally is not a problem . But at t im es you need t o know t he t ot al num ber of files and you do not want t o wade t hrough a long list of files. To count t he files, you can use t he | ( pipe) charact er and t he wc ( word count ) com m and wit h t he - l opt ion t o count t he num ber of lines:
% ls -l | 12
wc - l
Not e t hat t he act ual file count should be 11, but t he count includes t he line t ot a l
2 2 00 and so is off by 1.
And if you want t o count t he num ber of direct ories, you can use t he gr e p com m and. The g r e p com m and looks over incom ing t ext and print s out lines t hat m at ch t he specified pat t ern. To find all lines st art ing wit h d , you'd use ^ d as t he pat t ern, t he ^ signifying t he beginning of a line:
% ls -l | 8
gr e p ^ d |
wc - l
And if you want only regular files, you'd look for lines st art ing wit h - :
% ls -l | 3
gr e p ^ - |
wc - l
I f you'd like t o see a list ing of only PDF files, you can again use a pat t ern, t his t im e g r e p ping for t he charact ers at t he end of t he line. The end- of- line pat t ern indicat or is $ :
% ls -l | 3
gr e p pdf $ |
wc - l
I t found foo.pdf, im age.pdf, and t est .pdf, as it should have. One could m ore easily have used * ( st ar or splat ) as a st and- in for t he bit s of t he files we didn't know and sim ply list ed everyt hing ending in .pdf like so:
% l s *. pd f | 3
wc - l
49.8 Displaying a Calendar Need t o check t he dat e for last Wednesday? Here is a quick way t o do it in t he Term inal. Use t he c a l ( calendar) com m and:
% cal
De c e mbe r S M Tu 1 2 3 8 9 10 15 16 17 22 23 24 29 30 31
2002 W Th F S 4 5 6 7 11 12 13 14 18 19 20 21 25 26 27 28
Wit hout any param et ers, c a l will display t he calendar for t he current m ont h. You can also display t he calendar for t he ent ire year. c a l support s years 1 t o 9999:
% c a l 200 3 20 0 3 J a n ua r y S M Tu 5 6 7 12 13 14 19 20 21 26 27 28
W Th 1 2 8 9 15 16 22 23 29 30
F S 3 4 10 11 17 18 24 25 31
W Th 1 2 8 9 15 16 22 23 29 30
F S 3 4 10 11 17 18 24 25 31
Fe b r u a r y S M Tu
W Th
2 3 4 5 9 10 11 12 16 17 18 19 23 24 25 26
F
S 1 6 7 8 13 14 15 20 21 22 27 28
Ma r c h S M Tu 2 9 16 23 30
W Th
F
3 4 5 6 7 1 0 11 1 2 1 3 1 4 1 7 18 1 9 2 0 2 1 2 4 25 2 6 2 7 2 8 31
S 1 8 15 22 29
... Oc t obe r S M Tu 5 6 7 12 13 14 19 20 21 26 27 28
No v e mb e r S M Tu
W Th
F
2 3 4 5 6 7 9 10 11 12 13 14 16 17 18 19 20 21 23 24 25 26 27 28 30
S 1 8 15 22 29
De c e mb e r S M Tu 1 2 7 8 9 1 4 1 5 16 2 1 2 2 23 2 8 2 9 30
W Th F S 3 4 5 6 10 11 12 13 17 18 19 20 24 25 26 27 31
You can also opt t o display a part icular m ont h in a part icular year:
% c a l 1 2003 J a n ua r y 2 0 0 3 S M Tu W Th 1 2 5 6 7 8 9 12 13 14 1 5 1 6 19 20 21 2 2 2 3 26 27 28 2 9 3 0
F S 3 4 10 11 17 18 24 25 31
Or, you can display t he dat e in Julian form at :
% c a l - j 2003 20 0 3 J a n ua r y S M Tu
W Th
F
S
Fe b r u a r y S M Tu
W Th
F
S
5 12 19 26
6 13 20 27
1 8 15 22 29
7 14 21 28
2 9 16 23 30
3 10 17 24 31
4 11 18 25
33 40 47 54
34 41 48 55
35 42 49 56
36 43 50 57
37 44 51 58
38 45 52 59
W Th 337 338 344 345 351 352 358 359 365
F 3 39 3 46 3 53 3 60
32 39 46 53
... No v e mbe r S M Tu 30 6 31 3 32 0 32 7 33 4
307 314 321 328
308 315 322 329
W Th 309 316 323 330
—Wei- Meng Lee
[ Team LiB ]
310 317 324 331
F 311 318 325 332
S 305 312 319 326 333
De c e mb e r S M Tu 335 336 341 342 343 348 349 350 355 356 357 362 363 364
S 340 347 354 361
[ Team LiB ] Hack 50 Becoming an Administrator for a Moment
You r M a c doe s it s be st t o pr ot e ct you fr om you r se lf a n d you r fa m ily by r e qu ir in g a u t h e n t ica t ion , bot h in t h e GUI a n d on t h e com m a n d lin e , w h e n you 'r e a bou t t o do som e t h in g pot e n t ia lly pr oble m a t ic. OS X, being a m ult iuser Unix syst em at it s heart , t ries t o prevent you ( or your fam ily) from doing anyt hing t hat m ight adversely affect your Mac. I t does so by denying access t o part icular files t hat keep your syst em running and disallowing act ions t hat it considers pot ent ially harm ful. Every now and again, however, you need t o inst all a piece of soft ware or t ouch a vit al Unix configurat ion file t o get som et hing done. Before it 'll let you do so, OS X will require t hat you aut hent icat e yourself as an adm inist rat ive user, known in Unix parlance as root .
50.1 Desktop Root While m ost applicat ions can be inst alled sim ply by dragging t hem int o t he Applicat ions folder, som e require a lit t le m ore t om foolery. Applicat ion and package inst allers oft en need t o creat e folders, drop files int o place, and adj ust configurat ion set t ings in rest rict ed part s of t he operat ing syst em . At t hese t im es you're eit her not allowed t o cont inue if you're not list ed as an adm inist rat ive user of t he syst em ( t ake a look at t he Syst em Preferences Aut hent icat e dialog looks like Figure 5- 9.
Users pane) or prom pt ed for your password if you are. A t ypical
Figu r e 5 - 9 . Au t h e n t ica t e dia log
You'll not ice I 've expanded t he det ail level by clicking on t he Det ails arrow. I n t his case, t he applicat ion asking for aut hent icat ion is t he st andard Mac OS X I nst aller. Type in your password and t he I nst aller will cont inue. What you've done, in effect , is becom e an adm inist rat or wit h full power over your syst em , if only for a m om ent . You've t hen grant ed t he I nst aller sim ilar power t o do what it needs t o do.
Whenever you aut hent icat e yourself t o an applicat ion, realize t hat it 's going t o be fiddling wit h your syst em and m ake sure you have som e idea what it 's t rying t o do. Read t he not ices displayed by inst allers carefully.
You'll also encount er t im es when you need t o aut hent icat e yourself t o m ake a configurat ion change in t he Syst em Preferences or t he like. I f you find t hat you're unable t o change som e set t ings t hat seem as if t hey should be edit able, look around t he window for a lit t le lock icon. I f it 's locked, you m ay need t o unlock it ( click on it ) and aut hent icat e yourself. I f you feel t he need t o lock t he set t ings again when you're done, click t he lock again ( see Figure 5- 10) . Figu r e 5 - 1 0 . Lock e d se t t in gs
50.2 Command-Line Root On t he com m and line [ Hack # 48] , t here is no fancy dialog for aut hent icat ing you as t he root user. The s ud o ut ilit y ( subst it ut e- user do) allows you t o gain t em porary root privileges on a per- com m and basis. To use s ud o , sim ply preface t he com m and you wish t o run as root wit h s u do and a space, and s ud o will prom pt you for your ( not root 's) password. I f you have adm inist rat or privileges, ent ering your password will run t he s ud o ed com m and as if t he root user were doing it .
Use s u d o wit h care. You can easily m ake m ist akes wit h s ud o t hat could require a com plet e reinst allat ion of t he OS t o get going again. I f t hat t hought m akes you queasy, it would be wise for now t o use s u do only as direct ed in t his hack.
Typical s u d o use looks like t his:
% s udo a p a c h e c t l r e s t a r t Not es about s u d o : ● ● ●
The first t im e you run s u d o , you'll see anot her rem inder t o use s u do wit h care. You'll need t o ent er your password only when you haven't already used s ud o wit hin t he last five m inut es. I t 's not necessary t o act ivat e t he root account or do anyt hing else special t o st art using s ud o .
50.3 Enabling the Root Account You m ay find a reason at som e point t o enable t he root account on your Mac. While it 's a rare hack indeed t hat would require logging in as t he root user, it does com e up ( e.g., [ Hack # 1] ) .
To do so, launch Net I nfo Manager ( Applicat ions Ut ilit ies Net I nfo Manager) and aut hent icat e yourself by clicking t he lock icon at t he bot t om - left and ent ering your password, as show in Figure 5- 11. Figu r e 5 - 1 1 . Au t h e n t ica t in g you r se lf t o N e t I n fo M a n a ge r
To enable t he root user, select Securit y Enable Root User from t he m enu bar. I f t his is t he first t im e you've done t his, you'll be warned t hat t he root password is current ly blank ( see Figure 5- 12) and you'll be prom pt ed t o set one ( see Figure 5- 13) . Figu r e 5 - 1 2 . A w a r n in g a bou t t h e r oot pa ssw or d n ot be in g se t
Figu r e 5 - 1 3 . Se t t in g t h e r oot pa ssw or d
Click t he lock icon again t o disallow any furt her changes, and close Net I nfo Manager. The root account is now act ive.
To disable t he account , follow t he sam e st eps, but select Securit y
Disable Root User.
50.4 Logging in as Root Log in as root j ust as you would log in as any ot her user. The only difference is t hat root won't appear in t he list of users and t heir associat ed cut e icons. Click Ot her, ent er root as t he Nam e, and ent er t he password you assigned t o t he root account as Password. —Chris St one and Rael Dornfest
[ Team LiB ]
[ Team LiB ] Hack 51 Editing Special Unix Files
Spe cia l Un ix file s n e e d spe cia l h a n dlin g. You ca n 't sim ply e dit t h e m in W or d a n d e x pe ct t h in gs t o w or k . H e r e 's a cr a sh cou r se in e dit in g u sin g t h e pico com m a n d- lin e e dit or a n d Te x t Edit GUI e dit or . You've no doubt discovered OS X's default t ext edit or, t he apt ly nam ed Text Edit . Hopefully, you've also heard of and downloaded t he out st anding BBEdit ( ht t p: / / www.bbedit .com / index.ht m l) , favorit e t ext edit or of generat ions of Mac users. But unless you're a Unix j ock, you probably don't know t hat OS X ships wit h several ot her feat ureand hist ory- rich Term inal- based t ext edit ors. Vet erans will t end t o swear by eit her vi ( t he Visual Edit or) or Em acs, but seldom bot h. Then t here's pico, t he sim plest of t he t hree, yet st ill m ore t han sufficient for m ost sim ple edit ing work. Here we'll provide a crash course in edit ing t hose special Unix files we t alk about in t his book: ht t pd.conf, / et c/ inet d.conf, plist files, and t he like. We'll skip t he t wo wit h t he st eepest learning curve — vi and Em acs — and st ick wit h pico and Text Edit .
51.1 Using pico pico was developed at t he Universit y of Washingt on. I t is a sim ple but powerful Unix t ext edit or. To fire up pico, t ype p i c o ( by it self or followed by a part icular file t o edit ) in a Term inal [ Hack # 48] window ( see Figure 5- 14) . Figu r e 5 - 1 4 . Th e pico in t e r fa ce
pico's int erface, while perhaps a lit t le Unixey for t he uninit iat ed, is pret t y st raight forward. Rat her t han clicking but t ons in m enu bars, com m ands are issued by t yping Cont rol- charact er short cut s; t he bot t om t wo rows provide a list of com m only used short cut s. That ^ charact er prefixing all of t he short cut s st ands for t he Cont rol key on your keyboard; t hus, ^ G signifies t hat for m ore com prehensive help, you should press Cont rol- G ( see Figure 515) . Figu r e 5 - 1 5 . Ge t t in g h e lp in pico
Press Cont rol- X t o leave pico help. Now t hat you have pico warm ed up, let 's t ake it for a spin wit h som e com m on operat ions.
51.1.1 Moving about Move about wit hin t he t ext file you're edit ing, as you m ight expect , using t he arrow keys. Beyond basic charact erby- charact er m ovem ent , however, your old habit s will fail you. None of t he - sequences work here. To scroll t hrough long t ext , you cannot use t he Page Up and Page Down keys on your keyboard; it 's Cont rol- Y for page up and Cont rol- V for page down. To j um p t o t he beginning of a line, press Cont rol- A. To j um p t o t he end, t ype Cont rol- E. To search wit hin t he current file for a snippet of t ext , press Cont rol- W, ent er t he t ext t o find at t he Se a r c h : prom pt , and press Ret urn. To search for t he sam e t ext again, press Cont rol- W, followed by Ret urn. To change your m ind and cancel a search, press Cont rol- C.
51.1.2 Saving To save a file ( see Figure 5- 16) , press
- O ( writ e out — go figure! ) . Figu r e 5 - 1 6 . Sa vin g a file in pico
Type a filenam e or fully qualified pat h ( e.g., / t mp / t e s t . t x t ) t o which t o save, as shown in Figure 5- 17, and press Ret urn. Figu r e 5 - 1 7 . Su pplyin g a file n a m e or pa t h t o sa ve t o
You can also use t he built - in file and direct ory browser ( press Cont rol- T) t o locat e a part icular direct ory int o which t o save your file ( see Figure 5- 18) . Use t he arrow keys t o m ove about , Ret urn t o m ove int o a direct ory, . . t o m ove up a direct ory, and e t o select a direct ory and ret urn t o t he Fi l e Na me t o wr i t e : prom pt . You can also select a filenam e, and what ever you save will overwrit e what 's already t here. Figu r e 5 - 1 8 . Th e pico dir e ct or y br ow se r
51.1.3 Opening Oddly enough, pico doesn't have an Op e n Fi l e com m and. I nst ead, you insert t he cont ent s of a file int o t he edit or, as shown in Figure 5- 19. Press Cont rol- R and everyt hing's pret t y m uch t he sam e as it was wit h saving, direct ory browser and all. The only difference is t hat you use Ret urn rat her t hen e t o m ake your final select ion. The select ed file's cont ent s will appear in t he edit or, appended t o anyt hing you've already been edit ing. Figu r e 5 - 1 9 . I n se r t in g a file
51.1.4 Selecting text Select ing a block of t ext in pico is not as st raight forward as using your m ouse. I n fact , t he m ouse is ut t erly useless in pico and j ust about every ot her com m and- line applicat ion. To select a block of t ext , use t he arrow keys t o posit ion your cursor at t he st art of t he t ext you want t o select and press Cont rol- Shift - 6 ( a.k.a. Cont rol- ^ ) . pico will respond wit h [ Ma r k Se t ] . Move about unt il you've select ed all t he t ext you wish; select ed t ext is called out in inverse colors.
To sim ply unselect t he t ext , press Cont rol- Shift - 6 again. To cut t he select ed block, press Cont rol- K. To past e it som ewhere, m ove t he cursor t o t he right place and press Cont rol- U. Not e t hat t here's no copy in pico. To copy, j ust cut and past e ( Cont rol- K, Cont rol- U) in place and t hen past e again wit h Cont rol- U anywhere and as m any t im es as you wish.
51.1.5 Deleting Use your Delet e key as usual t o delet e t he charact er before your cursor. To delet e t he charact er aft er t he cursor, press Cont rol- D. Delet e an ent ire line wit h Cont rol- K.
51.1.6 Leaving To get out of pico at any t im e, press Cont rol- X. I f you've not saved what you're current ly edit ing, pico will offer you one last chance t o Sa v e mo d i f i e d b u f f e r .
51.2 TextEdit Text Edit ( Applicat ions Text Edit ) is t he default GUI t ext edit or. Being m ore like any ot her applicat ion you've used t han pico, Text Edit is also m uch m ore novice- friendly. As in m ost Mac applicat ions, you drag and drop select ions m ade wit h your m ouse. Saving, opening, cut t ing, - m odified arrow keys also copying, and past ing work as expect ed. Moving about wit h t he arrow keys and holds no surprises. Page Up and Page Down shift up and down a page.
51.3 Setting Your Default Command-Line Editor The default com m and- line edit or is vi — not a great choice for beginners. Com m ands like cront ab - e [ Hack # 53] use t he default as t heir edit or of choice, rat her t han allowing you t o use t he pico edit or you now know and love. To set your com m and- line edit or of choice t o pico, creat e a file in your hom e direct ory called .t cshrc cont aining t he following single line:
s e t e nv EDI TOR / u s r / b i n / p i c o The next t im e you invoke a Term inal com m and t hat requires a default edit or ( and respect s t he EDI TOR environm ent variable) , pico will be used inst ead of vi.
51.4 Why Not Simply Go GUI? Why, t hen, would anyone bot her delving int o ant iquit y wit h pico or any of t he ot her Term inal- based edit ors? Good quest ion. One answer is t hat edit ing on t he com m and line is far bet t er int egrat ed int o working wit h special Unix files t han t hrowing t hem out t o a GUI t ext edit or and j um ping back t o t he com m and line when you're done. This is especially t rue when it com es t o edit ing files you don't have perm ission t o edit wit hout becom ing an adm inist rat ive ( root ) user [ Hack # 50] . Just t ype s u do pi c o s p e c i a l _f i l e na me , aut hent icat e yourself, and
you're edit ing. Try opening t hat sam e file in Text Edit and you won't be allowed t o save it once you're done edit ing. That said, you can invoke Text Edit as t he adm inist rat ive user from t he com m and line:
% s udo / Ap p l i c a t i o n s / Te x t Ed i t . a p p / Co n t e n t s / Ma c OS/ Te x t Ed i t You have added a st ep, t hough, since you'll st ill have t o open t he part icular file you were aft er from wit hin Text Edit . Anot her reason t o use t he com m and line is t hat som e Term inal com m ands aut om at ically open your default edit or for you and rely upon knowing when it 's done. This doesn't always work part icularly well wit h an ext ernal GUI edit or like Text Edit . For t hose who regularly log in t o a rem ot e m achine [ Hack # 71] for adm inist rat ive t asks, t here's no choice but one of t he Term inal- based edit ors — eit her t hat or running a deskt op- sharing app, which is overkill for edit ing a configurat ion file. And, as m ent ioned, vi and Em acs are powerful edit ors, enabling far m ore t han would be possible wit hin a t radit ional t ext edit or. This power t akes som e know- how, but it quickly becom es indispensable. The choice is really yours. I f you're m ore com fort able using a GUI edit or like Text Edit or BBEdit ( which can aut hent icat e as an adm inist rat ive user from t he GUI ) , go right ahead. I f you're using t he com m and line quit e a bit and it 's st art ing t o grow on you, pico, vi, or Em acs m ight t urn out t o be your killer edit or. —Wei- Meng Lee
[ Team LiB ]
[ Team LiB ] Hack 52 Setting Shell Environment Variables
An e n vir on m e n t va r ia ble is a m a gica l pie ce of in visible da t a t h a t is a ct e d u pon by sh e ll pr ogr a m s a n d u t ilit ie s t h a t look for it s e x ist e n ce . Th e y'r e in n oce n t e n ou gh a n d you r a r e ly in t e r a ct w it h t h e m , bu t t h e y ca n pr ove t o be qu it e pow e r fu l a n d t im e sa vin g w h e n u se d a s pa r t of you r da ily life st yle . Sm art developers who care about code int egrit y use som et hing called a versioning syst em t o ensure a syst em of checks and balances, easy reversion t o previous code, and prevent ive overwrit ing ( by an aut om at ic or m anual m erging process) . I t 's such a com m on part of a developer's t oolkit t hat t he popular open source web I DE Sourceforge.net provides it as a default service. One annoyance of Concurrent Versioning Syst em ( CVS) ( longt im e users can find m any m ore) is t he com m and line — wit hout an envirom ent variable, you have t o t ype your c v s r o o t each and every t im e you m ake any changes t o your reposit ory:
c v s - d: ps e r v e r : a n o n y mo u s @c v s . a mp h e t a d e s k. s o u r c e f o r g e . n e t : / c v s r o o t / a mp h e t a d e s k l o g i n c v s - z 3 - d : p s e r v e r : a n o n y mo u s @c v s . a mp h e t a d e s k . s o u r c e f o r g e . n e t : / c v s r o o t / a mp h e t a d e s k c o Amp h e t a De s k These t wo lines log you int o a CVS server as t he user anonym ous and t hen check out t he ent ire source t ree of a program called Am phet aDesk. A cursory exam inat ion shows t hat t he largest part of t he com m and line is t he - d flag; it 's also repet it ive, as it needs t o be a part of every c v s com m and. I t can m ake a person nut s when she has t o worry about com m it t ing m odificat ions t o a dozen different files. Wouldn't it be great if you never had t o t ype t he - d flag and it s heavy payload? Thankfully, using environm ent variables, you don't . Think of an environm ent variable as a configurat ion file; t he values are act ed upon only by t he applicat ion t hat knows how t o handle t hem . I nst ead of being locat ed in seperat e config files, t hey're loaded int o t he shell environm ent . You can t hink of t hem ( roughly) as preferences for your shell ( as opposed t o preferences for t he OS X Term inal applicat ion) . The environm ent variable you want t o set is called, sem ant ically enough, CVS_ROOT ( nam ed aft er what t he - d flag represent s) . I f you haven't been fiddling wit h t he Term inal preferences, t hen you're using t he t csh shell. There are lot s of different t ypes of shells, t csh being t he default on OS X ( wit h an addit ional choice of bash under 10.2) . Set t ing an environm ent variable will change depending on which shell you're using, but under t csh, ent er t he following:
s e t e nv CVS_ ROOT " - d : p s e r v e r : a n o n y mo u s @c vs . a mp h e t a d e s k . s o u r c e f o r g e . n e t : / c v s r o o t / a mp h e t a d e s k " I f, on t he ot her hand, you've t weaked Term inal t o use bash, ent er t he following inst ead:
e x p or t CVS_ ROOT=" - d : p s e r v e r : a n o n y mo u s @c vs . a mp h e t a d e s k . s o u r c e f o r g e . n e t : / c v s r o o t / a mp h e t a d e s k " Wit h t he preceding com m and, you'll not ice t hat not hing seem s t o happen. That 's because environm ent variables are invisible — t here's only visual feedback when you've screwed up t he previous com m and ( or else use a program t hat uses t he variable) . To see your variable set properly, t ype p r i n t e n v ( for eit her shell) . You'll see your CVS_ ROOT, as well as a num ber of ot her variables already defined by OS X. You can now ent er t he m uch sm aller, and m ore readable, com m ands:
c v s l ogi n c v s - z 3 c o Amp h e t a De s k The problem wit h s e t e nv and e x p o r t are t hat t hey're bot h t em porary; once you close t he Term inal, your CVS_ROOT will be forgot t en and you'll be back in t he forest wit h a com m and line a m ile long. What do you do? Make it perm anent , of course. Doing so again differs depending on what shell you've chosen. Each shell has t he abilit y t o read a st art up file — som et hing you creat e t hat says " hey, everyt im e I st art t his shell, do t he com m ands wit hin t his file." These files are locat ed in your hom e direct ory and norm ally are not visible t o t he Finder. Wit h t he t csh shell, t he file is nam ed .t cshrc; under bash, it 's . bash_profile. Creat ing t hose files, adding t he m at ching com m and from before, and t hen st art ing a new Term inal window will set t he CVS_ROOT at st art up ( you can check t his wit h t he p r i n t e n v com m and) . Anot her alt ernat ive is using t he plist preference file form at . More inform at ion is available in t he See Also sect ion lat er in t his hack, but creat ing a file at ~ / .MacOSX/ environm ent .plist wit h t he following cont ent s would do it for you: