![]() If you want to learn it, you need a guide through the mazes and minefields: skip the official documentation and steer yourself to Neuburg’s indispensible AppleScript: the Definitive Guide.įor our present purposes, we’re using a tiny, tiny piece of AppleScript: a very short script that pops up a Cancel/OK dialog box. That said, once you know what you’re doing, more or less, vast areas of customization open up to you, and amazingly, Apple has shown no signs of discontinuing it-quite the opposite. It’s a hard language to learn and a harder language to use. By making AppleScript look superficially familiar, the designers obscured the fact that it’s still a programming language with precise syntactic requirements, and the contortions needed to implement English-like syntax (among other decisions) made those requirements weird and maddeningly opaque. Unfortunately, that well-meaning effort backfired. Its syntax vaguely resembles ordinary English, so that you can write a command like this: tell the application "Finder" to open the folders in the desktop where its name starts with "A" ![]() In a misguided attempt to make it friendly for non-programmers, its designers created what Matt Neuburg calls “ the English-likeness monster”. It’s also bizarre, frustrating, inconsistent, mysterious, and generally challenging. Most important for the purposes of this article, you can interact with the user. You can augment your apps with new capabilities, or automate tasks involving multiple applications. With it, you can write scripts to control the operating system or applications (provided they’re designed to be scriptable, which is not as common as it once was - Xcode, fortunately, is scriptable). It’s an ancient scripting language built into the Mac operating system, dating back to System 7, years before OS X made its debut. If you’re developing apps on a Mac, you probably already know about AppleScript. Here’s some more background on the build process. Xcode makes a lot of information about the build, including the currently selected configuration, available to your script in environment variables. Anything you can write in a script, you can do in one of these build phases. Specifically, you can add a “Run Script” phase, which instructs Xcode to run a command-line script, such as a shell script or a Ruby script, at a given point in the build. The invaluable thing about build phases is that you can add your own. The major steps it goes through are exposed to you in the form of “build phases.” You can access the build phases by selecting your application in the main navigator pane, then selecting the main app target, and then choosing “Build Phases” from the list of tabs along the top. When you hit ⌘B to build your project, Xcode begins a complicated process that begins with the set of text files, resources, and configuration files that consitute your program, and ends with the production of an executable application. There are three ingredients in this recipe: Xcode build phases, AppleScript, and the osascript tool. (As the prompt indicates, I’m also set up to automatically increment the build number for each non-Debug build, but that’s a separate topic.) I began experimenting, and the result was this technique for making Xcode check with me before carrying out a non-Debug build. After I accidentally made a release build for the tenth or eleventh time, it started feeling like Xcode should really be helping me out here. When I’ve switched the Xcode build settings to a Release or ad-hoc build configuration to bundle an app for distribution, I’m almost incapable of remembering to set it back afterwards. Why would you need an interactive build? In my case, it warns me when I’m about to make an all-too-frequent mistake. In this post, I’m going to illustrate an approach I’ve used to add a touch of interactivity to a project build. Apple’s Mack truck of an IDE, Xcode, doesn’t give you a lot of room to mess with its build process, but there are a few options for customization.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |