/r/macosprogramming

Photograph via snooOG

Subreddit for macOS developers!

A subreddit for macOS (OS X) developers :)

Related subreddits

/r/iOSProgramming

/r/macosprogramming

1,545 Subscribers

1

Transparent, clickthrough, non-interactive overlays on macos.

import numpy as np
import mss
import time
from ultralytics import YOLO
import tkinter as tk
import Quartz
import AppKit
from PIL import Image, ImageTk

# Load the YOLO model
model = YOLO("yolo11n.pt")

# Screen capture configuration
sct = mss.mss()
monitor = sct.monitors[1]  # Capture primary screen
# Set desired FPS
fps = 30
frame_time = 1 / fps

class TransparentWindow:
    def __init__(self):
        self.root = tk.Tk()
        self.root.overrideredirect(True)  # Remove window borders
        self.root.attributes('-topmost', True)  # Keep the window on top
        self.root.attributes('-alpha', 0.2)  # Completely transparent
        self.root.geometry(f"{monitor['width']}x{monitor['height']}+0+0")

        # Set the window to be click-through
        self.set_click_through()

        # Create a canvas for drawing
        self.canvas = tk.Canvas(self.root, width=monitor['width'], height=monitor['height'], bg='white', highlightthickness=0)
        self.canvas.pack()

        # Launch the window
        self.root.after(100, self.update)
        self.root.mainloop()

    def set_click_through(self):
        # Access the window's NSWindow instance to set it to ignore mouse events
        ns_window = AppKit.NSApp.windows()[0]
        ns_window.setIgnoresMouseEvents_(True)  # Make it ignore mouse events
    def update(self):
        # Capture the screen
        screen = np.array(sct.grab(monitor))
        screen_rgb = screen[..., :3]  # Drop the alpha channel
        # YOLO Inference
        results = model(screen_rgb)
        boxes = results[0].boxes.data.cpu().numpy()

        # Clear previous drawings
        self.canvas.delete("all")

        # Draw bounding boxes on the canvas
        for box in boxes:
            x1, y1, x2, y2, score, class_id = map(int, box[:6])
            self.canvas.create_rectangle(x1, y1, x2, y2, outline='green', width=2)

        # Schedule the next update
        self.root.after(int(frame_time * 1000), self.update)

# Create and launch the transparent window
overlay = TransparentWindow()import numpy as np
import mss
import time
from ultralytics import YOLO
import tkinter as tk
import Quartz
import AppKit
from PIL import Image, ImageTk

# Load the YOLO model
model = YOLO("yolo11n.pt")

# Screen capture configuration
sct = mss.mss()
monitor = sct.monitors[1]  # Capture primary screen
# Set desired FPS
fps = 30
frame_time = 1 / fps

class TransparentWindow:
    def __init__(self):
        self.root = tk.Tk()
        self.root.overrideredirect(True)  # Remove window borders
        self.root.attributes('-topmost', True)  # Keep the window on top
        self.root.attributes('-alpha', 0.2)  # Completely transparent
        self.root.geometry(f"{monitor['width']}x{monitor['height']}+0+0")

        # Set the window to be click-through
        self.set_click_through()

        # Create a canvas for drawing
        self.canvas = tk.Canvas(self.root, width=monitor['width'], height=monitor['height'], bg='white', highlightthickness=0)
        self.canvas.pack()

        # Launch the window
        self.root.after(100, self.update)
        self.root.mainloop()

    def set_click_through(self):
        # Access the window's NSWindow instance to set it to ignore mouse events
        ns_window = AppKit.NSApp.windows()[0]
        ns_window.setIgnoresMouseEvents_(True)  # Make it ignore mouse events
    def update(self):
        # Capture the screen
        screen = np.array(sct.grab(monitor))
        screen_rgb = screen[..., :3]  # Drop the alpha channel
        # YOLO Inference
        results = model(screen_rgb)
        boxes = results[0].boxes.data.cpu().numpy()

        # Clear previous drawings
        self.canvas.delete("all")

        # Draw bounding boxes on the canvas
        for box in boxes:
            x1, y1, x2, y2, score, class_id = map(int, box[:6])
            self.canvas.create_rectangle(x1, y1, x2, y2, outline='green', width=2)

        # Schedule the next update
        self.root.after(int(frame_time * 1000), self.update)

# Create and launch the transparent window
overlay = TransparentWindow()

