Articles 3D Audio Custom Controls General RB Graphics Hacks Mac OS X Menus Novelty Printing REALbasic 2005 REALbasic 2006 Registration Resources Reviews Serial Speech Sockets XML Video Resource Links News Current News February 2006 January 2006 December 2005 November 2005 October 2005 September 2005 August 2005 July 2005 June 2005 May 2005 April 2005 March 2005 ![]() REALbasic for Dummies by Erick Tejkowski ![]() Learning REALbasic through Applications REALbasic for Macintosh REALbasic Cross-Platform Application Development
Older files are in Stuffit 5 or greater format. Newer files are ".Zip". Download StuffIt Expander |
|
The release of Mac OS X marked the introduction of the Unix command line to thousands of Mac-o-philes all over the world. Despite feeling like a step backwards in time, the command line (typically accessed using the Terminal application included with Mac OS X) affords Mac junkies all sorts of tricks and hacks for customizing the Mac OS. REALbasic 3 introduces a new feature, called the Shell Class , which gives you the ability to use command line functions from within your own REALbasic project. This new feature makes it a cinch to give your OS X tweaks an interface as well as saving you from having to look up the hack each time. It also helps out those folks who are terrified of the command line (believe me, they're out there). Now, they can take part in the Mac OS X fun too. Background One of the more popular Mac OS X hacks around involves changing the genie effect of the dock. The hack involves launching the Terminal application and entering one of the following commands:
Once you've entered a command, you must force quit the dock to make the changes take effect. To do so from the command line, you have to:
Wheeww! As you can see, it takes quite a bit of work to accomplish this simple hack via the command line and it is hardly elegant as far as interfaces go. Luckily, REALbasic changes all of that. Create the interface To illustrate, begin by launching a copy of REALbasic 3. By default, REALbasic starts you off with an empty project, as shown here:
Double click Window1 in the Project Window to open the window. Then, from the toolbar, drag two PushButtons and three RadioButtons onto your Window1 interface. You can lay out the interface out anyway you desire, but it might look something like this:
The RadioButtons will permit a user to choose a genie effect, while the PushButtons will be used to change the genie effect and to restart the dock. For the purposes of this demonstration, the PushButtons and RadioButtons will be named and labeled according to this table:
Add the code Now, you have an interface, but it doesn't do anything yet. To add functionality, double-click PushButton1 to open the Code Editor. Add the following code to its Action Event. // Create two variables to store the command and the Shell Object.Dim Command as string Dim Terminal As Shell // Which genie behavior has the user chosen? // i.e. Create a command depending on which RadioButton is currently selected. If RadioButton1.Value then Command = "defaults write com.apple.Dock mineffect genie" ElseIf RadioButton2.Value then Command = "defaults write com.apple.Dock mineffect suck" ElseIf RadioButton3.Value then Command = "defaults write com.apple.Dock mineffect scale" End If // Create the Shell object Terminal = New Shell // Now, execute the command Terminal.Execute Command If Terminal.ErrorCode=0 then // No errors; everything worked without a hitch. MsgBox "genie behavior changed" Else // Ooops, an error occurred! Display the error. MsgBox "Error Code: " + Str(Terminal.ErrorCode) End If This code looks at which RadioButton is currently selected and builds a command accordingly. The commands should look familiar from the Terminal example earlier. Next, it's time to execute the command. To do so, you must first create a Shell Object. Once you have, it's a trivial matter to send the command to the Shell Object using the Execute method. If the command executed properly without errors, then ErrorCode will equal "0" (zero) and we display a message to the user. If something other than zero is returned, then something went wrong and we display the error instead. Of course, this code only takes care of the first step. The next step is to kill the dock, so we can see the effect of the changes we made. You could continue using the Shell Object and write some similar code that would find the PID of the Dock process and kill it. But, why bother? There's an easier way to do the same thing with REALbasic. AppleScript to the rescue! Yep, that's right. AppleScript can take care of this laborious function for us. Fire up the AppleScript Script Editor application and create a script like this:
Once you have entered the necessary code, save the AppleScript as a Compiled Script making sure not to include any spaces in the name of the file. For this example, I chose the name QuitTheDock. After you save the script, you can quit the Script Editor and return to REALbasic. Add the script you just made to your REALbasic project by dragging it into the Project Window from the Finder or by choosing File->Import. Finally, double-click PushButton2 to open the Code Editor. To the Action Event of PushButton2 add this one line of code: QuitTheDockTest and Build the Project Believe it or not, that's all there is to it! To test your handiwork, choose Debug->Run. If everything works as it should, you should be able to change the genie behavior of the dock at will. Once you have decided that you have created the project correctly, build the final application in REALbasic by choosing File->Build Application. Now, you won't ever have to type those commands in by hand again and the GUI gods will look down on you favorably. Where to go from here If you don't like typing or had any troubles recreating this project, you can download If you have no interest in programming, you can also downloadKeep in mind that this same approach can be applied to all sorts of Mac interface hacks. To give you some ideas, be sure to look at these links: |
||||||||||||||||
|
||||||||||||||||||||||||||||||||
Maintained by the Staff of ResExcellence. This entire site ©1997-2006 ResExcellence
Privacy Statement? Sure we gotta Privacy Statement.
[an error occurred while processing this directive]