Photograph via snooOG

This sub is obsolete, please use /r/macosprogramming/ instead.


3,097 Subscribers


Install HomeBrew from OS X application

My application requires nmap which can only be installed using brew. How do I make sure my OS X app installs these packages before running my app? Should I use sandboxing to test it?

15:31 UTC


My mac application doesn't work on other mac's

I created a mac cocoa application written in swift when i run it in my mac it works but when i build it for release mode and then run the application on other mac's where the UI is supposed to be is just a blank window. I used xcode to build it and it's deployment target was set to 10.10 the mac i checked it on had 10.10.5 and it didn't work.

does anyone what's going wrong or if there's any way for me to check why it's behaving like that. I'd be grateful for any help thanks.

The os version on my mac is 10.13.

08:27 UTC


How is macOS "Word of the Day" screensaver built?


I'm trying to build a macOS screensaver that has animations similar to the "Word of the Day" built-in screensaver, namely that there's a background gradient and text floating across the screen. I'm fairly experienced with SpriteKit and UIKit (but a total newbie to AppKit), and I've built one screensaver with SpriteKit before successfully, but I figured I would try to build this one using only things available to the ScreenSaver framework and I'm having some trouble.

I found a guide over here that suggests just using the built in `draw()` and `animateOneFrame()` methods to draw the background and moving objects in every frame, but I can already tell that performance of drawing the NSGradient in every frame is very poor at high resolutions, and animations appears to be choppy and inconsistent due to the fluctuating frame rate.

I could just 'give up' and build the screensaver in SpriteKit to get the fluid animation I want, but I assume that the built-in "Word of the Day" screensaver is not using SpriteKit and I am wondering how they got such silky-smooth animations at any resolution if not.

Can anyone shed some insight on this?

01:32 UTC


USB Driver tutorial

Hey everyone, I got an LED light strip that plugs in via usb. It's meant to be used for a TV but I am curious to see if I can write a driver to control it from within a Mac app. Are there any good resources for that kind of thing? i couldn't find much info. And it looks like apple wants me to get some entitlement to write drivers when really i just wanna mess with hardware on my own machine.

21:33 UTC


How to detect if NSWindow is dragged?

Hey all, I am using SwiftUI. I have a view called SideBar, that's consisting of VStack and buttons inside it.

I tried to attach some gestures, such as DragGesture() and TapGesture() onended on the VStack, hoping it would detect when a user drags the view, but this doesn't work all the time and I also think this is super hackish. Would anyone be able to help? Thanks a lot.


VStack{blabla}.frame(width: 40, height: 320)