Working on a project to identify objects on screen, and put boxes around them. Using an overlay. Here is my code... The window is clickthrough right now and everything, however i cant find a way to make it fully transparent.

0 Comments
2024/10/27
07:41 UTC

1

Mission Control - Assign Hotkeys to Spaces?

Not sure if there's a way to do this, but I bounce between spaces frequently, and the latency while switching is annoying. Can I assign a hotkey to each space to facilitate faster switching?

0 Comments
2024/10/26
18:00 UTC

1

Access Reminders Data

Where, and how, exactly is my reminders data stored? I'm trying to rig up an interface between Emacs Org Mode and Reminders (and eventually Notes and Calendar). I thought there'd by a reminders.db file somewhere or something, but just the file hierarchy is pretty confusing.

2 Comments
2024/10/22
19:39 UTC

2

[macOS] Intermittent App Package Installation Failure

I work on a macOS application that functions as a daemon. To test it, I:

  1. Compile executables.

  2. Use pkgbuild and productbuild to build an application bundle.

  3. Use codesign and notarytool to sign and notarize the app.

  4. Install the app with /usr/sbin/installer -target LocalSystem -pkg .... This often overwrites the previous version of the app.

Sometimes, the installation fails at the postinstall stage, when it can not find the application's install directory. We explicitly check for this error in our script:

if ! [ -d "$APP_INSTALL_DIR"/Contents ]; then
    echo "directory ${APP_INSTALL_DIR}/Contents is missing"
    exit 1
fi

This is unexpected!

Even worse, some of our customers have occasionally seen the same issue!

We use a postinstall script in order to install files into the /Library/LaunchDaemons and /Library/LaunchAgents directories, and start the agent with launchctl bootstrap.

Our preinstall script makes sure that the previous version of our application is fully uninstalled (so there is no confusion), and we wonder if that is part of the problem.

While researching this error, I ran across a discussion of a similar issue on Stackoverflow: <https:// stackoverflow.com/questions/19283889>. One of the commenters there wrote:

It appears that the OS X installer uses information about already installed packages and application bundles in order to decide where and if to install new packages. As a result, sometimes my installer did not install any files whatsoever, and sometimes it just overwrote the .app bundle in my build tree. Not necessarily the one used to build the installer, but any .app bundle that OS X had found. In order to get the installer to install the files properly I had to do two things:

  1. Tell OS X to forget about the installed package. sudo pkgutil --forget <package id> Not sure if this is needed for you nor in my case, but it is probably a good idea anyway.

  2. Delete all existing .app bundles for the app. If I didn't do this, the existing app bundle was overwritten on install instead of the app being placed in /Applications. Maybe there is a way to prevent this while building the installer package, but I haven't found it.

On the other hand, the man page for pkgutil says not to use --forget from an installer:

Discard all receipt data about package-id, but do not touch the installed files. DO NOT use this command from an installer package script to fix broken package design.

What is the correct approach to fix this problem?

