Кіріспе
Mac OS-дегі хабарламаларға негізделген процестер аралық байланыс механизмі Apple-дің бағдарламалық хабар алмасу жүйесі болып табылады. Apple оқиғалары – Mac OS-дегі хабарламаларға негізделген процестер аралық байланыс механизмі, ол алғаш рет System 7-де пайда болды және содан бері классикалық Mac OS-тің барлық нұсқаларында және macOS-та қолдау табады. Apple оқиғалары "ашық құжатты ашу" немесе "файлды басып шығару" сияқты "жоғары деңгейдегі" оқиғаларды сипаттайды, ал бұрынғы операциялық жүйелер "түрту" және "перне басу" сияқты әлдеқайда қарапайым оқиғаларды қолдаған. Apple оқиғалары Mac OS скрипт жүйесінің, Open Scripting Architecture (оның негізгі тілі AppleScript) негізін құрайды. Бастапқы нүкте – динамикалық түрде терілген, кеңейтілетін AEDesc деп аталатын дескриптор форматы, ол дерек типін анықтайтын OSType кодынан және типке тәуелді деректер блогынан тұрады. Мысалы, OSType inte коды деректің үлкен ендиан форматындағы төрт байттық бүтін сан екенін көрсетеді. Әртүрлі қарапайым типтер үшін алдын ала анықталған типтік кодтардан басқа, екі алдын ала анықталған құрылымдық дескриптор типі бар: дерек типі reco (жазба) болатын AERecord және тізім типімен (тізім немесе массив) AEList. Олардың ішкі құрылымында рекурсивті түрде тізілген AEDesc-тер бар, ал AERecord әр элементті бірегей жазба өрісі идентификаторымен (OSType) байланыстырады. Apple Event Manager осы құрылымдарды құруға, сондай-ақ олардың мазмұнын алуға және мазмұнының типін сұрауға арналған API шақыруларын ұсынады. Apple Event Manager сонымен қатар AEDesc-ті бір дерек типінен екіншісіне түрлендіретін мәжбүрлеуді (coercion) қолдайды. Стандартты мәжбүрлеулерден басқа, мысалы, бүтін сан мен нақты сан арасында, қолданбалар өздерінің мәжбүрлеуді басқарушы кері шақыруларын орната алады, олар арнайы дерек типтеріне және одан түрлендірулерді басқарады. Apple оқиғасы – бұл оқиғаның мақсатына байланысты өрістері бар AERecord. Сонымен қатар, ол Apple Event Manager-де алдын ала анықталған жиынтықтан атрибуттарды (қазір оқиғаның параметрлері деп аталатын жазба өрістерінен ерекшеленеді) қамтиды. Бұл оқиғаның не істеу керектігін (оқиға класы мен оқиға идентификаторы арқылы), оқиға жіберілетін мақсатты мекенжайды (жергілікті немесе қашықтағы машинадағы процесс болуы мүмкін) және оны өңдеудің басқа да әртүрлі опцияларын анықтайды. Қашықтағы машиналар бастапқыда AppleTalk арқылы қосылуы керек еді, бірақ Mac OS 9 TCP/IP арқылы қосылу опциясын қосты. Apple оқиғасын мақсатты процесске жібергеннен кейін, жіберу процесі Apple оқиғасына жауап алуға таңдай алады. Бұл бастапқы оқиғаның өңделуі туралы мақсаттан қайтарылған әртүрлі ақпараттарды, соның ішінде сәттілік/сәтсіздікті көрсететін қате кодын, бастапқы оқиға сұраған кез келген ақпаратты және/немесе басқа да тиісті ақпаратты қамтуы мүмкін. Apple оқиғалары AppleEvent Object Model негізін құрайды, ол өз кезегінде OSA және AppleScript негізін құрайды. 2016 жылдан бастап Apple Event Manager API-нің ресми іске асырылуы C және оның ұрпақтары, соның ішінде C++ тілінде қол жетімді. Сонымен қатар, Cocoa API арқылы Objective-C және Swift үшін ресми байланыстар ұсынылады. Басқа тілдер үшін де бейресми байланыстар бар (шектеулердің әртүрлі деңгейімен), соның ішінде Perl, UserTalk, Ruby және Python.
Apple's software messaging system
Apple events are the message based interprocess communication mechanism in Mac OS, first making an appearance in System 7 and supported by every version of the classic Mac OS since then and by macOS. Apple events describe "high level" events such as "open document" or "print file", whereas earlier OSs had supported much more basic events, namely "click" and "keypress". Apple events form the basis of the Mac OS scripting system, the Open Scripting Architecture (the primary language of such being AppleScript). The starting point is a dynamically typed, extensible descriptor format called an AEDesc, which is just an OSType code specifying the data type, together with a block of type dependent data. For instance, the OSType code inte indicates that the data was a four byte signed integer in big endian format. Besides predefined type codes for various common simple types, there are two predefined structured descriptor types: an AERecord, which has data type reco (record), and AEList with type list (list or array). The internal structure of these contain recursively nested AEDescs, while the AERecord also associates each element with a unique record field ID, which is an OSType. The Apple Event Manager provides API calls to construct these structures, as well as extract their contents and query the type of contents they hold. The Apple Event Manager also supports coercions, which converts AEDescs from one data type to another. In addition to standard coercions, for instance between integer and real types, applications can install their own coercion handler callbacks, which handle conversions to and from custom data types. An Apple event proper is an AERecord with fields that depended on the purpose of the event. In addition, it has attributes (which are distinct from record fields, which are now called the parameters of the event) from a set predefined by the Apple Event Manager. These specify what the event is supposed to do (through event class and event ID), the target address to which the event is to be sent (which could be a process on the local or a remote machine), and various other options for handling it. Remote machines initially had to be connected via AppleTalk, but Mac OS 9 added the option for connections via TCP/IP. After sending an Apple event to its target process, the sending process can elect to receive a reply to an Apple event. This can contain various bits of information returned from the target about the processing of the original event, including an error code indicating success/failure, any information requested by the original event, and/or other appropriate information. Apple events are the foundation of the AppleEvent Object Model, which in turn is the foundation of the OSA and AppleScript. as of 2016, the official implementation of the Apple Event Manager API is available in C and its descendants, including C++. Official bindings are also provided for Objective C and Swift through the Cocoa API. Unofficial bindings also exist for other languages (with varying degrees of limitation), including Perl, UserTalk, Ruby and Python.
Скриптті жасау көпірі
Scripting Bridge — macOS фреймворкі, ол қолданбаларға AppleScript сияқты делдалдық скрипт тілін қолданбай бір-бірімен байланысуға мүмкіндік береді. AppleScript сияқты, Scripting Bridge де қолданбалар арасындағы байланыс үшін Apple оқиғаларын пайдаланады. Scripting Bridge көбінесе Objective-C және PyObjC-ден қолданылады.