All Projects → progrium → Macdriver

progrium / Macdriver

Licence: mit
Native Mac APIs for Go

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to Macdriver

webviewhs
🌐 A Haskell binding to the webview library created by Serge Zaitsev.
Stars: ✭ 109 (-96.96%)
Mutual labels:  bindings, native-apps, cocoa, webkit
Fruity
Rusty bindings for Apple libraries
Stars: ✭ 72 (-97.99%)
Mutual labels:  apple, bindings, cocoa
Quickeys
A mac menu bar app that provides note taking functionality though a quick dropdown menu.
Stars: ✭ 54 (-98.49%)
Mutual labels:  mac, apple
mbpfan
A simple daemon to control fan speed on all MacBook/MacBook Pros (probably all Apple computers) for Linux Kernel 3 and newer
Stars: ✭ 680 (-81.02%)
Mutual labels:  mac, apple
Sensors
A macOS application displaying the thermal, voltage and current sensor values.
Stars: ✭ 70 (-98.05%)
Mutual labels:  mac, apple
Doesitarm
🦾 A list of reported app support for Apple Silicon and the new Apple M1 Macs
Stars: ✭ 3,200 (-10.66%)
Mutual labels:  apple, macos-application
Google-Docs-for-Mac
Native Google Docs app for Mac
Stars: ✭ 33 (-99.08%)
Mutual labels:  native-apps, webkit
LAPSforMac
Local Administrator Password Solution for Mac
Stars: ✭ 29 (-99.19%)
Mutual labels:  mac, apple
Ultratabsaver
The open source Tab Manager Extension for Safari.
Stars: ✭ 178 (-95.03%)
Mutual labels:  apple, mac
pre-commit-macadmin
Pre-commit hooks for Mac admins.
Stars: ✭ 43 (-98.8%)
Mutual labels:  mac, apple
Geek Blog
基于Vue+Nuxt.js服务器渲染(SSR)搭建的个人博客系统
Stars: ✭ 33 (-99.08%)
Mutual labels:  mac, apple
Macos Egpu Cuda Guide
Set up CUDA for machine learning (and gaming) on macOS using a NVIDIA eGPU
Stars: ✭ 187 (-94.78%)
Mutual labels:  apple, mac
Wwdc Notes
WWDCNotes.com content ✨
Stars: ✭ 183 (-94.89%)
Mutual labels:  apple, cocoa
Notarize
Notarization status monitoring tool for macOS, supporting multiple developer accounts.
Stars: ✭ 90 (-97.49%)
Mutual labels:  mac, apple
Quotefixformac
QuoteFix for Apple Mail —
Stars: ✭ 181 (-94.95%)
Mutual labels:  apple, mac
brewfile
🍎 Brewfile to install softwares in macOS for engineers
Stars: ✭ 37 (-98.97%)
Mutual labels:  mac, apple
Mac Setup
🛠️ Front end web development setup for macOS.
Stars: ✭ 265 (-92.6%)
Mutual labels:  apple, mac
Awesome Macos
 A curated list of awesome applications, softwares, tools and shiny things for macOS.
Stars: ✭ 12,565 (+250.78%)
Mutual labels:  apple, mac
Rapidpayload
Framework RapidPayload - Metasploit Payload Generator | Crypter FUD AntiVirus Evasion
Stars: ✭ 174 (-95.14%)
Mutual labels:  apple, mac
Clean-macOS
💻 A simple script to setup a clean environment on macOS
Stars: ✭ 155 (-95.67%)
Mutual labels:  mac, apple

MacDriver Logo

Native Mac APIs for Golang!

GoDoc Test workflow Go Report Card @progriumHQ on Twitter Project Forum Sponsor Project


MacDriver is a toolkit for working with Apple/Mac APIs and frameworks in Go. It currently has 2 parts:

1. Bindings for Objective-C

The objc package wraps the Objective-C runtime to dynamically interact with Objective-C objects and classes:

cls := objc.NewClass("AppDelegate", "NSObject")
cls.AddMethod("applicationDidFinishLaunching:", func(app objc.Object) {
	fmt.Println("Launched!")
})
objc.RegisterClass(cls)

delegate := objc.Get("AppDelegate").Alloc().Init()
app := objc.Get("NSApplication").Get("sharedApplication")
app.Set("delegate:", delegate)
app.Send("run")
  • Access any class or method you can access in Objective-C
  • Common object convenience methods: Get, Set, Alloc, Init, ...
  • Create and extend classes at runtime that can be used by Objective-C code
  • Retain and Release methods for working with Objective-C memory management

2. Framework Packages

The cocoa, webkit, and core packages wrap objc with wrapper types for parts of the Apple/Mac APIs. They're being added to as needed by hand until we can automate this process with schema data. These packages effectively let you use Apple APIs as if they were native Go libraries, letting you write Mac applications (potentially also iOS, watchOS, etc) as Go applications:

func main() {
	app := cocoa.NSApp_WithDidLaunch(func(notification objc.Object) {
		config := webkit.WKWebViewConfiguration_New()
		wv := webkit.WKWebView_Init(core.Rect(0, 0, 1440, 900), config)
		url := core.URL("http://progrium.com")
		req := core.NSURLRequest_Init(url)
		wv.LoadRequest(req)

		w := cocoa.NSWindow_Init(core.Rect(0, 0, 1440, 900),
			cocoa.NSClosableWindowMask|
				cocoa.NSTitledWindowMask,
			cocoa.NSBackingStoreBuffered, false)
		w.SetContentView(wv)
		w.MakeKeyAndOrderFront(w)
		w.Center()
	})
	app.SetActivationPolicy(cocoa.NSApplicationActivationPolicyRegular)
	app.ActivateIgnoringOtherApps(true)
	app.Run()
}
  • 1:1 mapping of API names with Objective-C APIs
  • Cocoa types: NSApplication, NSImage, NSMenu, NSWindow, more ...
  • Webkit types: WKWebView and configuration classes
  • Core types: NSData, NSDictionary, NSNumber, NSPoint, NSRect, NSSize, NSString, NSURL, more ...
  • Core also allows dispatching Go functions in the Cocoa run loop
  • Many constants/enums are defined

Examples

examples/largetype - A Contacts/Quicksilver-style Large Type utility in under 80 lines: largetype screenshot

examples/pomodoro - A menu bar pomodoro timer in under 80 lines: pomodoro gif

examples/topframe - An always-on-top webview with transparent background in 120 lines [requires Go 1.16+]: topframe screenshot

NEW: See progrium/topframe for a more fully-featured standalone version!

Generating wrappers

Eventually we can generate most of the wrapper APIs using bridgesupport and/or doc schemas. However, the number of APIs is pretty ridiculous so there are lots of edge cases I wouldn't know how to automate yet. We can just continue to create them by hand as needed until we have enough coverage/confidence to know how we'd generate wrappers.

Thanks

The original objc and variadic packages were written by Mikkel Krautz. The variadic package is some assembly magic to make everything possible since libobjc relies heavily on variadic function calls, which aren't possible out of the box in Cgo.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].