static PyObject *Launch_LSFindApplicationForInfo(PyObject *_self, PyObject *_args) { PyObject *_res = NULL; OSStatus _err; OSType inCreator; CFStringRef inBundleID; CFStringRef inName; FSRef outAppRef; CFURLRef outAppURL; if (!PyArg_ParseTuple(_args, "O&O&O&", PyMac_GetOSType, &inCreator, OptCFStringRefObj_Convert, &inBundleID, OptCFStringRefObj_Convert, &inName)) return NULL; _err = LSFindApplicationForInfo(inCreator, inBundleID, inName, &outAppRef, &outAppURL); if (_err != noErr) return PyMac_Error(_err); _res = Py_BuildValue("O&O&", PyMac_BuildFSRef, &outAppRef, CFURLRefObj_New, outAppURL); return _res; }
// Launches the "System Events" process. static OSStatus WBLaunchSystemEvents(ProcessSerialNumber *psnPtr) { OSStatus err; FSRef appRef; check(psnPtr != NULL); // Ask Launch Services to find System Events by creator. err = LSFindApplicationForInfo(kSystemEventsCreator, NULL, NULL, &appRef, NULL); // Launch it! if (noErr == err) { LSApplicationParameters appParams; // Do it the easy way on 10.4 and later. memset(&appParams, 0, sizeof(appParams)); appParams.version = 0; appParams.flags = kLSLaunchDefaults; appParams.application = &appRef; err = LSOpenApplication(&appParams, psnPtr); } return err; }
void CUtils::LaunchRemoteDesktop(CBSLTaskInstance& bslTaskInstance) { if (!bslTaskInstance.GetRemoteDesktopAddress().IsEmpty()) { wxString strConnection(bslTaskInstance.GetRemoteDesktopAddress()); wxString strCommand; #if defined(__WXMSW__) strCommand = wxT("mstsc.exe /v:") + strConnection; wxExecute(strCommand); #elif defined(__WXGTK__) strCommand = wxT("rdesktop-vrdp ") + strConnection; wxExecute(strCommand); #elif defined(__WXMAC__) FSRef theFSRef; OSStatus status = noErr; status = LSFindApplicationForInfo('RDC#', CFSTR("net.sf.cord"), NULL, &theFSRef, NULL); if (status != noErr) { ::wxMessageBox( _("Please download and install the CoRD application from http://cord.sourceforge.net"), _("Missing application"), wxOK | wxICON_INFORMATION ); } else { strCommand = wxT("osascript -e 'tell application \"CoRD\"' -e 'activate' -e 'open location \"rdp://") + strConnection + wxT("\"' -e 'end tell'"); strCommand.Replace(wxT("localhost"), wxT("127.0.0.1")); system(strCommand.char_str()); } #endif } }
static PyObject *AE_LSFindApplicationForInfo(PyObject *_self, PyObject *_args) { PyObject *_res = NULL; OSStatus _err; OSType inCreator; CFStringRef inBundleID; CFStringRef inName; FSRef outAppRef; char path[PATH_MAX]; if (!PyArg_ParseTuple(_args, "O&O&O&", AE_GetOSType, &inCreator, AE_GetCFStringRef, &inBundleID, AE_GetCFStringRef, &inName)) return NULL; _err = LSFindApplicationForInfo(inCreator, inBundleID, inName, &outAppRef, NULL); if (inBundleID != NULL) CFRelease(inBundleID); if (inName != NULL) CFRelease(inName); if (_err != noErr) return AE_MacOSError(_err); _err = FSRefMakePath(&outAppRef, (UInt8 *)path, PATH_MAX); _res = PyUnicode_DecodeUTF8(path, strlen(path), NULL); return _res; }
OSErr CScreensaver::GetpathToBOINCManagerApp(char* path, int maxLen) { CFStringRef bundleID = CFSTR("edu.berkeley.boinc"); OSType creator = 'BNC!'; FSRef theFSRef; OSStatus status = noErr; status = LSFindApplicationForInfo(creator, bundleID, NULL, &theFSRef, NULL); if (status == noErr) status = FSRefMakePath(&theFSRef, (unsigned char *)path, maxLen); return status; }
int main(int argc, char **argv) { /* Look up the application by its bundle identifier, which is given in the Info.plist file. This will continue to work even if the user changes the name of the application, unlike fullPathForApplication. */ FSRef fsref; OSStatus status; int len; char buf[BUFSIZE]; status = LSFindApplicationForInfo(NULL,CFSTR("edu.upenn.cis.Unison"),NULL,&fsref,NULL); if (status) { if (status == kLSApplicationNotFoundErr) { fprintf(stderr,"Error: can't find the Unison application using the Launch Services database.\n"); fprintf(stderr,"Try launching Unison from the Finder, and then try this again.\n",status); } else fprintf(stderr,"Error: can't find Unison application (%d).\n",status); exit(1); } status = FSRefMakePath(&fsref,buf,BUFSIZE); if (status) { fprintf(stderr,"Error: problem building path to Unison application (%d).\n",status); exit(1); } len = strlen(buf); if (len + strlen(EXECPATH) + 1 > BUFSIZE) { fprintf(stderr,"Error: path to Unison application exceeds internal buffer size (%d).\n",BUFSIZE); exit(1); } strcat(buf,EXECPATH); /* It's important to pass the absolute path on to the GUI, that's how it knows where to find the bundle, e.g., the Info.plist file. */ argv[0] = buf; // printf("The Unison executable is at %s\n",argv[0]); // printf("Running...\n"); execv(argv[0],argv); /* If we get here the execv has failed; print an error message to stderr */ perror("unison"); exit(1); }
int main(int argc, const char **argv) { CFURLRef cfurl; OSStatus err = LSFindApplicationForInfo(0, CFSTR("com.apple.Xcode"), 0, 0, &cfurl); if (err != noErr) return internal_error; CFBundleRef bundle = CFBundleCreate(0, cfurl); if (bundle == 0) return internal_error; CFStringRef str = CFStringRef(CFBundleGetValueForInfoDictionaryKey(bundle, CFSTR("CFBundleShortVersionString"))); const char * ptr = CFStringGetCStringPtr(str, 0); if (ptr == 0) return internal_error; // self-test const char * fail1 = "2.4"; const char * fail2 = "2.4.0"; const char * fail3 ="2.3"; const char * ok1 = "2.4.1"; const char * ok2 ="2.5"; const char * ok3 ="3.0"; // ptr = fail1; // printf ("string: %s\n", ptr); int length = strlen(ptr); if (length < 3) // expect "x.y" at least return internal_error; // fail on 2.4 and below (2.4.1 is ok) if (ptr[0] < '2') return fail; if (ptr[0] >= '3') return success; if (ptr[2] < '4') return fail; if (length < 5) return fail; if (ptr[4] < '1') return fail; return success; }
void Moose::launchAudioscrobbler( const std::vector<std::string>& vargs ) { FSRef appRef; LSFindApplicationForInfo( kLSUnknownCreator, CFSTR( AUDIOSCROBBLER_BUNDLEID ), NULL, &appRef, NULL ); const void* arg[vargs.size()]; int index(0); AEDescList argAEList; AECreateList( NULL, 0, FALSE, &argAEList ); for( std::vector<std::string>::const_iterator i = vargs.begin(); i != vargs.end(); i++ ) { arg[index++] = CFStringCreateWithCString( NULL, i->c_str(), kCFStringEncodingUTF8 ); AEPutPtr( &argAEList, 0, typeChar, i->c_str(), i->length()); } LSApplicationParameters params; params.version = 0; params.flags = kLSLaunchAndHide | kLSLaunchDontSwitch | kLSLaunchAsync;; params.application = &appRef; params.asyncLaunchRefCon = NULL; params.environment = NULL; CFArrayRef args = CFArrayCreate( NULL, ((const void**)arg), vargs.size(), NULL); params.argv = args; AEAddressDesc target; AECreateDesc( typeApplicationBundleID, CFSTR( AUDIOSCROBBLER_BUNDLEID ), 16, &target); AppleEvent event; AECreateAppleEvent ( kCoreEventClass, kAEReopenApplication , &target, kAutoGenerateReturnID, kAnyTransactionID, &event ); AEPutParamDesc( &event, keyAEPropData, &argAEList ); params.initialEvent = &event; LSOpenApplication( ¶ms, NULL ); AEDisposeDesc( &argAEList ); AEDisposeDesc( &target ); }
std::string Moose::applicationPath() { FSRef appRef; LSFindApplicationForInfo( kLSUnknownCreator, CFSTR( AUDIOSCROBBLER_BUNDLEID ), NULL, &appRef, NULL ); char path[PATH_MAX]; FSRefMakePath( &appRef, (unsigned char*)path, PATH_MAX ); if ( path == NULL ) return "/Applications/Last.Fm.app/Contents/MacOS/Last.fm"; std::string s = path; s.append( "/Contents/MacOS/Last.fm" ); return s; }
bool XMacSystem::SearchExecutablePath( const VString& inExecutableName, VFilePath& outPath) { // first lookup in environment variables bool found = XBSDSystem::SearchExecutablePath( inExecutableName, outPath); // then ask launch services if (!found) { VString name( inExecutableName); if (!name.EndsWith( CVSTR( ".app"))) name += CVSTR( ".app"); CFURLRef cfAppUrl = NULL; CFStringRef cfName = name.MAC_RetainCFStringCopy(); OSStatus status = LSFindApplicationForInfo( kLSUnknownCreator, NULL /* inBundleID */, cfName, NULL /* outFSRef */, &cfAppUrl); if (cfName != NULL) CFRelease( cfName); if (status == noErr) { if (testAssert( cfAppUrl != NULL)) { CFStringRef cfPosixPath = ::CFURLCopyFileSystemPath( cfAppUrl, kCFURLPOSIXPathStyle); if (testAssert( cfPosixPath != NULL)) { VString posixPath; posixPath.MAC_FromCFString( cfPosixPath); posixPath.Compose(); // add an ending / because it's a bundle folder posixPath += "/"; outPath.FromFullPath( posixPath, FPS_POSIX); found = true; ::CFRelease( cfPosixPath); } } } if (cfAppUrl != NULL) CFRelease( cfAppUrl); } return found; }
static int ask_launch_services(const char *appid, char *buf, size_t bufsize) { /* Ask LaunchServices to find product by identifier... */ OSStatus rc; CFURLRef url = NULL; CFStringRef id = CFStringCreateWithBytes(NULL, BAD_CAST appid, strlen(appid), kCFStringEncodingUTF8, 0); rc = LSFindApplicationForInfo(kLSUnknownCreator, id, NULL, NULL, &url); CFRelease(id); if (rc == noErr) { Boolean b = CFURLGetFileSystemRepresentation(url, TRUE, BAD_CAST buf, bufsize); CFRelease(url); return(b != 0); } /* if */ return(0); }
OSStatus FindPIDForWoW(pid_t *pid) { CFURLRef outAppURL; OSErr err; err = LSFindApplicationForInfo(NULL, (CFStringRef)@"com.blizzard.worldofwarcraft", NULL, NULL, &outAppURL); err = 0; FSRef desired, found; ProcessSerialNumber psn = {0, kNoProcess}; if (!CFURLGetFSRef(outAppURL, &desired)) return errFSBadFSRef; do { err = GetNextProcess(&psn); if (err) return err; // -600 = process not found err = GetProcessBundleLocation(&psn, &found); } while (err || FSCompareFSRefs(&desired, &found)); err = GetProcessPID(&psn, pid); if (err) return err; return noErr; }
static void set_x11_path(void) { #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050 CFURLRef appURL = NULL; OSStatus osstatus = LSFindApplicationForInfo(kLSUnknownCreator, CFSTR(kX11AppBundleId), nil, nil, &appURL); switch (osstatus) { case noErr: if (appURL == NULL) { fprintf(stderr, "Xquartz: Invalid response from LSFindApplicationForInfo(%s)\n", kX11AppBundleId); exit(1); } if (!CFURLGetFileSystemRepresentation(appURL, true, (unsigned char *)x11_path, sizeof(x11_path))) { fprintf(stderr, "Xquartz: Error resolving URL for %s\n", kX11AppBundleId); exit(3); } strlcat(x11_path, kX11AppBundlePath, sizeof(x11_path)); #ifdef DEBUG fprintf(stderr, "Xquartz: X11.app = %s\n", x11_path); #endif break; case kLSApplicationNotFoundErr: fprintf(stderr, "Xquartz: Unable to find application for %s\n", kX11AppBundleId); exit(10); default: fprintf(stderr, "Xquartz: Unable to find application for %s, error code = %d\n", kX11AppBundleId, (int)osstatus); exit(11); } #else /* TODO: Make Tiger smarter... but TBH, this should never get called on Tiger... */ strlcpy(x11_path, "/Applications/Utilities/X11.app/Contents/MacOS/X11", sizeof(x11_path)); #endif }
bool CamulewebApp::GetTemplateDir(const wxString& templateName, wxString& templateDir) { wxString dir; m_localTemplate = false; DebugShow(wxT("looking for template: ") + templateName + wxT("\n")); #ifdef __WXMAC__ CFURLRef amuleBundleUrl; OSStatus status = LSFindApplicationForInfo( kLSUnknownCreator, // This magic string is the bundle identifier in aMule.app's Info.plist CFSTR("org.amule.aMule"), NULL, NULL, &amuleBundleUrl); if (status == noErr && amuleBundleUrl) { CFBundleRef amuleBundle = CFBundleCreate(NULL, amuleBundleUrl); CFRelease(amuleBundleUrl); if (amuleBundle) { CFURLRef webserverDirUrl = CFBundleCopyResourceURL( amuleBundle, CFSTR("webserver"), NULL, NULL); CFRelease(amuleBundle); if (webserverDirUrl) { CFURLRef absoluteURL = CFURLCopyAbsoluteURL(webserverDirUrl); CFRelease(webserverDirUrl); if (absoluteURL) { CFStringRef pathString = CFURLCopyFileSystemPath( absoluteURL, kCFURLPOSIXPathStyle); CFRelease(absoluteURL); #if wxCHECK_VERSION(2, 9, 0) dir = wxCFStringRef(pathString). AsString(wxLocale::GetSystemEncoding()); #else dir = wxMacCFStringHolder(pathString). AsString(wxLocale::GetSystemEncoding()); #endif if (CheckDirForTemplate(dir, templateName)) { templateDir = dir; return true; } } } } } #endif dir = GetConfigDir(wxT("remote.conf")) + wxT("webserver"); if (CheckDirForTemplate(dir, templateName)) { templateDir = dir; m_localTemplate = true; return true; } #ifdef WEBSERVERDIR dir = wxT(WEBSERVERDIR); if (CheckDirForTemplate(dir, templateName)) { templateDir = dir; return true; } #endif dir = wxStandardPaths::Get().GetResourcesDir(); // Returns 'aMule' when we use 'amule' elsewhere #if !defined(__WXMSW__) && !defined(__WXMAC__) dir = dir.BeforeLast(wxFileName::GetPathSeparator()); dir = JoinPaths(dir, wxT("amule")); #endif dir = JoinPaths(dir, wxT("webserver")); if (CheckDirForTemplate(dir, templateName)) { templateDir = dir; return true; } // template not found. reverting to default const wxChar* const defaultTemplateName = wxT("default"); if ( templateName == defaultTemplateName ) { return false; } Show(wxT("Template ") + templateName + wxT(" not found, reverting to default\n\n")); return GetTemplateDir(defaultTemplateName, templateDir); }
static OSStatus LaunchSystemEvents(ProcessSerialNumber *psnPtr) // Launches the "System Events" process. { OSStatus err; FSRef appRef; assert(psnPtr != NULL); // Ask Launch Services to find System Events by creator. err = LSFindApplicationForInfo( kSystemEventsCreator, NULL, NULL, &appRef, NULL ); // Launch it! if (err == noErr) { if ( LSOpenApplication != NULL ) { LSApplicationParameters appParams; // Do it the easy way on 10.4 and later. memset(&appParams, 0, sizeof(appParams)); appParams.version = 0; appParams.flags = kLSLaunchDefaults; appParams.application = &appRef; err = LSOpenApplication(&appParams, psnPtr); } else { FSSpec appSpec; LaunchParamBlockRec lpb; // Do it the compatible way on earlier systems. // I launch System Events using LaunchApplication, rather than // Launch Services, because LaunchApplication gives me back // the ProcessSerialNumber. Unfortunately this requires me to // get an FSSpec for the application because there's no // FSRef version of Launch Application. if (err == noErr) { err = FSGetCatalogInfo(&appRef, kFSCatInfoNone, NULL, NULL, &appSpec, NULL); } if (err == noErr) { memset(&lpb, 0, sizeof(lpb)); lpb.launchBlockID = extendedBlock; lpb.launchEPBLength = extendedBlockLen; lpb.launchControlFlags = launchContinue | launchNoFileFlags; lpb.launchAppSpec = &appSpec; err = LaunchApplication(&lpb); } if (err == noErr) { *psnPtr = lpb.launchProcessSN; } } } return err; }
int main(int argc, const char * argv[]) { CFStringRef bundleID = CFSTR("org.cocoapods.CocoaPods"); CFStringRef envScript = CFSTR("bundle/bin/bundle-env"); const char *shPath = "/bin/sh"; const char *podBin = "pod"; // ----------------------------------------------------------------------------------------------- // Try to locate the CocoaPods.app bundle. // ----------------------------------------------------------------------------------------------- CFURLRef appURL = NULL; CFStringRef appFilename = CFSTR("CocoaPods.app"); const char *explicitApp = getenv("CP_APP"); if (explicitApp) { if (access(explicitApp, F_OK) == 0) { // An existing path is specified, so assume that the user meant that that’s the app bundle. size_t len = strlen(explicitApp); appURL = CFURLCreateFromFileSystemRepresentation(NULL, (const UInt8 *)explicitApp, len, true); } else { // Try to find an app bundle with the specified name (without extname) as filename. size_t len = strlen(explicitApp)+5; char filename[len]; snprintf(filename, len, "%s.app", explicitApp); appFilename = CFStringCreateWithCString(NULL, filename, kCFStringEncodingUTF8); } } else { // See if the user has specified a default that specifies the path to the app bundle. // NOTE This is not going to be advertised just yet, but investigative users may use it :) CFStringRef appPath = CFPreferencesCopyAppValue(CFSTR("CPApplicationBundlePath"), bundleID); if (appPath) { appURL = CFURLCreateWithFileSystemPath(NULL, appPath, kCFURLPOSIXPathStyle, true); CFRelease(appPath); } } if (appURL == NULL) { OSType creator = kLSUnknownCreator; OSStatus status = LSFindApplicationForInfo(creator, bundleID, appFilename, NULL, &appURL); Boolean found = status != kLSApplicationNotFoundErr; if (found && explicitApp != NULL) { CFStringRef foundAppFilename = CFURLCopyLastPathComponent(appURL); found = CFStringCompare(appFilename, foundAppFilename, 0) == kCFCompareEqualTo; CFRelease(foundAppFilename); } if (!found) { CFIndex len = CFStringGetLength(appFilename)+1; char filename[len]; CFStringGetCString(appFilename, filename, len, kCFStringEncodingUTF8); fprintf(stderr, "[!] Unable to locate the %s application bundle. Please ensure the " \ "application is available and launch it at least once.\n", filename); CFRelease(appURL); CFRelease(appFilename); return -1; } } CFURLRef envScriptURL = CFBundleCopyResourceURLInDirectory(appURL, envScript, NULL, NULL); assert(envScriptURL != NULL); CFRelease(appURL); CFRelease(appFilename); const char envScriptPath[PATH_MAX]; assert(CFURLGetFileSystemRepresentation(envScriptURL, false, (UInt8 *)envScriptPath, PATH_MAX)); CFRelease(envScriptURL); // ----------------------------------------------------------------------------------------------- // Create arguments list for that calls `/bin/sh /path/to/bundle-env pod […]` and appends the // arguments that were passed to this program. // ----------------------------------------------------------------------------------------------- const char *args[argc+3]; args[0] = shPath; args[1] = envScriptPath; args[2] = podBin; for (int i = 1; i < argc; i++) { args[i+2] = *(argv+i); } args[argc+2] = NULL; // ----------------------------------------------------------------------------------------------- // Replace process. // ----------------------------------------------------------------------------------------------- #ifdef DEBUG printf("$ '%s'", envScriptPath); for (const char **i = args; *i != NULL; i++) { printf(" '%s'", *i); } printf("\n"); #endif execv(shPath, (char *const *)args); fprintf(stderr, "Failed to execute `%s` (%d - %s)\n", envScriptPath, errno, strerror(errno)); return errno; }
int main( int argc, char *argv[] ) { int i, j, quartzMode = -1; char **newargv; // Check if we are going to run in Quartz mode or idle // to support startx from the Quartz server. The last // parameter in the list is the one used. for (i = argc-1; i; i--) { if (!strcmp(argv[i], "-idle")) { pause(); return 0; } else if (!strcmp(argv[i], "-quartz") || !strcmp(argv[i], "-rootless") || !strcmp(argv[i], "-fullscreen")) { quartzMode = 1; break; } else if (!strcmp(argv[i], "-iokit")) { quartzMode = 0; break; } } if (quartzMode == -1) { #ifdef HAS_CG_MACH_PORT // Check if the CoreGraphics window server is running. // Mike Paquette says this is the fastest way to determine if it is running. CFMachPortRef cgMachPortRef = CGWindowServerCFMachPort(); if (cgMachPortRef == NULL) quartzMode = 0; else quartzMode = 1; #else // On older systems we assume IOKit mode. quartzMode = 0; #endif } if (quartzMode) { // Launch the X server for the quartz modes char quartzPath[PATH_MAX+1]; int pathLength; OSStatus theStatus; CFURLRef appURL; CFStringRef appPath; Boolean success; // Build the new argument list newargv = (char **) malloc((argc+2) * sizeof(char *)); for (j = argc; j; j--) newargv[j] = argv[j]; newargv[argc] = "-nostartx"; newargv[argc+1] = NULL; // Use the XDarwinQuartz soft link if it is valid pathLength = readlink(XPATH(XDarwinQuartz), quartzPath, PATH_MAX); if (pathLength != -1) { quartzPath[pathLength] = '\0'; newargv[0] = quartzPath; execv(newargv[0], newargv); } // Otherwise query LaunchServices for the location of the XDarwin application theStatus = LSFindApplicationForInfo(kLSUnknownCreator, CFSTR("org.xfree86.XDarwin"), NULL, NULL, &appURL); if (theStatus) { fprintf(stderr, "Could not find the XDarwin application. (Error = 0x%lx)\n", theStatus); fprintf(stderr, "Launch XDarwin once from the Finder.\n"); return theStatus; } appPath = CFURLCopyFileSystemPath (appURL, kCFURLPOSIXPathStyle); success = CFStringGetCString(appPath, quartzPath, PATH_MAX, CFStringGetSystemEncoding()); if (! success) { fprintf(stderr, "Could not find path to XDarwin application.\n"); return success; } // Launch the XDarwin application strncat(quartzPath, "/Contents/MacOS/XDarwin", PATH_MAX); newargv[0] = quartzPath; execv(newargv[0], newargv); fprintf(stderr, "Could not start XDarwin application at %s.\n", newargv[0]); return errno; } else { // Build the new argument list newargv = (char **) malloc((argc+1) * sizeof(char *)); for (j = argc; j; j--) newargv[j] = argv[j]; newargv[0] = "XDarwin"; newargv[argc] = NULL; // Launch the IOKit X server execvp(newargv[0], newargv); fprintf(stderr, "Could not start XDarwin IOKit X server.\n"); return errno; } }
static PyObject *AE_AddressDescToPath(PyObject *_self, PyObject *_args) { AEDesc desc; ProcessSerialNumber psn; pid_t pid; OSType creatorType = kLSUnknownCreator; Size cSize; char *cStr; CFStringRef bundleID = NULL; FSRef fsref; UInt8 path[PATH_MAX]; PyObject* pathObj; OSStatus err; if (!PyArg_ParseTuple(_args, "O&", AE_AEDesc_Convert, &desc)) return NULL; switch (desc.descriptorType) { case typeKernelProcessID: err = AEGetDescData(&desc, &pid, sizeof(pid)); if (err) return AE_MacOSError(err); err = GetProcessForPID(pid, &psn); if (err) return AE_MacOSError(err); err = GetProcessBundleLocation(&psn, &fsref); if (err) return AE_MacOSError(err); break; case typeProcessSerialNumber: err = AEGetDescData(&desc, &psn, sizeof(psn)); if (err) return AE_MacOSError(err); err = GetProcessBundleLocation(&psn, &fsref); if (err) return AE_MacOSError(err); break; case typeApplSignature: err = AEGetDescData(&desc, &creatorType, sizeof(creatorType)); if (err) return AE_MacOSError(err); err = LSFindApplicationForInfo(creatorType, bundleID, NULL, &fsref, NULL); if (err) return AE_MacOSError(err); break; case typeApplicationBundleID: cSize = AEGetDescDataSize(&desc); cStr = malloc((size_t)cSize); if (!cStr) return AE_MacOSError(errAECoercionFail); err = AEGetDescData(&desc, cStr, cSize); if (err) return AE_MacOSError(err); bundleID = CFStringCreateWithBytes(NULL, (UInt8 *)cStr, (CFIndex)cSize, kCFStringEncodingUTF8, 0); free(cStr); if (!bundleID) return AE_MacOSError(errAECoercionFail); err = LSFindApplicationForInfo(creatorType, bundleID, NULL, &fsref, NULL); if (err) return AE_MacOSError(err); break; case typeMachPort: // unsupported case typeApplicationURL: // unsupported (remote applications) default: return AE_MacOSError(errAECoercionFail); } err = FSRefMakePath(&fsref, path, sizeof(path)); if (err) return AE_MacOSError(err); pathObj = PyUnicode_DecodeUTF8((char *)path, strlen((char *)path), NULL); return Py_BuildValue("O", pathObj); }