Index: doc/tk_mac.n ================================================================== --- doc/tk_mac.n +++ doc/tk_mac.n @@ -25,19 +25,21 @@ \fB::tk::mac::OnShow\fR \fB::tk::mac::ShowHelp\fR \fB::tk::mac::PerformService\fR \fB::tk::mac::LaunchURL \fIURL...\fR \fB::tk::mac::GetAppPath\fR +\fB::tk::mac::GetInfoAsJSON \fB::tk::mac::standardAboutPanel\fR \fB::tk::mac::useCompatibilityMetrics \fIboolean\fR \fB::tk::mac::CGAntialiasLimit \fIlimit\fR \fB::tk::mac::antialiasedtext \fInumber\fR \fB::tk::mac::useThemedToplevel \fIboolean\fR \fB::tk::mac::iconBitmap \fIname width height \-kind value\fR + .fi .BE .SH "EVENT HANDLER CALLBACKS" .PP The Aqua/macOS application environment defines a number of additional @@ -218,10 +220,15 @@ customized for the specific URL scheme the developer wants to support. .TP \fB::tk::mac::GetAppPath\fR . Returns the current applications's file path. +.TP +\fB::tk::mac::GetInfoAsJSON\fR +. +Returns a JSON-encoded Tcl string which serializes the application's +\fBmainBundle.infoDictionary\fR (defined by its \fIInfo.plist\fR file). .PP .SH "ADDITIONAL DIALOGS" .PP Aqua/macOS defines additional dialogs that applications should support. Index: macosx/tkMacOSXInit.c ================================================================== --- macosx/tkMacOSXInit.c +++ macosx/tkMacOSXInit.c @@ -40,10 +40,12 @@ * Forward declarations... */ static Tcl_ObjCmdProc2 TkMacOSXGetAppPathObjCmd; static Tcl_ObjCmdProc2 TkMacOSVersionObjCmd; +static Tcl_ObjCmdProc2 TkMacOSXGetInfoAsJSONObjCmd; + #pragma mark TKApplication(TKInit) @implementation TKApplication @synthesize poolLock = _poolLock; @@ -699,10 +701,12 @@ TkMacOSXStandardAboutPanelObjCmd, NULL, NULL); Tcl_CreateObjCommand2(interp, "::tk::mac::iconBitmap", TkMacOSXIconBitmapObjCmd, NULL, NULL); Tcl_CreateObjCommand2(interp, "::tk::mac::GetAppPath", TkMacOSXGetAppPathObjCmd, NULL, NULL); + Tcl_CreateObjCommand2(interp, "::tk::mac::GetInfoAsJSON", + TkMacOSXGetInfoAsJSONObjCmd, NULL, NULL); Tcl_CreateObjCommand2(interp, "::tk::mac::macOSVersion", TkMacOSVersionObjCmd, NULL, NULL); MacSystrayInit(interp); MacPrint_Init(interp); @@ -725,11 +729,11 @@ *---------------------------------------------------------------------- */ static int TkMacOSXGetAppPathObjCmd( - TCL_UNUSED(void *), + TCL_UNUSED(void *), /* clientData */ Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[]) { if (objc != 1) { @@ -813,11 +817,11 @@ *---------------------------------------------------------------------- */ static int TkMacOSVersionObjCmd( - TCL_UNUSED(void *), + TCL_UNUSED(void *), /* clientData */ Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[]) { static char version[16] = ""; @@ -829,10 +833,62 @@ snprintf(version, 16, "%d", [NSApp macOSVersion]); } Tcl_SetResult(interp, version, NULL); return TCL_OK; } + +/* + *---------------------------------------------------------------------- + * + * TkMacOSXGetInfoAsJSONObjCmd -- + * + * Returns the contents of the Info.plist file in the application + * bundle as a JSON-encoded Tcl string. + * + * Results: + * Returns the JSON encoding of the Info.plist file.. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +static int +TkMacOSXGetInfoAsJSONObjCmd( + TCL_UNUSED(void *), /* clientData */ + Tcl_Interp *interp, + Tcl_Size objc, + Tcl_Obj *const objv[]) +{ + static char *bytes = NULL; + + if (objc != 1) { + Tcl_WrongNumArgs(interp, 1, objv, NULL); + return TCL_ERROR; + } + + if (bytes == NULL) { + NSJSONWritingOptions opt = NSJSONWritingPrettyPrinted; + NSDictionary *infoDict = [[NSBundle mainBundle] + infoDictionary]; + NSData *infoAsJSON = [NSJSONSerialization + dataWithJSONObject: infoDict + options:opt + error:nil]; + if (infoAsJSON.length) { + int buffer_size = (int) infoAsJSON.length + 1; + bytes = malloc(buffer_size); + strlcpy(bytes, infoAsJSON.bytes, buffer_size); + } + } + if (bytes) { + Tcl_SetObjResult(interp, Tcl_NewStringObj(bytes, TCL_INDEX_NONE)); + return TCL_OK; + } + return TCL_ERROR; +} /* *---------------------------------------------------------------------- * * TkpDisplayWarning --