((I submitted this question on the Apple forums, but got no response: https://developer.apple.com/forums/thread/759046.))

0 Comments
2024/10/03
12:51 UTC

1

Overwrite MacOS Timezone Using a Custom Safari Extension?

0 Comments
2024/09/30
15:02 UTC

2

Crash Reporting?

What's the current recommendation for macOS (and iOS) crash reporting services nowadays? We used to pay HockeyApp for this, then it got bought by Microsoft, and now its scheduled for shutdown soon. Where should we move?

3 Comments
2024/08/14
04:16 UTC

2

Email API or library?

Does anyone know if there are any libraries that provide access to the email app data!

0 Comments
2024/08/06
05:27 UTC

9

Hello I would like to announce a container-like solution for macOS which doesn't require sip to be disabled.

I’m excited to share a project I’ve been working on called osxiec (osx isolated environment creator). While it’s not a full container solution, osxiec provides a way to isolate processes from the main system on macOS.

Here are some key features:

  • Process isolation using groups and macOS volumes
  • Network isolation
  • Soft and hard memory limits
  • CPU priority management
  • Sandbox isolation

Unlike existing solutions like "darwin containers," osxiec doesn’t require System Integrity Protection (SIP) to be disabled. It's designed to be an easy-to-use tool for testing code, isolating applications, and integrating with your development workflows on macOS.

I’d love to get feedback from the community. Any suggestions or concerns are welcome!

https://github.com/Okerew/osxiec

2 Comments
2024/08/05
18:54 UTC

3

What are the best programming languages to create Windows and MacOS app (same codebase) (multi-platform)?

9 Comments
2024/08/03
07:44 UTC

1

Audio Share

Hello, we are working on building a software to record audio and screens but have run into an issue. Everytime we record the screen, audio stops getting recorded. In contrast, it works perfectly in Windows. Does anyone have any suggestion on what could be the issue here?

1 Comment
2024/07/25
00:06 UTC

0

How to have my own macOS apps for my private use without paying anything? Are cracks also made with the Apple Development Program accounts?

It must be a dumb question to most people here - sorry about it! I've been using macOS since 3 years ago very lightly and now I'm trying to use mac more actively thinking maybe it could become my main working machine replacing Windows.

Just yesterday I started coding Swift on Xcode to create something useful for myself as I usually do it with AutoHotKey on Windows. And it seems I need to enroll in the Apple Development Program. Is it correct even if it's only for myself and not for distributing? Then all the macOS programs that you can download on the Internet were made with Apple Development Program accounts? Even cracks?

At least there is a debug app from the Swift project in like ~/Library/Developer/Xcode/DerivedData/GlobalHotkeys3-bdyffbtmfedmnmbhtthegawzlhbw/Build/Products/Debug/GlobalHotkeys3.app

So I'm using it for now. Any tips please!

2 Comments
2024/07/22
00:44 UTC

4

Run in background?

9 Comments
2024/07/20
01:44 UTC

6

How to ensure an app will use the performance cores on Apple Silicon?

We've noticed on an M1 Max laptop, the app (which should use as many cores as possible) is being confined solely to the two efficiency cores, no matter how much load we throw at it. What could be causing this? The computer is plugged in and set to "high power" mode in the system settings, energy pane.

Other than marking DispatchQueue priority as .userInitiated or similar, is there anything else (like a system entitlement?) to ensure that the whole CPU is maximized?

Thanks.

0 Comments
2024/07/17
18:18 UTC

1

I can release on the App Store but have to wait for using Test Flight 😅 (it's the same build)

0 Comments
2024/07/10
16:37 UTC

1

The black screen only appears when my app is first installed.

I developed a macos application with Flutter and created a deployable file with a developer ID certificate and Xcode. I compressed it into a dmg and passed it through internal tests. When I did this, I got something like the title. Even after shutting down and running it again, I never get the black screen again.

Interestingly, uninstalling and reinstalling the app also doesn't cause the black screen. So I wanted to see if there was an issue with authenticating the apple account, so I brought my personal macbook, which uses the same apple account as my work macbook, and experimented with it, and again, after the first install, I only got the black screen.

It doesn't seem to be a code signing or notarisation issue. Because if I get the black screen in the first place and shut it down, there is no problem after that.

I don't have a clue how to reproduce this as the only way to do so is the first installation on the first device, so if anyone has experienced something similar, or knows anything about this issue, please help.

0 Comments
2024/07/10
07:36 UTC

7

[article] Fixing the code signing and notarization issues of Unreal Engine (5.3+) projects

I wrote an article about my long journey in the packaging, code signing, and notarization process of an Unreal Engine macOS application.

I found several problems in the recently introduced modernized Xcode workflow, and a bug in the implementation of CEF as a macOS framework.

All the detailed information is in the article - that's quite long so I added a TL;DR section for the ones only looking for the solution.

I hope the article can help other developers and save them all the weeks I had to spend on this.

https://pgaleone.eu/unrealengine/macos/2024/07/06/codesigning-notarization-issues/

1 Comment
2024/07/06
16:53 UTC

3

Example of using CoreLocation on macOS

I'm trying to put together a minimal example of a program that can use the CoreLocation api on macOS.

I know that I need to add usage description keys the Info.plist, so I'm compiling in a plist file.

Here is the code I'm using now, complete with a Makefile.

When I execute the program, I just get the error message:

CLLocationManager error: The operation couldn’t be completed. (kCLErrorDomain error 1.)

What am I missing? Is the codesign step neccesary? Do I need to notarize it (and how do I notarize a single executable)?

4 Comments
2024/07/06
13:58 UTC

1

App Group Not working as intended after updating to macOS 15 beta.

I have an app (currently not released on App Store) which runs on both iOS and macOS. The app has widgets for both iOS and macOS which uses user preference (set in app) into account while showing data. Before upgrading to macOS 15 (until Sonoma) widgets were working fine and app was launching correctly, but after upgrading to macOS 15 Sequoia, every time I launch the app it give popup saying '“Kontest” would like to access data from other apps. Keeping app data separate makes it easier to manage your privacy and security.' and also widgets do not get user preferences and throw the same type of error on Console application when using logging. My App group for both iOS and macOS is 'group.com.xxxxxx.yyyyy'. I am calling it as 'UserDefaults(suiteName: Constants.userDefaultsGroupID)!.bool(forKey: "shouldFetchAllEventsFromCalendar")'. Can anyone tell, what am I doing wrong here?

2 Comments
2024/06/29
16:47 UTC

1

change loginscreen language with terminal

Hey there,

recently I tried to perform system language change for a user by using a shell (bash) script combined with osascript.
Now I can change my systemlanguage from a menu (osascript generated).

Now my problem comes in:

I can programmically change the language and region of macos by using the terminal. But I have not found a way to do this also for the "Login Window".
So my system is completly in english but my loginwindow stays in german.
Until I do this manually in the system settings -> General -> Language & Region -> Cogwheel -> Apply to Login Window.

So is there a way to also set this using commandline or osascript.

Thanks you in advance!

2 Comments
2024/06/27
10:43 UTC

2

Different Apple ID for Xcode vs OS

I am transitioning from a career in Architecture and Windows programming (mostly PowerShell) to Canine Behavior and MacOS/iOS programming, and I have a question about Apple IDs as it relates to an Apple Developer Account.

I have an Apple ID based on an old company name. I was forced to change the name of my company because, well, Autodesk kinda sucks. Anyway, prior to creating a Dev account, I wonder if it makes sense to create a new Apple ID? Can I use the old, now "personal" Apple ID for iCloud and app purchases and books and such, and the new Apple ID can be used only within Xcode? Or is Xcode aware of the Apple ID in use by the underlying OS and they need to be the same?

2 Comments
2024/06/26
14:56 UTC

1

Multiple Terminal windows

Whenever I open Terminal, previous instances of the Terminal windows open along with the new window.

0 Comments
2024/06/23
18:04 UTC

2

When transforming a .app to .pkg, the installer replace the first instance of my app it found

When transforming a .app to .pkg, the installer replaced the first instance of my app it found (.app) with the updated version and it only instal the app in /Applications if no other versions are present in the system.

I just want my installer to install the app in /Applications, not look for other versions already installed

I don't understand why I get this weird behavior...

here is what I use to convert my .app to .pkg:

xcrun productbuild --sign "Developer ID Installer" --component ./MyApp.app /Applications/ ./MyApp.pkg

0 Comments
2024/06/10
22:09 UTC

6

Creating my own mac app

Complete newbie here. I want to create my own note taking app. Something like a cross between evernote and notion. A place to dump thoughts and tasks and references.

I'm very fussy so no existing app really ticks all of the boxes for me whether it be because of price or privacy concerns.

I've done a bit of very basic coding in the past - COBOL (don't laugh), C++ and er, well, that's it :-) But I like learning.

How realistic is it to build my own app to run on my own mac? Perhaps sync it between all of my macs? Perhaps even have an ios version so I can have it on my phone? I'm ok with learning new skills and I'm not looking to create something commercially viable. It's just for my own needs.

Am I dreaming? If not, what would be the best language / platform to learn? Swift? OR something else?

Thanks in advance for any helps, tips, comments.

3 Comments
2024/06/10
17:37 UTC

1

Instant sandbox environment

Posting this here out of curiousity - i have very little programming experience. Would it be possible to create a sandboxed environment shortcut? As in something to safely open unknown files or mount external volumes in said environment?

I can think of two important uses that can help a lot of people:

  • Open .zip files, .rar files and such - in a protected environment to inspect its contents.
  • Mounting SD cards and external volumes in this sandboxed environment to protect against infected files on said volumes.
  • Perhaps many more uses... - including now that i think of it, being able to run a simple program, that would not otherwise be allowed on the main system if it was restricted.

It would function as a window that would open through a right click menu shortcut, kind of like winebottler, where only a certain part of a macos environment is needed.

Thank you, let me know if im retarded

1 Comment
2024/06/09
09:14 UTC

1

Inspect accessibility tree of apps?

Hello. I want to make an app that will manipulate other apps, but for that I need to know the structure of the app's accessibility tree. How can I inspect this? I am a blind developer, I tried operating xCode's accessibility inspector but I cannot work it out withou a mouse.

2 Comments
2024/06/08
18:17 UTC

Back To Top