TapGesture().onEnded{_ in

print("end click")




DragGesture().onEnded{_ in

print("end drag")



1 Comment
11:02 UTC


HBO Westworld canonizes AppKit

07:33 UTC


Updating Perian project to Catalina

Hello, unfortunately I'm not a programmer, I tried building the Perian project (https://github.com/MaddTheSane/perian) on macOS Catalina but I really can't manage to make it through, even after cloning all the right git repositories and updating the Xcode project configuration.

Since it's definitely a useful project I would like to ask if anybody with more knowledge about macOS programming than me could take over the effort of updating the project to the latest versions of ffmpeg and libmatroska and port the whole project to Catalina.

Thanks :)

12:50 UTC


Learning partner wanted

Hi there! I’m Tommaso a designer and web developer with the dream of building amazing iOS and especially macOS products.

I’m looking for someone who is at the beginning of his/her macOS/iOS journey with my same dream and who is willing to join me for learning, experimenting and building cool stuffs together.

I’m an absolute beginner in this field but I’m full of determination trust me.

If you are interested write me a DM. Thanks!

22:21 UTC


What am I doing wrong with NSTableView? (Swift, Story Board)

I boiled my problem down the following screenshot. I've for a ViewController.swift, it inherits the NSTableViewDataSource and NSTableViewDelegate. In the story board, I clicked on Identity and Type and set the Custom Class to the ViewController (inside ViewController.swift). viewDidLoad() runs, but numberOfRows(in:) never runs. I kind of expected it to produce a bunch of rows (123 of them, in my case) that look like the table cell prototype.


20:33 UTC


How to have a window (view) on mac os to always be on top and also opens on every other desktop (SwiftUI MACOS)

I have a view called sidebar. The idea is to have this view always on top no matter what, whether the user is currently on fullscreen of a different app or different desktop.

I have successfully achieved the always on top on the same desktop when the app got opened, but not when it's on another app's fullscreen. This is my code:

var sidebarWindow:NSWindow

let window = NSRect(x: 0, y: 0, width: 0, height: 0)

sidebarWindow = NSWindow(

contentRect: window,

styleMask: [.titled,.miniaturizable],

backing: .buffered, defer: false)


sidebarWindow.level = .floating



if let myScreen = NSScreen.main {

let windowFrame = myScreen.frame

let h = windowFrame.size.height

let w = windowFrame.size.width

sidebarWindow.setFrameOrigin(NSPoint(x: w-55, y: h/2-180))


sidebarWindow.contentView = NSHostingView(rootView: SideBar(thisWindow: sidebarWindow))

But, as I described above, this `Sidebar()` (sidebarWindow) is not visible when I'm entering other app in full screen, as well as when I'm changing my desktop to other desktop.

How can I make `SideBar()` to always be on top no matter what, whether the user is currently on fullscreen of a different app and or different desktop?

Sorry if it's unclear.

Thanks a lot, any help would be appreciated!

1 Comment
05:19 UTC


What do you think of CodeRunner IDE ?

Any thought about this IDE ?

Looks really nice, actually using the free 14-days version and thinking about buying a licence... But I'm interested in users' opinions first !

22:55 UTC


How to make a macOS Swift app run even when not active?

I am completely new to Swift and macOS app development and trying to make a small macOS Menu Bar app that needs to listen to .mouseMoved events all the time right after the user starts the app.

I have the code like below:

class EventMonitor {
    func mouseMoved(with event: NSEvent) {
        print("mouse moved. x: \(event.absoluteX) y: \(event.absoluteY)")
    init() {
        NSEvent.addLocalMonitorForEvents(matching: .mouseMoved) {
            self.mouseMoved(with: $0)
            return $0

This code works but only when I click the icon on the menu bar, i.e when this app is active. But how do I keep listening to .mouseMoved events even when the app is not active?

Any help/ideas would be really appreciated.

21:02 UTC


Disabled SIP for debug, now I can't attach to anything

I used 'csrutil enable --without debug' and now lldb does not attach to anything. This is reverse of the desired effect. General searches and ADF searches are not giving me anything other than, Use csrutil to enable debugging of system applications. Now I cannot debug anything.

Background: Preview has a long-standing issue of refusing to open files with an incorrect no-permission message after a certain number, volume, time or whatever of files have been opened (you can see the error logged from PVImageContainer initWithURL:). It's fixed by restarting the application, but I'd like to find the source of the problem.

Edit to add: this is what I see

11 > sleep 100 &
[1] 20415

12 > lldb
(lldb) attach 20415
error: attach failed: unable to attach
(lldb) ^D

OK, further edit, I can attach to processes that I own the executable... but the question remains: does 'disabling' SIP still not really let us use the debugger generally (and dtrace etc)?

16:33 UTC


How do I diagnose this memory leak further?

Hi there!

I'm currently investigating a memory leak (CGContext cannot allocate ...) in a small library. I've ran the profiler a bit yesterday and identified ~where it/the leak is happening.

The memory increases every time I enter a certain component and doesn't decrease the same amount when leaving certain component.

What I got from instrumentin the allocations is that VM: CG image alongside VM: CG raster data keeps getting more and more persistent allocations and growing and growing in memory.

Out of the reported 522mb allocations in the app, 499mb are from the two culprits mentioned above and I can't seem to find it's cause :-(. The App doesn't crash in the End, but images are not refreshing anymore and the component won't load anymore when it is at about 1.5gb allocations for those two.

Any tips how to proceed, would be greatly appreciated!

1 Comment
11:37 UTC


How do you run python script with arguments programmatically using swift

I am working on a MacOS project to turn my iOT device on and off. There is only a working python script to do it. I want to run these scripts from my MacOS project which I am writing in Swift

19:06 UTC


How do programmatically create and manage a window without storyboards?

This is a challenge I would like to do -- to see if I can make an app without storyboards, but I don't know where to start. Apple Documentation doesn't help me much.

05:11 UTC


How do developers find a hidden code? ( or not well-documented code)

CompSci student here.

I wanted to make a program that changes the language input programmatically, but I had a lot of trouble finding a related class/library in the Apple Developer documentation.

Later, an experienced dev showed me an open-source project and it was using `TISInputSources` class in its code. When I looked into it, `TISInputSources` was mentioned but with no further explanation or link.

I was finally able to find a file ` HIToolbox/TextInputSources.h` which had sufficient explanations in it. However, the fact that there was no link in the doc leading up to the file throws me off so hard, and I can fathom how devs even find out about these codes.

So dear experienced devs,

how do you go about finding these codes? I'm deeply curious about it.

Thank you!

05:29 UTC


Calling AppKit developers

Trying to reach out to the Mac community and I guess that means making my first Reddit post! As a small introduction for myself I’m Lucas Derraugh and I run AppleProgramming on YouTube and am looking to start up a series focusing on Mac development. It will likely be half interview of an individual and then the other half talking about a code challenge and how you tackled it looking at the code details behind the implementation. My original Twitter post for some context: https://twitter.com/lucasderraugh/status/1233143222110543872?s=21

If you want to promote your app to a pretty decent audience or just want to show off cool code, I think it would be a fun thing to try! You can reach out via email at first name @ last name .com

21:30 UTC


I can't get the client script to connect to the localhost server the TCP connection never happens for some reason. Can anyone help me please?

Greetings ya'll

ok so I wrote a simple client side program that creates a socket using

CFSteamCreatePairWithSocketToHost function

and connects to the server that runs on the local host on port 8080. It creates the socket just fine but it never connects to the server. I wrote the server in C btw. It didn't work and gave me a

kCFErrorDomainCFNetwork error 72000

and the only information that relays is that apparently the TCP connection couldn't be made don't know why though. So i tried to write the client side script in C too and added it to my swift project bridging header and all but it still doesn't connect. It creates the socket just fine but it fails to connect to the server and I have no idea why. Is mac blocking the libraries from making a TCP connection or something? please help me my dudes what do I do? I don't even know what to search for. the only thing I found was this on r/shittyprogramming.

Here's the code I used to connect to the server using swift 4. The server is running on port 8080 on localhost.

class client:NSObject {
      var inputstream = InputStream!
      var outputstream = OutputStream!

      func setupNetworkCom() {
          var readstream = Unmanaged<CFReadStream>?
          var writestream = Unmanaged<CFWriteStream>?

          CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, "localhost" as CFString, 8080, &readstream, &writestream)

          inputstream = readstream!.takeRetainedValue()
          outputstream = writestream!.takeReatainedValue()

          inputstream.schedule(in: .current, forMode: .common)
          outputstream.schedule(in: .current, forMode: .common)


I've also tried changing the local host to which is the IP I specified for the server to run on but it still doesn't work.

05:24 UTC


Enable the internal Xcode 11 debugging menu

19:38 UTC


PDFdocument returns nil

When I run this code in playground in works but when I run it in a macOs NSviewcontroller file, the pdfdocument returns nil. Why is that ? Any ideas ?

var pdfT = PDFDocument(url: URL(fileURLWithPath: locations[file]))

Okay so weird , I figured out the problem, the absolute path being passed had the following characters preceding the absolute path - > file:///

for some reason this is acceptable in playground when initiating a pdf object. But in mac os this doesn't fly , so I wrote a simple function to solve the problem.

func perpareAbsoultePath(path:String) -> String{
var index = 0
var pathPrepared = ""
var upToIndex = 7
for letter in path{
if index >= upToIndex{
    return pathPrepared

function just creates a string minus the preceding characters I mentioned, hahah that was frustrating.

03:46 UTC

Back To Top