Monday, February 22, 2021

Play my slides, please!

Did you ever need to take notes while you watch your slides play, but you don't want to switch back and forth between your Keynote and your text editor? Here you go... Save this to your Mac as main.swift - no other name will work, then run it in a terminal like so:

$ swift main.swift


import Cocoa

var pid = pid_t(-1)

let bid = "com.apple.iWork.Keynote"

for x in NSWorkspace.shared.runningApplications {
    if x.bundleIdentifier == bid {
        pid = x.processIdentifier
        break
    }
}

guard let keynote = NSRunningApplication(processIdentifier: pid) else {
    print("Can't find Keynote")
    exit(-1)
}

let src = CGEventSource(stateID: CGEventSourceStateID.hidSystemState)

let key: UInt16 = 0x79

guard let keydown = CGEvent(keyboardEventSource: src, virtualKey: key, keyDown: true) else {
    fatalError("Can't get keydown")
}

guard let keyup = CGEvent(keyboardEventSource: src, virtualKey: key, keyDown: false) else {
    fatalError("Can't get keydown")
}

while (true) {
    keydown.postToPid(pid)
    usleep(10_000)
    keyup.postToPid(pid)
    usleep(15_000_000)
}

Monday, February 15, 2021

Creating a CloudKit Container

I was working through a CloudKit tutorial and needed to create a container for my app.

I tried clicking the + button to create a CloudKit container from XCode 12 directly, but nothing happened.

So I clicked the CloudKit Dashboard and could see there were no containers.

I tried to create one. I entered iCloud.com.domain.app (reverse URL format) and gave it a name. Then I got an error message in red, "Unable to find a developer."

OK, well I'm logged in as the Account Holder, not as a Developer per sé, but this should work. Kept trying. Nothing.

So I tried something a little crazy: I went to the Certificates, Identifiers & Profiles section of App Store Connect. I created an identifier for the container I was trying to create.

After I did that, I went back to XCode and clicked the plus (+) again. Lo and behold, the container I had specified in the identifier I had created, all of a sudden showed up.

Will this work? Time will tell. But if you're getting the same error trying to create a CloudKit container, maybe this will help.

If so, you can buy me a beer!

😀 🍺