Dissecting a Mac .app
I for one moved from a windows platform to the mac, but luckily via unix/linux so before I got to using a Mac, I had some great grounding on Unix/Linux as I was also Lecturing that at the University, teaching the Postgraduate students how to use it for Administration. Right, back to Macs, I could not understand why would one overpay to have an Apple product, while a windows box would do pretty much the same and also had Visual Basic for rapid application development.
Long story short, Microsoft killed VB6, Apple moved to intel technologies and I was given a Mac on one of the projects I was working on and I have never looked back, now I own quite a few Macs and Apple products myself and recommend Apple hardware to people that ask.
The transition from being a traditional windows user and developer to a Mac was first met with disappointment, where there was practically nothing out of the box that I could do, I could not even paint a picture using something like paintbrush. So a vanilla install was pretty much a useless one (I started with Tiger). Then I found a variety of software that could be used, mostly freeware or shareware. The apps on my mac started to grow, I also learned that installation was not a setup.exe file that one double clicked, but generally was a DMG file that was automounted and then the app had to be dragged into the
Then uninstallation was as easy as just dragging the entire app to thrash. Only to learn that there were just like in windows there are INI files, Mac has their own set of pList files. These remain behind and though small soon start to clutter the HDD. Found there were apps like AppTrap that took care of this when uninstalling apps and offered to either delete or leave these files.
Every time I worked with the Mac Apps it was a learning into the mysterious world of Mac Apps. At the time FireFox was in version 3 and when it had issues, I found a trick that said start it in Safe Mode from the Terminal. I was not scared of the terminal, but how do you start a mac app from the terminal? I tried starting the appname.app but the terminal said it was a directory. The trick mentioned that I had to use
To start the app, we just double click on it or right click and select open. There is another option that says Show Package Contents. Let us click on that, it will open up a finder window with the files it contains. These files are what make up the Corona Simulator application. At this point there are just two files, Contents (a directory) and ResourceRules.plist. We will look at the pList later, let us further double click on the Contents. This has 7 items in it,
Of these, the ones that are of interest to us are the MacOS and the Resources folders. The resources folder is the folder that generally holds all the images, icons and *resources* that are used for the project. If you have been developing for the Mobile Devices (iOS) you already are aware of the ResourceDirectory. The application Icon is always a file called Icons.icns, which may have multiple sized icons for the application.
The other directory, MacOS is the directory that holds the executable, this is the app that you need to spawn, not only can you run that but also pass parameters from the command line to it. so if you are using CoronaSDK, you can pass it the command line parameters
Also if you want to have your own little commandline thingie to spawn your own app, you can just write these few lines of code in xcode and get it to work using the terminal.
Start xCode, start a new project, select Mac OSX, and select commandline, in the
Then build it, doesn't really matter at this point if it is debug or release. Then go to the folder where you have the project saved, look for the folder called build, it will then further have a sub folder either called Debug or Release and inside that folder is the app that we just created. You can rename it to whatever you want, move it out to the folder of your choice if you so wish.
Testing it in real life...
Now, we need to run it from the terminal (command line) so what we do is type
where of course the yourUsername would be whatever it is on your mac, the yourProjectName is the name of your project that you want to spawn.
Well, that's that this is the actual Mac App, it is *ugly* in the sense it has no Icon, you can just double click it to spawn it.
Hope that gave you information on both the Mac Applications structure and the application that can spawn other apps and write to the console, a lot many of you have been trying to capture that information in their own apps, well this is how you can.
One final Tip: If you want to mangle the output, i.e. hijack the output and then change portions of it, it is not just *easily* possible and beyond the scope of this project/article.
Long story short, Microsoft killed VB6, Apple moved to intel technologies and I was given a Mac on one of the projects I was working on and I have never looked back, now I own quite a few Macs and Apple products myself and recommend Apple hardware to people that ask.
The transition from being a traditional windows user and developer to a Mac was first met with disappointment, where there was practically nothing out of the box that I could do, I could not even paint a picture using something like paintbrush. So a vanilla install was pretty much a useless one (I started with Tiger). Then I found a variety of software that could be used, mostly freeware or shareware. The apps on my mac started to grow, I also learned that installation was not a setup.exe file that one double clicked, but generally was a DMG file that was automounted and then the app had to be dragged into the
/Applications
folder.Then uninstallation was as easy as just dragging the entire app to thrash. Only to learn that there were just like in windows there are INI files, Mac has their own set of pList files. These remain behind and though small soon start to clutter the HDD. Found there were apps like AppTrap that took care of this when uninstalling apps and offered to either delete or leave these files.
Every time I worked with the Mac Apps it was a learning into the mysterious world of Mac Apps. At the time FireFox was in version 3 and when it had issues, I found a trick that said start it in Safe Mode from the Terminal. I was not scared of the terminal, but how do you start a mac app from the terminal? I tried starting the appname.app but the terminal said it was a directory. The trick mentioned that I had to use
appname.app/Content/MacOS/appname
. This piqued my interest and I got on to dissecting an app. For this purpose let us have a look at the CoronaSDK Simulator app.To start the app, we just double click on it or right click and select open. There is another option that says Show Package Contents. Let us click on that, it will open up a finder window with the files it contains. These files are what make up the Corona Simulator application. At this point there are just two files, Contents (a directory) and ResourceRules.plist. We will look at the pList later, let us further double click on the Contents. This has 7 items in it,
- _CodeSignature (Directory)
- Frameworks (Directory)
- MacOS (Directory)
- Resources (Directory)
- PkgInfo (File)
- Info.pList (File)
- CodeResources (Shortcut)
Of these, the ones that are of interest to us are the MacOS and the Resources folders. The resources folder is the folder that generally holds all the images, icons and *resources* that are used for the project. If you have been developing for the Mobile Devices (iOS) you already are aware of the ResourceDirectory. The application Icon is always a file called Icons.icns, which may have multiple sized icons for the application.
The other directory, MacOS is the directory that holds the executable, this is the app that you need to spawn, not only can you run that but also pass parameters from the command line to it. so if you are using CoronaSDK, you can pass it the command line parameters
-project
and the path to your project
. This will start the simulator and open the project for you.Also if you want to have your own little commandline thingie to spawn your own app, you can just write these few lines of code in xcode and get it to work using the terminal.
Start xCode, start a new project, select Mac OSX, and select commandline, in the
main.c
file type the following code// // main.c // runSimulator // // Created by Jayant Varma on 27/09/11. // Copyright 2011 OZ Apps. All rights reserved. // #include#include #define command "'/Users/Applications/CoronaSDK/Corona Simulator.app/Contents/MacOS/Corona Simulator'" //Change this if it is in a different location on your system. int main( int argc, char *argv[] ) { char s[200]; sprintf(s, command); i = argc; if (argc > 1){ sprintf(s,"%s -project '%s'",s,argv[1]); } system(s); return 0; }
Then build it, doesn't really matter at this point if it is debug or release. Then go to the folder where you have the project saved, look for the folder called build, it will then further have a sub folder either called Debug or Release and inside that folder is the app that we just created. You can rename it to whatever you want, move it out to the folder of your choice if you so wish.
Testing it in real life...
Now, we need to run it from the terminal (command line) so what we do is type
theAppname
(if it is in the search path, if it is not this will not work, alternatively you can go to the directory that has this file and then run it but you will need to prefic wit with a ./
) this will start the simulator (if you had the path correct) but no project is opened as we did not pass it any parameters on which project to start. To do so, we can drag the folder icon onto the terminal and it will put the filepath for us to use. generally there will be problems if there are spaces in the path, so add a ' at the start and a ' at the end of this path, so an example commandline would beappname '/Users/yourUserName/Desktop/yourProjectName'
where of course the yourUsername would be whatever it is on your mac, the yourProjectName is the name of your project that you want to spawn.
Well, that's that this is the actual Mac App, it is *ugly* in the sense it has no Icon, you can just double click it to spawn it.
Hope that gave you information on both the Mac Applications structure and the application that can spawn other apps and write to the console, a lot many of you have been trying to capture that information in their own apps, well this is how you can.
One final Tip: If you want to mangle the output, i.e. hijack the output and then change portions of it, it is not just *easily* possible and beyond the scope of this project/article.
Comments
Post a Comment