DATA pt. 4 – Running from Command Line and Logging
This is part of the continuing series of articles on Developing Appcelerator Titanium Applications (DATA)
Running Titanium Apps from the Command Line
To run a Titanium app using a command line script as opposed to starting it up through the Titanium Developer App, we placed the following in a file named run.sh inside our app’s directory.
export PATH=$PATH:/Library/Application\ Support/Titanium/sdk/osx/0.6.0/ tibuild.py -d . -s /Library/Application\ Support/Titanium -r -a /Library/Application\ Support/Titanium/sdk/osx/0.6.0 ./
The tibuild.py does our work for us and running ./run.sh from the command line starts our app up without having to open the Titanium Developer App.
Logging
This is a short blurb on the difference between Titanium logging and Firebug’s logging. At the top of our Javascript file we have the following try/catch statement to setup our log var.
try {
var log = Titanium.App.stdout; // Titanium's logging to the command line
} catch (squash) {
var log = console.log; // console logging for Webkit/Firebug
}The try/catch is an easy way to ensure we have the right logging for the right environment. We want TItanium logging when running Titanium and console.log as the default.
Calling logging is simple from this point:
log('HELLO!');