Skip to content

Instantly share code, notes, and snippets.

@jmercouris
Created November 13, 2017 18:23
Show Gist options
  • Save jmercouris/fcc9223a7c681fa07084ba0fb8b42887 to your computer and use it in GitHub Desktop.
Save jmercouris/fcc9223a7c681fa07084ba0fb8b42887 to your computer and use it in GitHub Desktop.
(defmethod load-cocoa-application ((a cocoa-application))
(with-autorelease-pool
(let* ((bundle (#/mainBundle ns:ns-bundle))
(info (#/infoDictionary bundle))
(classname (#/objectForKey: info #@"NSPrincipalClass"))
(progname (#/objectForKey: info #@"CFBundleName")))
(when (%null-ptr-p classname)
(setq classname #@"NSApplication"))
(unless (%null-ptr-p progname)
(#/setProcessName: (#/processInfo ns:ns-process-info) progname))
(let* ((appclass (#_NSClassFromString classname))
(app (#/sharedApplication appclass)))
(when (%null-ptr-p app)
(error "Could not create shared instance of ~s" (%get-cfstring
classname)))
app))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment