Note. I was still learning this while you were updating with what you used, but I will add this FWIW.
Using the bundle identifier of an application is usually a more reliable way to access the application and then using only the name, since the user can move or rename the application in OS X, but they cannot easily change the package identifier. Moreover, even when Apple renamed iCal.app in Calendar.app, CFBundleIdentifier is still com.apple.iCal .
if (![[NSWorkspace sharedWorkspace] launchAppWithBundleIdentifier:@"com.apple.iCal" options:NSWorkspaceLaunchDefault additionalEventParamDescriptor:nil launchIdentifier:NULL]) { NSLog(@"launching Calendar.app failed!"); }
The above code will work even if your application is isolated. You could try creating a custom NSAppleEventDescriptor that would indicate the equivalent of something like the following AppleScript code, but would most likely fail because of the sandbox:
view calendar at date "Sunday, April 8, 2012 4:28:43 PM"
If your application does not need to be isolated, it is much easier if you use Scripting Bridge, and with this method you can select a specific NSDate .
Sample project using ScriptingBridge: OpenCalendar.zip
In this project, I use the following code:
SBCalendarApplication *calendarApp = [SBApplication applicationWithBundleIdentifier:@"com.apple.iCal"]; [calendarApp viewCalendarAt:[self.datePicker dateValue]];
Calendar.app/iCal.app launches and changes the calendar to the specified date.
NSGod source share