Sunday, May 9, 2021

#1 2021-04-11 01:13:16 am

Fredrik71
Member
Registered: 2019-10-23
Posts: 703

PyObjC module objc getClassList

In PyObjC there is a module called objc
https://pyobjc.readthedocs.io/en/latest … -objc.html

If you scroll down from the page (link above) you will find the topic Accessing classes and protocols

The script use getClassList from objc module and return AppleScript record.

Ps. The script could maybe we done faster, any person are welcome to improve.

PyObjC 7.1 26116 classes

Applescript:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

-- PyObjC 7.1 26116 classes
set theScript to "
import Accounts
import AddressBook
import AdSupport
import AppleScriptKit
import AppleScriptObjC
import ApplicationServices
import Automator
import AVFoundation
import AVKit
import BusinessChat
import CalendarStore
import CFNetwork
import CloudKit
import Cocoa
import Collaboration
import ColorSync
import Contacts
import ContactsUI
import CoreAudio
import CoreAudioKit
import CoreBluetooth
import CoreData
import CoreLocation
import CoreMedia
import CoreMediaIO
import CoreMIDI
import CoreML
import CoreServices
import CoreSpotlight
import CoreText
import CoreWLAN
import CryptoTokenKit
import DictionaryServices
import DiscRecording
import DiscRecordingUI
import DiskArbitration
import DVDPlayback
import EventKit
import ExceptionHandling
import ExternalAccessory
import FinderSync
import FSEvents
import GameCenter
import GameController
import GameKit
import GameplayKit
import ImageCaptureCore
import IMServicePlugIn
import InputMethodKit
import InstallerPlugins
import InstantMessage
import Intents
import IOSurface
import iTunesLibrary
import LatentSemanticMapping
import LaunchServices
import libdispatch
import LocalAuthentication
import MapKit
import MediaAccessibility
import MediaLibrary
import MediaPlayer
import MediaToolbox
import Metal
import MetalKit
import MetalPerformanceShaders
import ModelIO
import MultipeerConnectivity
import NaturalLanguage
import NetFS
import Network
import NetworkExtension
import NotificationCenter
import OpenDirectory
import OSAKit
import Photos
import PhotosUI
import PreferencePanes
import PrintCore
import PubSub
import Quartz
import SafariServices
import SceneKit
import ScreenSaver
import ScriptingBridge
import SearchKit
import Security
import SecurityFoundation
import SecurityInterface
import ServiceManagement
import Social
import SpriteKit
import StoreKit
import SyncServices
import SystemConfiguration
import UserNotifications
import VideoSubscriberAccount
import VideoToolbox
import Vision
import WebKit
import objc

print(objc.getClassList())
"


set theClassList to do shell script "/usr/local/bin/python3 <<EOF" & theScript & "EOF"
-- return theClassList

set theASList to {}
set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {","}
set theASList to every text item of theClassList
set AppleScript's text item delimiters to ASTID
-- return theASList

set theList to {}
repeat with i from 1 to (count theASList)
   set theItem to word 5 of (item i of theASList)
   set the end of theList to theItem
end repeat
-- return theList

