|
8-22-02
Build a Bundle - Part 2 by
Erick Tejkowsi
In our last REALbasic tutorial, we began creating a project to help you create application bundles. This week, we'll continue
with the same project, giving it the ability to add Classic Mac applications (i.e. not Carbon) to the bundle.
The result is a bundle that you can double-click
in Mac OS 9 or Mac OS X.
Build the Interface
Since this week's tutorial is a continuation to a previous project, there aren't any interface additions this time.
If you missed the last tutorial where we built the interface,
you can download it here.
Source Code
In Part 1 of the Bundle Builder project, we added some code to the Action event of PushButton1. This time we'll
also be adding code to that event. Since there are a number of changes to make, it would probably be easiest if you simply deleted
all of the code that is within PushButton1. In its place, add this code:
Dim dlgApp,dlgAppOS9 as OpenDialog
Dim f,ff,ffOS9 as FolderItem
dim contents,destApp,destMacOS,destMacOS9 as folderItem
dim infoplist, pkgInfo as textoutputStream
dim r as resourcefork
dim s,stringToFind,appLocation as string
//select or create a new folder
//to use as the base for our bundle
f=selectfolder
If f <> Nil and f.exists then
//select a Carbon application
//that we will add to the bundle
dlgApp=New OpenDialog
dlgApp.InitialDirectory=DesktopFolder
dlgApp.Title="Select a REALbasic-made Carbon application."
dlgApp.Filter="application"
ff=dlgApp.ShowModal()
//select a Classic application
//that we will add to the bundle
dlgApp=New OpenDialog
dlgApp.InitialDirectory=DesktopFolder
dlgApp.Title="Select a REALbasic-made Classic application."
dlgApp.Filter="application"
ffOS9=dlgApp.ShowModal()
if ff<>nil and ff.exists then
// Create folder named "Contents" in it.
contents = f.child("Contents")
if contents<>nil then
contents.createAsFolder
// Create PkgInfo file (which contains type and creator)
pkgInfo = contents.child("PkgInfo").createtextFile
if pkginfo<>nil then
pkgInfo.write ff.MacType+ff.MacCreator
pkgInfo.close
end if
// Create Info.plist file using 'plist' resource from the built application.
r=ff.openresourceFork
infoplist = contents.child("Info.plist").createtextFile
if infoplist<>nil then
s = r.getResource("plst",0)
//add an entry to the plist file, before we create it
//this points to the Carbon executable in the MacOS folder
stringToFind = "</dict>"+chr(13)+"</plist>"
appLocation = appLocation+"<key>CFBundleExecutable</key>"+chr(13)
appLocation = appLocation+"<string>"+ff.name+"</string>"+chr(13)
//this little bit of code, squeezes in the CFBundleExecutable
//at the end of the file, but before the
//"</dict></plist>" that ends the plist file
appLocation = appLocation+stringToFind
s=replace(s,stringToFind,appLocation)
//create the .plist file
infoplist.write s
infoplist.close
end if
//create a folder to store the carbon app
destMacOS = contents.child("MacOS")
if destMacOS<>nil then
destMacOS.createAsFolder
// Copy the application into the app folder (MacOS)
ff.copyFileTo destMacOS.child(ff.name)
end if
//create a folder to store the classic app
destMacOS9 = contents.child("MacOSClassic")//MacOSClassic
if destMacOS9<>nil then
destMacOS9.createAsFolder
// Copy the application into the app folder (MacOS)
ffOS9.copyFileTo destMacOS9.child(ffOS9.name)
//code adapted from Matt Neuburg's Alias example
//using his "MakeAlias" AppleScripts
//www.tidbits.com/matt/newbookexamples/ch21_Files/makeAlias.hqx
if targetcarbon then
s = makeAlias2(destMacOS9.child(ffOS9.name).absolutePath, f.absolutePath, ffOS9.name)
else
s = makeAlias(destMacOS9.child(ffOS9.name).absolutePath, f.absolutePath, ffOS9.name)
end
end if
// Set folder name + ".app" extension
// (works in place of setting the bundle bit)
f.name = f.name+".app"
MsgBox "Bundle is complete!"
end if
else
MsgBox "No application chosen. Unable to create bundle."
end if
Else
MsgBox "No folder chosen. Unable to create bundle."
End if
Notice that in the above code, we make two calls: makeAlias and makeAlias2. These method names
match the names of two AppleScripts you'll need to add to the project. They are scripts
from Matt Neuburg. Matt wrote REALbasic: The Definitive Guide. Once you've downloaded Matt's Alias example,
drag the two included scripts into your Bundle Builder project window.
So, what's going on here? Like the Carbon application we added last week, a Classic-only version of the application
can also be part of your bundle. It must reside in a folder called "MacOSClassic". Our code creates that folder
and copies the selected Classic application to it. Finally, we need to add an alias to the Classic application to
the root of the bundle. Hence the need for Matt's scripts. Creating this alias causes the bundle's icon to match that
of the Classic application in OS 9.
Conclusion
That's it for this week. Select Debug->Run to test your work. As is the custom, you can download
the finished project. See you next week!
9-3-02
REALbasic News
by Erick Tejkowsi
iff Taxi
Cherie Benoit has announced a Made-wth-REALbasic app:
iff Taxi.
iff Taxi is a Macintosh utility made with REALbasic for categorizing
object IFF files for use with "The Sims" and its various expansion
packs. With it users can edit objects so they can be used with the
new Downtown and Vacation Isle areas of the game. It also allows
users to get around a game bug involving a limit on build mode type
objects. Download-addicts will appreciate iff Taxi's ability to edit
multiple files at once. Large collections of objects can be made
Downtown- or Vacation-ready in a matter of minutes.
Port Tester
Colourfull Creations has released Port Tester for OS X and OS 9 as
Freeware. Port Tester is a small application that was written to test
out sockets/ports on the Macintosh. You can use it to connect to an IP
and start a conversation or to listen on a specific port for data.
Port Tester is released as freeware and can be downloaded here.
Key Features:
- Easy to use
- Comes with source
- Freeware
UserMsg
George Clark has posted UserMsg, a tool for creating cross-platform alert dialogs, including
Sheets in Mac OS X, complete with an appropriate icon, text and
user-definable buttons. The user's response can be read and used to
determine what, if any, further actions are needed. UserMsg is Freeware.
UserMsg consists of various custom classes, windows and a module that all
work together to create their magic.
UserMsg requires REALbasic v4 or later. In order to use sheets, you *must*
have at least REALbasic v4.5. Any attempt to use UserMsg's sheet window in
any version of RB less than 4.5 will crash REALbasic.
UserMsg also requires the 'mfile' plug-in, part of 'OSX Utils' (see the link
in the UserMsg docs if you don't have OSX Utils).
UserMsg can be found at:http://gaclark.home.sprynet.com/realbasic.html
FontPrinter Tutorial at AppleLinks
Another fine REALbasic tutorial by Marc
Zeedar (of RB Developer fame)
is at AppleLinks: REALbasic Lesson 066: FontPrinter: Part Five
App Bundler 1.0a1
Thomas Reed has released App Bundler 1.0a1, which is a nearly total
rewrite of the previous 1.0dx versions.
App Bundler is a MwRB program that creates a bundle from an existing
Carbon and/or Classic application. It requires OS X and Mac OS X 10.2.
App Bundler is freeware and includes the source code.
You can find it here.
8-27-02
REALbasic News
by Erick Tejkowsi
About Box and Undo from Forbes
Scott Forbes has a couple REALbasic-related offerings this week.
-
Undo Toolkit 4.5.1 is a powerful, flexible implementation of the
Undo command that can be added to existing projects, providing
unlimited multiple Undo and Redo with minimal memory footprint.
Undo Toolkit 4.5.1 is open source software, released under the GNU
General Public License.
It's available for download here.
-
AquaAboutBox 1.0
AquaAboutBox is a set of REALbasic window templates that follow
Apple's Aqua Human Interface Guidelines for an about box. The Aqua
HI Guidelines are very specific about the layout and content of Mac
OS X about boxes, with exact rules for icon placement, font sizes,
distance between elements and other requirements.
These templates will save you the tedious effort of designing your
about box to Apple's exact specs -- just download AquaAboutBox,
choose the template that best suits your application, fill in the
blanks, and be done in five minutes. AquaAboutBox also includes
the StaticURL class, a StaticText subclass that behaves like a web
link. AquaAboutBox is public domain software, and you can
download the source code.
T3TracePlugin
3TAG AB announced that the T3TracePlugin now is
available for download.
T3TracePlugin is the REALbasic developers dream when it comes to track
down bugs. Logging exactly what you want right when you need it. And, on
the Win32 platform, where you have no really good way of knowing what
happens within your REALbasic application, the T3TracePlugin is a vital
part of getting your application running well and have platform specific
bugs found and eliminated before your users find them.
Son of Weather Grok
Son of Weather Grok is Made with REALbasic by Bains Software.
Son of Weather Grok, a popular desktop weather application, has been
updated to v4.2.1. This version fixes the Query feature, which was broken by
an NOAA website update, and makes it much easier to set up forecasts.
Direct Download
RB Plugin Plunger
Alfred Van Hoek has posted an Alpha release of RB Plugin Plunger. Check it out!
NavBar Builder
REALmac Software released NavBar Builder,
the easiest way to create a whole web site complete with
javaScript rollover navigation bars. NavBar Builder will allow you to build
web sites faster than ever before.
NavBar Builder 1.6 is Made with REALbasic.
MBS Plugin
MonkeyBread has announced the
availability of the MBS Plugin in version 2.6 beta. Yes, Mac OS X 10.2
is just released and they still need some time to verify that everything
works, but everyone is welcome to try the new stuff.
You can find the
software and the online documentation on their website.
Lighthouse
Lighthouse from Electric Butterfly is available!
Available for both Classic Mac OS 9 and Mac OS X (Not yet tested on 10.2 Jaguar), Lighthouse is created with REALbasic.
|