예제 #1
0
def test():
    target = AE.AECreateDesc('sign', 'quil')
    ae = AE.AECreateAppleEvent('aevt', 'oapp', target, -1, 0)
    print unpackevent(ae)
    raw_input(":")
    ae = AE.AECreateAppleEvent('core', 'getd', target, -1, 0)
    obj = Character(2, Word(1, Document(1)))
    print obj
    print repr(obj)
    packevent(ae, {'----': obj})
    params, attrs = unpackevent(ae)
    print params['----']
    raw_input(":")
예제 #2
0
    def newevent(self, code, subcode, parameters = {}, attributes = {}):
        """Create a complete structure for an apple event"""

        event = AE.AECreateAppleEvent(code, subcode, self.target,
                  AppleEvents.kAutoGenerateReturnID, AppleEvents.kAnyTransactionID)
        packevent(event, parameters, attributes)
        return event
예제 #3
0
def mac_show(bundle_id):
    target = AE.AECreateDesc(AppleEvents.typeApplicationBundleID, bundle_id)
    activateEvent = AE.AECreateAppleEvent('misc', 'actv', target,
                                          AppleEvents.kAutoGenerateReturnID,
                                          AppleEvents.kAnyTransactionID)
    activateEvent.AESend(AppleEvents.kAEWaitReply,
                         AppleEvents.kAENormalPriority,
                         AppleEvents.kAEDefaultTimeout)
예제 #4
0
def focuswindow(window):
    """Focuses the provided window"""
    if window is None:
        pass
    actevent = AE.AECreateAppleEvent('misc', 'actv', window,
                                     AppleEvents.kAutoGenerateReturnID,
                                     AppleEvents.kAnyTransactionID)
    actevent.AESend(AppleEvents.kAEWaitReply, AppleEvents.kAENormalPriority,
                    AppleEvents.kAEDefaultTimeout)
def run(command):
    termAddress = AE.AECreateDesc(typeApplicationBundleID,
                                  'com.apple.Terminal')
    theEvent = AE.AECreateAppleEvent(kAECoreSuite, kAEDoScript, termAddress,
                                     kAutoGenerateReturnID, kAnyTransactionID)
    commandDesc = AE.AECreateDesc(typeChar, command)
    theEvent.AEPutParamDesc(kAECommandClass, commandDesc)
    try:
        theEvent.AESend(SEND_MODE, kAENormalPriority, kAEDefaultTimeout)
    except AE.Error as why:
        if why[0] != -600:
            raise
        os.system(START_TERMINAL)
        time.sleep(1)
        theEvent.AESend(SEND_MODE, kAENormalPriority, kAEDefaultTimeout)
예제 #6
0
def run(command):
    """Run a shell command in a new Terminal.app window."""
    termAddress = AE.AECreateDesc(typeApplSignature, TERMINAL_SIG)
    theEvent = AE.AECreateAppleEvent(kAECoreSuite, kAEDoScript, termAddress,
                                     kAutoGenerateReturnID, kAnyTransactionID)
    commandDesc = AE.AECreateDesc(typeChar, command)
    theEvent.AEPutParamDesc(kAECommandClass, commandDesc)

    try:
        theEvent.AESend(SEND_MODE, kAENormalPriority, kAEDefaultTimeout)
    except AE.Error, why:
        if why[0] != -600:  # Terminal.app not yet running
            raise
        os.system(START_TERMINAL)
        time.sleep(1)
        theEvent.AESend(SEND_MODE, kAENormalPriority, kAEDefaultTimeout)
예제 #7
0
    def main(self):
        pool = NSAutoreleasePool.alloc().init()
        NSLog("editing thread started for %s" % self.path)
        NSLog("shell command: %@", EDITOR_COMMAND % {'linenum': self.linenum, 'filename': self.path.replace("'","'\"'\"'")})

        stdin = open('/dev/null','r')
        stdout = open('/dev/null','w')
        subprocess.call(EDITOR_COMMAND % {'linenum': self.linenum, 'filename': self.path.replace("'","'\"'\"'")},
                        shell=True, stdin=stdin, stdout=stdout, stderr=stdout)
        #os.system(EDITOR_COMMAND % {'linenum':self.linenum, 'filename':self.path})

        # Send the "file closed" ODB event.
        if self.odb_app:
            NSLog("sending file closed event to %s, %s" % (self.odb_app, type(self.odb_app)))

            target = AE.AECreateDesc(AppleEvents.typeApplSignature, self.odb_app[::-1])  # For strange endianness reasons, have to reverse this
            event = AE.AECreateAppleEvent(kODBEditorSuite, kAEClosedFile, target, AppleEvents.kAutoGenerateReturnID, AppleEvents.kAnyTransactionID)

            if self.odb_token:
                event.AEPutParamDesc(keySenderToken, pack(self.odb_token, typeWildcard))

            fsr = Carbon.File.FSPathMakeRef(self.path)[0].encode('utf-8')
            event.AEPutParamDesc(AppleEvents.keyDirectObject, pack(fsr))

            event.AESend(AppleEvents.kAENoReply, AppleEvents.kAENormalPriority, AppleEvents.kAEDefaultTimeout)

            #evt_app = NSAppleEventDescriptor.descriptorWithTypeCode_(fourcc(self.odb_app))
            #evt = NSAppleEventDescriptor.appleEventWithEventClass_eventID_targetDescriptor_returnID_transactionID_(fourcc(kODBEditorSuite),
            #                                                                                                       fourcc(kAEClosedFile),
            #                                                                                                       evt_app,
            #                                                                                                       -1, # kAutoGenerateReturnID
            #                                                                                                       0) # kAnyTransactionID
            #if self.odb_token:
            #    evt_tok = NSAppleEventDescriptor.descriptorWithDescriptorType_data_(fourcc('****'), self.odb_token)
            #    evt.setParamDescriptor_forKeyword_(evt_tok, fourcc(keySenderToken))
            #
            #fsr = objc.FSRef.from_pathname(self.path).data
            #evt_path = NSAppleEventDescriptor.descriptorWithDescriptorType_bytes_length_(fourcc('fsrf'),fsr,len(fsr))
            #evt.setParamDescriptor_forKeyword_(evt_path, fourcc('----'))

        NSLog("editing thread finished for %s" % self.path)
        del pool
예제 #8
0
파일: aetools.py 프로젝트: mcyril/ravel-ftn
"""Tools for use in AppleEvent clients and servers.
예제 #9
0
"""