Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
73 lines (64 sloc) 1.9 KB
#if defined(__APPLE__) || defined(SC_IPHONE)
#include <sys/param.h>
#include <stdexcept>
#include <cstring> // for strncpy
#include <mach-o/dyld.h> // for _NSGetExecutablePath
#include <libgen.h>
#include <stdlib.h>
#include <CoreFoundation/CFString.h>
#include <CoreFoundation/CFBundle.h>
//#include <CoreServices/CoreServices.h>
#include "SC_StandAloneInfo_Darwin.h"
bool SC_StandAloneInfo::haveCheckedBundleStatus;
char SC_StandAloneInfo::dirPath[PATH_MAX];
void SC_StandAloneInfo::SC_StandAloneInfoInit() {
char relDir[PATH_MAX];
CFStringEncoding encoding = kCFStringEncodingASCII;
if(!haveCheckedBundleStatus) {
haveCheckedBundleStatus = true;
CFURLRef enablerURL = CFBundleCopyResourceURL (
if ( enablerURL ) {
// If sclang or SuperCollider binary is run within the .app bundle,
// this is how we find the Resources path.
CFStringRef rawPath = CFURLCopyFileSystemPath(enablerURL, kCFURLPOSIXPathStyle);
rawPath = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@/.."), rawPath);
CFStringGetCString(rawPath, relDir, PATH_MAX, encoding);
} else {
// when sclang is run from a symlink, the resource URL above will not be found,
// so we need to find the path of the executable.
uint32_t *bufsize;
*bufsize = PATH_MAX;
if(_NSGetExecutablePath(relDir, bufsize)==0) {
realpath(relDir, dirPath); // resolve symlink
char *dir = dirname(dirPath);
strcpy(dirPath, dir);
} else {
// in case it failed, fall back to current directory
getcwd(dirPath, PATH_MAX);
realpath(relDir, dirPath);
bool SC_StandAloneInfo::IsStandAlone() {
return true;
return false;
void SC_StandAloneInfo::GetResourceDir(char* pathBuf, int length)
if ( !haveCheckedBundleStatus )
strncpy(pathBuf, dirPath, length);
Something went wrong with that request. Please try again.