set anArray to current application's NSArray's arrayWithArray:theList
set theSortList to (anArray's sortedArrayUsingSelector:"compare:") as list

return {objectiveCClass:theSortList}

This script below have run against PyObjC 5.3 in Python version 2.7.17 (PyObjC 5.3 26118 classes)

Applescript:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

-- PyObjC 5.3 26118 classes
set theScript to "
import Accounts
import AddressBook
import AdSupport
import AppKit
import AppleScriptKit
import AppleScriptObjC
import ApplicationServices
import Automator
import AVFoundation
import AVKit
import BusinessChat
import CalendarStore
import CFNetwork
import CFOpenDirectory
import CloudKit
import Cocoa
import Collaboration
import ColorSync
import Contacts
import ContactsUI
import CoreAudio
import CoreAudioKit
import CoreBluetooth
import CoreData
import CoreFoundation
import CoreLocation
import CoreMedia
import CoreMediaIO
import CoreML
import CoreServices
import CoreSpotlight
import CoreText
import CoreWLAN
import CryptoTokenKit
import DictionaryServices
import DiscRecording
import DiscRecordingUI
import DiskArbitration
import DVDPlayback
import EventKit
import ExceptionHandling
import ExternalAccessory
import FinderSync
import Foundation
import FSEvents
import GameCenter
import GameController
import GameKit
import GameplayKit
import HIServices
import ImageCaptureCore
import IMServicePlugIn
import InputMethodKit
import InstallerPlugins
import InstantMessage
import Intents
import IOSurface
import iTunesLibrary
import JavaScriptCore
import LatentSemanticMapping
import LaunchServices
import libdispatch
import LocalAuthentication
import MapKit
import MediaAccessibility
import MediaLibrary
import MediaPlayer
import MediaToolbox
import ModelIO
import MultipeerConnectivity
import NaturalLanguage
import NetFS
import Network
import NetworkExtension
import NotificationCenter
import OpenDirectory
import OSAKit
import Photos
import PhotosUI
import PreferencePanes
import PrintCore
import PubSub
import QTKit
import Quartz
import SafariServices
import SceneKit
import ScreenSaver
import ScriptingBridge
import SearchKit
import Security
import SecurityFoundation
import SecurityInterface
import ServiceManagement
import Social
import SpriteKit
import StoreKit
import SyncServices
import SystemConfiguration
import UserNotifications
import VideoSubscriberAccount
import VideoToolbox
import Vision
import WebKit
import objc

print(objc.getClassList())
"


set theClassList to do shell script "/usr/local/bin/python2 <<EOF" & theScript & "EOF"
-- return theClassList

set theASList to {}
set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {","}
set theASList to every text item of theClassList
set AppleScript's text item delimiters to ASTID
-- return theASList

set theList to {}
repeat with i from 1 to (count theASList)
   set theItem to word 5 of (item i of theASList)
   set the end of theList to theItem
end repeat
-- return theList

set anArray to current application's NSArray's arrayWithArray:theList
set theSortList to (anArray's sortedArrayUsingSelector:"compare:") as list

return {objectiveCClass:theSortList}

And if we like to know how many of this classes begins with NS we use NSPredicate to filter.

Applescript:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

-- PyObjC 7.1 26116 classes
set theScript to "
import Accounts
import AddressBook
import AdSupport
import AppleScriptKit
import AppleScriptObjC
import ApplicationServices
import Automator
import AVFoundation
import AVKit
import BusinessChat
import CalendarStore
import CFNetwork
import CloudKit
import Cocoa
import Collaboration
import ColorSync
import Contacts
import ContactsUI
import CoreAudio
import CoreAudioKit
import CoreBluetooth
import CoreData
import CoreLocation
import CoreMedia
import CoreMediaIO
import CoreMIDI
import CoreML
import CoreServices
import CoreSpotlight
import CoreText
import CoreWLAN
import CryptoTokenKit
import DictionaryServices
import DiscRecording
import DiscRecordingUI
import DiskArbitration
import DVDPlayback
import EventKit
import ExceptionHandling
import ExternalAccessory
import FinderSync
import FSEvents
import GameCenter
import GameController
import GameKit
import GameplayKit
import ImageCaptureCore
import IMServicePlugIn
import InputMethodKit
import InstallerPlugins
import InstantMessage
import Intents
import IOSurface
import iTunesLibrary
import LatentSemanticMapping
import LaunchServices
import libdispatch
import LocalAuthentication
import MapKit
import MediaAccessibility
import MediaLibrary
import MediaPlayer
import MediaToolbox
import Metal
import MetalKit
import MetalPerformanceShaders
import ModelIO
import MultipeerConnectivity
import NaturalLanguage
import NetFS
import Network
import NetworkExtension
import NotificationCenter
import OpenDirectory
import OSAKit
import Photos
import PhotosUI
import PreferencePanes
import PrintCore
import PubSub
import Quartz
import SafariServices
import SceneKit
import ScreenSaver
import ScriptingBridge
import SearchKit
import Security
import SecurityFoundation
import SecurityInterface
import ServiceManagement
import Social
import SpriteKit
import StoreKit
import SyncServices
import SystemConfiguration
import UserNotifications
import VideoSubscriberAccount
import VideoToolbox
import Vision
import WebKit
import objc

print(objc.getClassList())
"


set theClassList to do shell script "/usr/local/bin/python3 <<EOF" & theScript & "EOF"
-- return theClassList

set theASList to {}
set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {","}
set theASList to every text item of theClassList
set AppleScript's text item delimiters to ASTID
-- return theASList

set theList to {}
repeat with i from 1 to (count theASList)
   set theItem to word 5 of (item i of theASList)
   set the end of theList to theItem
end repeat
-- return theList

set anArray to current application's NSArray's arrayWithArray:theList
set predicate to current application's NSPredicate's predicateWithFormat:"(self beginswith %@)" argumentArray:{"NS"}
set anArray to anArray's filteredArrayUsingPredicate:predicate
set theSortList to (anArray's sortedArrayUsingSelector:"compare:") as list

return {objectiveCClass:theSortList}

Last edited by Fredrik71 (2021-04-11 05:58:25 am)


if you are the expert, who will you call if its not your imagination.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)