Archive for the ‘Mac’ Category

Only running unit tests in Xcode if the build was successful

August 14th, 2009 2 comments

My workflow in Xcode is typical TDD – write a test, run the tests, write some code, run the tests…  I set up a “Run Script” build phase, so that every time I build the tests, they are automatically run.  The only problem is that the “Run Script” happens whether the build was successful or not.  So, I try to build and fail, and then the same exact tests that I already ran, automatically run again – while I sit there and wait.

The solution turned out to be very simple.  “Run Script” build phases in Xcode can have input files and output files.  The phase is only run if some input files were more recently modified than some output files.  Thus, if we set the input file to be the test executable, and the output files to be all the source files, then the tests will only run if the build is successful.  It will look something like this when set up:

Conditional Run Script Phase

Applescript to safely open links from Apple Mail

July 27th, 2009 No comments

I’m (justifiably) nervous about following links from emails.  I wrote an applescript that sets my mind at ease.  It works like this:

  1. I copy the link to the clipboard (right-click on it)
  2. I run the script
  3. it automatically finds the site name e.g. “orbitz” from “” and opens up a new google search in Safari.
  4. When I click on the hit that’s the real site, the script inserts the domain name of the real site into the link from the email
  5. The valid link comes up in Safari

I just thought about searching my Safari bookmarks, but this got the process down from manually editing the URL to three mouse clicks, so I’m happy :)

set link_to_scrub to (get the clipboard)

set text item delimiters to "/"
set tokens_to_scrub to text items of link_to_scrub

set domain_name_to_scrub to (get item 3 of tokens_to_scrub)

set text item delimiters to "."
set url_labels_to_scrub to text items of domain_name_to_scrub

tell application "Safari"
make new document with properties {URL:"" & (item 2 of url_labels_to_scrub)}

set current_url to a reference to URL of document 1

repeat until current_url starts with ""
delay 0.1
end repeat

repeat while current_url starts with ""
delay 0.1
end repeat
end tell

set text item delimiters to "/"
set real_tokens to text items of (current_url as string)

set real_domain_name to (get item 3 of real_tokens)

set text item delimiters to "."
set real_url_labels to text items of real_domain_name

repeat with current_label_index from -2 to -1
set item current_label_index of url_labels_to_scrub to item current_label_index of real_url_labels
end repeat

set real_domain_name to url_labels_to_scrub as string
set item 3 of tokens_to_scrub to real_domain_name

set text item delimiters to "/"
set real_link to (tokens_to_scrub as string)

tell application "Safari"
set URL of document 1 to real_link
end tell

Categories: Applescript, Mac Tags: , , ,

Applescript Studio Debugger/Breakpoint Fiasco

July 16th, 2009 No comments

I was working on an Applescript Studio project with Objective-C mixed in, when all of a sudden, without any warning or intervention from me, the debugger ceased to load when I ran the app (in debug mode). Hmmm, little gremlins, hackers from Russia???

After searching the lists and checking off the usual culprits (debug configuration, yes; debug symbols enabled, ditto), I went to my old-standby-last-resort-when-xcode-starts-acting-crazy-for-no-reason move: I created a fresh project, confirmed that it was working normally, and then opened every setting window in both projects to see what settings are different, and so could possible be contributing to the hiccup.

When I opened the settings for the executable (I was desparate), I noticed that the “Debugging->When using…” drop-down was different. Now, to you or I, “when using” seems to say “these setting only apply when you happen to be using X.” Yet on planet Xcode, it seems to translate into “when you change X, you’re project will begin to work in a different way then usual, even if you do not change any o the settings in this window.” I selected “GDB” from the drop-down, and all my problems were solved… maybe that’s a bit dramatic.

Anyway, my breakpoints are again working (in both the Obj-C and applescript code). Yay!

Categories: Mac, Programming, Xcode Tags: , ,

Getting the process ID of a Mac App

July 15th, 2009 No comments

It seems like a common-enough problem, yet after striking out on the mailing list archives, coding sites, and Apple Developer Connection, I wrote this little Cocoa snippet to find the process ID of a particular app:

