Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4060190
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:18:23+00:00 2026-05-20T15:18:23+00:00

I am using pyobjc to add some needed OSX functionality to some random python

  • 0

I am using pyobjc to add some needed OSX functionality to some random python software. I will need to access API-defined objc-land constants from python-land.

An example of such constants lies far down in the NSRunningApplication page, specifically the three possible values of NSApplicationActivationPolicy.

For context, the current task at hand is listing currently running, user-facing applications. To this end, the following code works just fine:

from Foundation import *
from Cocoa import *
import objc

for runningApp in sorted(
                     NSWorkspace.sharedWorkspace().runningApplications(),
                     key=lambda x: x.localizedName()
                  ):
    if runningApp.activationPolicy() == 0:
        # Do stuff

But I’d rather not check against zero (to make it more readable) nor hardcode a dummy NSApplicationActivationPolicyRegular value to zero in my own code when it’s readily available in the original library.

How can I access such objc constants from python through pyobjc?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T15:18:24+00:00Added an answer on May 20, 2026 at 3:18 pm

    The Apple-supplied PyObjC predates some of the additions that were made to Cocoa in 10.6. NSRunningApplication is one of these additions, and so PyObjC doesn’t know about it. You need to add some metadata to the AppKit BridgeSupport file at: /System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/PyObjC/AppKit/PyObjC.bridgesupport

    These three lines will cover the enum you’re trying to use.

    <enum name='NSApplicationActivationPolicyRegular' value='0' />
    <enum name='NSApplicationActivationPolicyAccessory' value='1' />
    <enum name='NSApplicationActivationPolicyProhibited' value='2' /> 
    

    Note that changing PyObjC like this probably means you’ll have to statically link and include your updated version into your app for distribution, because the version on everyone else’s machine won’t have this data. It might be best to compile the newest version of PyObjC (which will contain these changes plus others) and use that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm already recording from my iSight from a python script using the pyobjc bridge
I have a plugin written entirely in Python using PyObjC whose core classes I
I need to access the elapsed time since startup in nanoseconds from a Python
I'm trying to overlay an image with some text using PyObjC, while striving to
I'm trying to install pyobjc (using pyobjc-1.2-python2.3-macosx10.2.dmg) on a Mac running OSX 10.6 and
I'm using Python 2 with Tkinter and PyObjC , and then I'm using py2app
Using PyObjC , you can use Python to write Cocoa applications for OS X.
I have a program that uses OpenGL combined with Cocoa and Python using PyObjC.
Using PyObjC, is it possible to import a Python module, call a function and
using this http://bl.ocks.org/950642 we can see how to add images to nodes, the question

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.