I Love AppleScript Studio
by - June 18th, 2004
Boy, the more I work with AppleScript Studio, the more I love the thing.
I don't use any commercial apps to maintain and manage my weblog. When I started YellowText in 1995, the word "blog" didn't even exist. A simple script to automatically upload an HTML file to my webserver became a more complicated script to automate the whole process, and eventually a simple AppleScript Studio app that took text from BBEdit, did a little dance with it, and then told Interarchy to post it. That's CWOBber (Colossal Waste of Bandwidth weblogger.). The goal for CWOBber2 was immediately obvious: make it a completely self-contained app with no need for external text editors or FTP apps at all. Make it slicker and easier to use. Maybe add a little, what do call it? Oh, yeah: "error reporting." That's the baby.
But if the motives for CWOBber2 were clear, the proper user interface wasn't. Over the past year or two I went through several different concepts and iterations and none of them felt right.
Why don't I just switch to LiveJournal or MoveableType? Because CWOBber isn't just my weblogger. It's a chance to keep studying new web standards and technologies and to keep learning about current Macintosh development tools. Plus, every programmer should eat his own dog food. But with CWOBber2, I was chugging Alpo as though I were on "Jackass" and someone bet me three dollars that I wouldn't.
Finally, while in London trying to make sense of British reality television, it came to me in a flash. I wanted to get it all down before I forgot about it. I launched Interface Builder (part of Apple's free XCode authoring system) and the Interface was Built inside of five minutes. I write a blog item in an editing window, I click a button marked "Publish," a sheet drops down so I can set some options, I click "Post," and it goes on my Web site. And it's all there. If I use Interface Builder's "Test Interface" feature, it behaves like a real application, too. Clicky-clicky, typey-typey, scrolley-scrolley...the only thing it won't do is, well, anything productive. It's sort of like one of those concept cars at the auto show, or any Apple CEO between John Sculley's ouster and Steve Jobs' return.
Though even the prototype is actually fairly useful, thanks to the fact that the editor centers around what's technically known as a ScrollView object. If you go into Interface Builder, create a new window, drag a ScrollView into it, and then add this to an AppleScript Studio project with no code whatsoever, you can click "Build" and you'll have 60% of a standalone word processor. The ScrollView object comes with a lot of ready-made features. You can type text into it. You can cut, copy and paste. You can Undo what you've Done. When you misspell a word, it's automatically underlined in red. The text automatically wraps to the width of the ScrollView and when the user resizes the window, the content dynamically resizes itself automagically. AppleScript Studio adds the usual gang of menus and adds them to your project on its own, and whaddya know: the "Print" command more or less works, too.
I really don't have time to work on CWOBber2 until I finish this next book of mine. The deadline is only days away and friends, I'm keeping my passport within reach just in case. But earlier this week I wanted to see if the interface worked well even with a huge, blog-sized pile of text in the editing window. Reflexively I dragged a text file into it from the Desktop but it didn't work. Oops...I forgot that you can't drag-and-drop into a whatsis unless you add a little bit of code to tell the thingamabob what kinds of data it should be willing to accept. 'TEXT' please, thank you, that's lovely. Two lines of AppleScript. Build. And now this empty shell of an app has full drag-and-drop functionality.
A couple of days later, I was looking at CWOBber2's interface again. The text looked kind of small. What would be the ideal type size? I didn't know. I supposed it would depend on whether I was using the app on Lilith 7 (my PowerBook, where the screen is just 16 inches away on my lap) or my desktop Mac (where it's a full two or three feet). I went back into Interface Builder and dragged a miniature popup menu to the editing window. Five lines of code later and it was all wired up. Build. And now I can change the font size whenever I want.
I also set the editor's font to something nicer than the Helvetica default. Well, golly: this is starting to look like a real application! Yesterday I got stuck searching for Le Mot Juste and I turned once again to the CWOBber2 editing window for a little diversion. There's an invisible TextField object that CWOBber2 will use for little status messages that don't merit a full-on warning dialog. Folks, word count is the bane of my existence. Every time I write something for publication my time is split 20-80. I spend 20% of my time writing the thing and then 80% trying to eviscerate the Flawless Gem of Perfect Truth, Beauty and Wisdom I've just created into the 800 words I'm actually permitted.
So when I'm right on my deadline and editors are sending me uncomfortable e-mails regarding how cheap it'd be to Priceline a ticket to Boston and how easy it would be for them to buy a gun once they got here, time is of the essence; I desperately need to keep an eye on my word count. I don't want to have to click anything to discover that Wile E. Coyote's rocket-powered roller skates have no "Off" switch and he's approaching the edge of the cliff at a distressing rate of speed. How hard would it be to add a feature to CWOBber so it gives me a live word count as I type?
Not terribly. Word count is just one line of AppleScript ('set thisVariable to the number of words in the text view of the scroll view "newBlogContent"' is literally it, I think). Turning this number into a few words of text and then sticking it in the editing window's status thingy is just another line or two. I tell Interface Builder that it needs to execute this script every time someone stops typing in that scroll view and it's done. Build.
I had a newspaper column due this afternoon. Been so busy that I didn't even start it until the AM. Clicked into BBEdit and created a new document as usual, and after I'd written the two lead paragraphs I suddenly stopped.
After a moment's thought I did a Select All, dragged the selected text into CWOBber2's editing window -- the window where practically nothing was wired up, the window where basically all I'd done was draw what the user-interface should eventually look like -- and I wrote the rest of my column.
And...well, damn. I liked using this slapped-together word processor. Liked it even more than BBEdit. Or should I say, I like it; I'm using the proto-CWOBber2 to write this column as well. BBEdit has earned a very special place in my heart. I preferred it to Word for most of my writing because it has a quick, clean, concise interface and it never ever ever changes "iMac" to "IMac" (or does anything else that might lead to PowerBook-shaped dents in my office drywall) without my asking it to. But it doesn't spell-check interactively and I have to click a button to get a word count. And after that, I have to click another button to get the word count window out of the way
There was a long stretch of my life during which I didn't write a scrap of software. Somewhere during the late Eighties it stopped being fun. When I was a tiny kid and I first learned to program, you could write 'em big or you could write 'em small. You could get immediate results from just a few lines of code, and the magic of Making Your Computer Do Something spurred you on to Make It Do Even More. Software wasn't engineered: it was grown from little seeds.
But then operating systems got way more complicated. True, making a Mac go "Beep!" was just one command, but you needed to write four pages of infrastructure before the compiler recognized that the thing you had just typed into its code-editing window was meant to be an actual working piece of software.
If you wanted it to go "Beep!" after a button was pressed...well, holy cow. Tell your significant other to find someone to sleep around with, because you were going to be very inattentive life-partner for the foreseeable future.
AppleScript is still by far the most fun I have writing code. Once again, I'm growing software. I'm not submitting myself to three days in The Bunker focusing 100% on trying to build as much of CWOBber2 in one go as I can. I just need to pour myself little shot glasses of interest and curiosity. Your app arises from the ground like a skyscraper, with little bits of structure appearing every day and a new floor being completed every week, until you find yourself with a useful application on your hands. You're partly convinced that elves are logging into your Mac remotely every night and adding bits of code on their own (after the world's last kind-hearted old cobbler was driven into bankruptcy by cheap Korean labor, they decided to update their skills; very wise...American textile workers would do well to learn by their pointy-hatted example). How else is this app growing the way it is? You just don't remember ever doing that much with this project.
AppleScript Studio reminded me that writing software is creative and energizing and exciting. Like a kid with an unplayed beta of Halo 2, I had to remind myself that deadlines loomed over the immediate horizon and that I should not, should not, should not wire up that "Publish" button so that it would take the column I just wrote and e-mail it to my editor automatically. Even though I knew it would have required a dozen lines of code, max, and perhaps twenty minutes of my time. Ditto for making the color of the interactive word count creep slowly from black to bright red the closer I get to my word count. Ditto for...
With the possible exceptions of singing at family weddings and giving your boss the severe beating he so richly deserves, anytime you have to be directly restrained from an activity, you know you're in a unique and highly positive environment.
digs the Mac, and has been writing about the Mac for longer than most of us could tell the difference between a bite of Apple Sauce from a byte of Apple code. You can read his monthly column at Macworld magazine, and his blog at the Colossal Waste of Bandwidth.
Andy's latest book is The Mac OS X Tiger Book (US$16.49 - Amazon).
Most Recent Columns From Andy Ihnatko
- You Can't Spell 'Speculate' without 'Peas' - February 22nd
- So: It's A Video iPod. Sweet! - October 13th
- How to Stuff a Wild iPod - October 13th
Andy Ihnatko's Archives
Warning: include(/usr/local/etc/httpd/sites/macobserver.com/htdocs/forums/extension.inc) [function.include]: failed to open stream: No such file or directory in /var/www/bbm/macobserver.com/ee2/www/htdocs/comments/comments.php on line 108
Warning: include() [function.include]: Failed opening '/usr/local/etc/httpd/sites/macobserver.com/htdocs/forums/extension.inc' for inclusion (include_path='.:/usr/share/php5:/usr/share/php') in /var/www/bbm/macobserver.com/ee2/www/htdocs/comments/comments.php on line 108
Warning: include(/usr/local/etc/httpd/sites/macobserver.com/htdocs/forums/common.) [function.include]: failed to open stream: No such file or directory in /var/www/bbm/macobserver.com/ee2/www/htdocs/comments/comments.php on line 110
Warning: include() [function.include]: Failed opening '/usr/local/etc/httpd/sites/macobserver.com/htdocs/forums/common.' for inclusion (include_path='.:/usr/share/php5:/usr/share/php') in /var/www/bbm/macobserver.com/ee2/www/htdocs/comments/comments.php on line 110
Warning: include(/usr/local/etc/httpd/sites/macobserver.com/htdocs/forums/includes/bbcode.) [function.include]: failed to open stream: No such file or directory in /var/www/bbm/macobserver.com/ee2/www/htdocs/comments/comments.php on line 112
Warning: include() [function.include]: Failed opening '/usr/local/etc/httpd/sites/macobserver.com/htdocs/forums/includes/bbcode.' for inclusion (include_path='.:/usr/share/php5:/usr/share/php') in /var/www/bbm/macobserver.com/ee2/www/htdocs/comments/comments.php on line 112
Fatal error: Call to a member function sql_query() on a non-object in /var/www/bbm/macobserver.com/ee2/www/htdocs/comments/comments.php on line 532
- Sat, 10:30 AM
- How-To - How to Assign Custom Icons to Desktop Files & Folders in OS X
- Fri, 8:10 PM
- Free on iTunes - 3 Free iOS Apps We Hope You Never Need
- 7:52 PM
- The Back Page - Apple’s ‘iRadio’ Streaming Excites Labels, Sony Hung on Skipping
- 3:50 PM
- Particle Debris - How the War Between Apple & Google Will be Won
- 3:29 PM
- News - Pentagon Approves iPhone & iPad for Military Use
- 1:10 PM
- TMO Quick Tip - Apple TV: Hiding Unused Icons from the Main Screen
- 10:40 AM
- Sci-Fi Airshow
- 9:17 AM
- News - CW Signs Content Deal for Apple TV
- 8:31 AM
- TMO Quick Tip - iTunes 11.0.3: New MiniPlayer Features
- Thu, 5:25 PM
- Analysis - Apple CEO Tim Cook Will Propose Corporate Tax Overhaul, Report
- 4:07 PM
- myPhoneDesktop Allows You to Send Data from Mac/PC to iPhone
- 3:03 PM
- iLuv Ships ‘Aud 5’ Lightning Speaker Dock for iPhone 5