// Just replace this first string with your app name
NSString* target_app_name = @"Finder";
NSWorkspace* workspace = [NSWorkspace sharedWorkspace];
NSArray* active_apps = [workspace launchedApplications];
NSNumber* process_id = nil;

for (int i = 0; i < [active_apps count]; ++i) {
  NSDictionary* current_app = [active_apps objectAtIndex:i];
  NSString* app_name = [current_app valueForKey:@"NSApplicationName"];

  if ([app_name isEqualToString:target_app_name])
  process_id = [current_app valueForKey:@"NSApplicationProcessIdentifier"];
Categories: Mac, Programming Tags: ,

Applescript to add inclusion guards to C++ Header files in Xcode

April 26th, 2009 No comments

I got tired of manually adding them, so here’s a little script…

set list_lib to load script alias “Path:To:List Utilities.scpt”

tell application “Xcode”

Get file name of front-most document (via window)

set header_file_path to associated file name of window 1


Go back and get the source file using the name

set header_file to first source document whose path is header_file_path

Turn the file into a list of lines to
— find the insertion point for the inclusion guard

set lines_of_header to paragraphs of text of header_file

Create the inclusion guard based on the file name

set inclusion_guard_token to first word of (get name of header_file) 

set guard_start to “\n#ifndef “ & inclusion_guard_token 
& “\n” & “#define “ & inclusion_guard_token & “\n”


Insert the start of the guard

set lines_of_header to list_lib‘s list_insert(lines_of_header, guard_start, 9)

Insert the end of the guard

set end of lines_of_header to “\n\n#endif”

Set the revised contents of the file

set text of header_file to (lines_of_header as text)

end tell

List Utilities.scpt (code from AppleScript: The Definitive Guide, 2nd Edition:

on find_in_list(what, L)

repeat with i from 1 to count L

if item i of L is what then

return (a reference to item i of L)

end if

end repeat


end find_in_list

on list_insert(L, what, ix)

if ix = 1 then

return {what} & L


return {item 1 of L} & list_insert(rest of L, what, ix - 1)

end if

end list_insert

Categories: Mac, Programming Tags: , ,

Hippomocks 2.0 on Mac OS X

April 22nd, 2009 No comments

I’m exploring Hippomocks, a C++ mock library.


The library supplies a test suite for compilers not known to be supported.  GCC is listed, but I think Apple’s version is a little different than standard GCC, so I’ll run that.  Pretty easy in Terminal:

  1. “cd /path/to/Hippoocks/HippoMocksTest/”
  2. “make test” (there’s also a test0x, but it requires >= GCC 4.3, which is confirmed when my Mac doesn’t recognize “-std=c++0x”)

And… errors :(  But easy ones to fix…

cc1plus: warnings being treated as errors

../HippoMocks/hippomocks.h:139: warning: ‘class func_index’ has virtual functions but non-virtual destructor

is_virtual.cpp:4: warning: ‘class IL’ has virtual functions but non-virtual destructor

test_class_mock.cpp:24: warning: ‘class IG’ has virtual functions but non-virtual destructor
n.b. the above errors were over several compiles, but I showed them together for brevity.
Picking up where we left off… “make test” now succeeds, and ./test reports:
The final step, per the installation instructions, is to copy the single header file, hippomocks.h, into a system directory.  I’m putting it in /usr/local/include.
That’s it!  The library is ready for use in all my C++ projects.  All I have to do is #include <hippomocks.h> and go to town.
Categories: Mac, Programming Tags: , , , , ,

Automate acceptance/unit testing C++ in Xcode

April 13th, 2009 2 comments

In my quest to automate all repetitive tasks, setting up a Xcode project for unit testing (using Boost.Test) is in my crosshairs.  I’m in the process of adopting BDD, so you’ll see that terminology mixed with that of unit testing.


  1. List out all the manual steps.  I started with the process described by Richard Dingwall in a very nice tutorial here.
  2. Implement task in Applescript
Manual process

Ok, so here’s what I do when I start a new C++ project…

  1. File->New Project…
  2. Add Group “Features” @ [project-directory]/Features
  3. Add Group “Specifications” @ [project-directory]/Specifications
  4. Add Group “Boost Test Common” @ [project-directory]/Boost Test Common
  5. Add XcodeLogFormatter.h (allows Boost.Test reports to be properly displayed in Xcode build results; see below) and run_tests.cpp (Boost.Test’s main function) to Boost Test Common
  6. Add Features Target
    1. Add->”New Target”
    2. BSD->Shell Tool
    3. Name: Features
    4. Add run_tests.cpp to “Compile Sources”
    5. Add “/usr/local/include/boost-1_38/” to “Header Search Paths” of Features Target
    6. Add->New Build Phase->New Run Script Build Phase
    7. Script: “${TARGET_BUILD_DIR}/${EXECUTABLE_NAME}” (this causes the Features to be run every time the target is built)
  7. Add Specification (i.e. unit tests) Target: repeat step 6 above for “Specifications”
  8. Add->Existing Files->[boost unit test library]; check Targets: “Features” and “Specifications”

Finally done!  Here’s the script and Xcode library script.

Not Doing Now

As I work, I make a list of things that would be nice to have, but are not important enough to think about right now and would take me away from my task:

  1. Put Boost Test Common files in a commonly accessible include folder

Source Code

XcodeLogFormatter.h (from

#include <boost/test/included/unit_test.hpp>

struct xcode_log_formatter :
public boost::unit_test::output::compiler_log_formatter
// Produces an Xcode-friendly message prefix.
void print_prefix(std::ostream& output,
boost::unit_test::const_string file_name, std::size_t line
output << file_name << ‘:’ << line << “: “;

run_tests.cpp (from

#include <boost/test/unit_test.hpp>
#include “XcodeLogFormatter.h”

// Set up the unit test framework to use an xcode-friendly log formatter.
struct xcode_config {
xcode_config() {
boost::unit_test::unit_test_log.set_formatter( new xcode_log_formatter );
~xcode_config() {}

// Call our fixture.

(updated) Check out the finished AppleScripts:
1. main script @
2. Xcode handler library script @

Building Boost Libraries for Mac ppc & x86

April 7th, 2009 No comments

By default, Boost builds libraries for your native architecture only.  I’m sure there is a better way, but an easy way I found without manually using bjam is adding “architecture=combined” to the makefile that configure generates.  E.g:

@$(BJAM) $(BJAM_CONFIG) –user-config=user-config.jam –prefix=$(prefix) –exec-prefix=$(exec_prefix) –libdir=$(libdir) –includedir=$(includedir) architecture=combined $(LIBS) install || echo “Not all Boost libraries built properly.”

Categories: Mac, Programming Tags: ,

expatpp C++ XML Parser Library wrapper

March 27th, 2009 No comments

expatpp is a free wrapper to the also free expat C XML Parser library.  Unfortunately, it doesn’t exist… or so I thought.

The sourceforge site doesn’t have any files to download, but after some fishing, I found a download which includes expatpp and a compatible version of expat here.

After removing the txt from the Makefile in expatpp/expat and running “make all” from terminal, I had a static version of expatpp, ready to go!  Sort of.  The makefile builds expat, the underlying library.  So far, I’m simply including the single source file in my projects.

You just have to move the expat lib to the directory of your choice (there is no install target in the Makefile) and also expatpp.h & xmlparse.h (so far) where your projects will be able to find them.

Categories: Mac, Programming Tags:

HTML Tidy on Mac

March 27th, 2009 No comments

God bless free software providers.  But, oh how painful the installation!!  After slogging through outdated documentation, this is how to download HTML Tidy through cvs on the mac.

Fire up Terminal and enter the following commands:

  • cvs login
  • [Press Enter when asked for a password]
  • cvs -z3 export -f -Dnow tidy
Yay!  Now that you have the source…
  1. cd path/of/installed/source
  2. cd build/gmake
  3. make all
  4. sudo make install (I changed the include dir in the makefile first)
Categories: Mac, Web Development Tags:

windows 7 product key

windows 7 product key

windows 7 key generator

windows 7 key generator

free winrar download

free winrar download

winzip activation code

winzip activation code

free winrar

free winrar

winzip free download

winzip free download

winrar free download

winrar free download

winrar download free

winrar download free

winzip free download full version

winzip free download full version

windows 7 activation crack

windows7 activation crack

windows 7 crack

windows 7 crack

free winzip

free winzip