progrium/darwinkit

Request: official tutorial

Closed this issue ยท 9 comments

I ask that a tutorial on how to use MacDriver be made please. I'm hoping for a YouTube video and a web page ๐Ÿ˜.

Great idea. Can you be more specific with what you'd like to see?

tmc commented

Iโ€™d love to see a walkthrough of how to add new macOS api coverage. I think the original author is more interested in usage.

@tmc Great idea. That tutorial should be made.

@progrium I would like to see a step by step beginners guide to creating a simple GUI version of a "hello world" like program. This tutorial should instruct the user on how to create and display a window.

I think I should add more detail as to what this tutorial should include:

Introduction: Explain what is MacDriver, Objective-C, and Appkit.

Step:
Setup a new Go project

  • Create a new folder
  • Create a new file called main.go inside the folder

Step:
Setup MacDriver

  • Open Terminal application and cd to the new project's folder.
  • Run these commands in the Terminal:
    go get github.com/progrium/macdriver/cocoa
    go get github.com/progrium/macdriver/core
    go get github.com/progrium/macdriver/objc

Step:
Copy example source code into main.go.

package main

import "github.com/progrium/macdriver/cocoa"
import "github.com/progrium/macdriver/core"
import "github.com/progrium/macdriver/objc"

func main() {

	app := cocoa.NSApp_WithDidLaunch(func(n objc.Object) {
		frame := core.Rect(400, 400, 300, 200)

		win := cocoa.NSWindow_Init(
			frame,
			cocoa.NSTitledWindowMask|
				cocoa.NSClosableWindowMask,
			cocoa.NSBackingStoreBuffered,
			false,
		)
		win.SetTitle("Hello world")
		win.MakeKeyAndOrderFront(nil)
	})
	app.SetActivationPolicy(cocoa.NSApplicationActivationPolicyRegular)
	app.ActivateIgnoringOtherApps(true)
	app.Run()
}

Step:
Run example program.

  • Run this command in Terminal: go run main.go

This is a crash course tutorial for people who are just curious to those who want to start their career in Go.
I am hoping a more detailed tutorial could be made that describes what each line of code does and why it is needed.

Thanks, this is very helpful! I'll see what I can do.

Actually I think this example code is even more minimal and easier to read:

package main

import "github.com/progrium/macdriver/cocoa"
import "github.com/progrium/macdriver/objc"

func main() {

	app := cocoa.NSApp_WithDidLaunch(func(n objc.Object) {
		win := cocoa.NSWindow_New()
		win.SetTitle("Hello world")
		win.MakeKeyAndOrderFront(nil)
	})

	app.SetActivationPolicy(cocoa.NSApplicationActivationPolicyRegular)
	app.ActivateIgnoringOtherApps(true)
	app.Run()
}

@tmc I liked your idea so much that I created its own issue here: #110.

I created a crash course page here: https://github.com/progrium/macdriver/wiki/Crash-Course-in-MacDriver. Let me know what you think.

Great start! I think it's worth mentioning at the end that if Go bindings don't exist yet, you can still often work with most APIs using objc.Get() and calling Send to call methods.