Пример #1
0
def parsefile(paths, style='appscript'):
	if isinstance(paths, basestring):
		paths = [paths]
	aetes = []
	for path in paths:
		f = file(path)
		aetes.append(newdesc(kae.typeAETE, f.read()))
		f.close()
	return parseaetes(aetes, paths[0], style)
Пример #2
0
def parsefile(paths, style='appscript'):
    if isinstance(paths, basestring):
        paths = [paths]
    aetes = []
    for path in paths:
        f = file(path)
        aetes.append(newdesc(kae.typeAETE, f.read()))
        f.close()
    return parseaetes(aetes, paths[0], style)
Пример #3
0
def growlNotify(title, description='', **kw):
    try:
        if usingStereo:
            description += '\n(AirPlay)'

        if 'image' in kw:
            image = (NSImage.alloc().initWithData_(buffer(kw['image']))
                     .TIFFRepresentation())
            kw['image'] = newdesc('TIFF', image)

        growl.notify(
            with_name=NOTIFICATION_TRACK_INFO,
            title=title,
            description=description,
            identifier='StreamVision notification',
            application_name=GROWL_APP_NAME,
            **kw)
    except CommandError:
        growlRegister()
        growlNotify(title, description, **kw)
Пример #4
0
def makeCustomSendProc(addResultFn, isLive):
    def customSendProc(event, modeFlags, timeout):
        # unpack required attributes
        try:
            eventcode, addressdesc = _unpackEventAttributes(event)
            appPath = ae.addressdesctopath(addressdesc)

            # reject events sent to self otherwise they'll block main event loop
            if appPath == NSBundle.mainBundle().bundlePath():
                raise MacOSError(-1708)

            # get app instance and associated data
            if not _appCache.has_key((addressdesc.type, addressdesc.data)):
                if addressdesc.type != kae.typeProcessSerialNumber:
                    raise OSAError(
                        10000,
                        "Can't identify application (addressdesc descriptor not typeProcessSerialNumber)"
                    )
                app = appscript.app(appPath)
                appData = app.AS_appdata

                _appCache[(addressdesc.type, addressdesc.data)] = (app,
                                                                   appData)
            app, appData = _appCache[(addressdesc.type, addressdesc.data)]

            # unpack parameters
            desc = event.coerce(kae.typeAERecord)
            params = {}
            for i in range(desc.count()):
                key, value = desc.getitem(i + 1, kae.typeWildCard)
                params[key] = appData.unpack(value)
            resultType = params.pop('rtyp', None)
            directParam = params.pop('----', kNoParam)
            try:
                subject = appData.unpack(
                    event.getattr(kae.keySubjectAttr, kae.typeWildCard))
            except Exception:
                subject = None

            # apply special cases
            if subject is not None:
                targetRef = subject
            elif eventcode == 'coresetd':
                # Special case: for 'set' command, use direct parameter as target reference and use 'to' parameter for direct argument
                targetRef = directParam
                directParam = params.pop('data')
            elif isinstance(directParam, appscript.reference.Reference):
                # Special case: if direct parameter is a reference, use this as target reference
                targetRef = directParam
                directParam = kNoParam
            else:
                targetRef = app

            # render
            for key, renderer in [(kLangPython, pythonrenderer),
                                  (kLangRuby, rubyrenderer),
                                  (kLangObjC, objcrenderer)]:
                try:
                    addResultFn(
                        key,
                        renderer.renderCommand(appPath, addressdesc, eventcode,
                                               targetRef, directParam, params,
                                               resultType, modeFlags, timeout,
                                               appData))
                except Exception, e:
                    traceback.print_exc()
                    s = 'Untranslated event %r' % eventcode
                    addResultFn(key, s)

        except Exception, e:
            traceback.print_exc()
            s = 'Untranslated event %r' % eventcode
            addResultFn(kLangAll, s)

        # let Apple event execute as normal, if desired
        if isLive:
            return event.send(modeFlags, timeout)
        else:
            return ae.newdesc(kae.typeNull, '')
Пример #5
0
def _packuint32(n):  # used to pack csig attributes
    return newdesc(kae.typeUInt32, struct.pack('I', n))
Пример #6
0
def makeCustomSendProc(addResultFn, origSendProc):
	def customSendProc(event, modeFlags, priority, timeout):
		# unpack required attributes
		try:
			eventcode, addressdesc = _unpackEventAttributes(event)
			appPath = ae.addressdesctopath(addressdesc)
			
			# get app instance and associated data
			if not _appCache.has_key((addressdesc.type, addressdesc.data)):
				if addressdesc.type != kae.typeProcessSerialNumber:
					raise OSAError(10000, 
							"Can't identify application (addressdesc descriptor not typeProcessSerialNumber)")
				app = appscript.app(appPath)
				appData = app.AS_appdata
				
				_appCache[(addressdesc.type, addressdesc.data)] = (app, appData)
			app, appData = _appCache[(addressdesc.type, addressdesc.data)]
			
			# unpack parameters
			desc = event.coerce(kae.typeAERecord)
			params = {}
			for i in range(desc.count()):
				key, value = desc.getitem(i + 1, kae.typeWildCard)
				params[key] = appData.unpack(value)
			resultType = params.pop('rtyp', None)
			directParam = params.pop('----', None)
			try:
				subject = appData.unpack(event.getattr(kae.keySubjectAttr, kae.typeWildCard))
			except Exception:
				subject = None
			
			# apply special cases
			if subject is not None:
				targetRef = subject
			elif eventcode == 'coresetd':
				# Special case: for 'set' command, use direct parameter as target reference and use 'to' parameter for direct argument
				targetRef = directParam
				directParam = params.pop('data')
			elif isinstance(directParam, appscript.reference.Reference):
				# Special case: if direct parameter is a reference, use this as target reference
				targetRef = directParam
				directParam = None
			else:
				targetRef = app
			
			# render
			for key, renderer in [(kPython, pythonrenderer), (kRuby, rubyrenderer), (kObjC, objcrenderer)]:
				try:
					addResultFn(key, renderer.renderCommand(
							appPath, addressdesc, eventcode, 
							targetRef, directParam, params, 
							resultType, modeFlags, timeout, 
							appData))
				except Exception, e:
					traceback.print_exc()
					s = 'Untranslated event %r' % eventcode
					addResultFn(key, s)

		except Exception, e:
			traceback.print_exc()
			s = 'Untranslated event %r' % eventcode
			addResultFn(kAll, s)
		
		# let Apple event execute as normal, if desired
		if _userDefaults.boolForKey_('sendEvents'):
			return origSendProc(event, modeFlags, priority, timeout)
		else:
			return ae.newdesc(kae.typeNull, '')
Пример #7
0
def _packuint32(n): # used to pack csig attributes
	return newdesc(kae.typeUInt32, struct.pack('I', n))
Пример #8
0
                                  (kLangRuby, rubyrenderer),
                                  (kLangObjC, objcrenderer)]:
                try:
                    addResultFn(
                        key,
                        renderer.renderCommand(appPath, addressdesc, eventcode,
                                               targetRef, directParam, params,
                                               resultType, modeFlags, timeout,
                                               appData))
                except (UntranslatedKeywordError,
                        UntranslatedUserPropertyError), e:
                    s = 'Untranslated event %r\n%s' % (eventcode, e)
                    addResultFn(key, s)
                except Exception, e:
                    traceback.print_exc()
                    s = 'Untranslated event %r' % eventcode
                    addResultFn(key, s)

        except Exception, e:
            traceback.print_exc()
            s = 'Untranslated event %r' % eventcode
            addResultFn(kLangAll, s)

        # let Apple event execute as normal, if desired
        if isLive:
            return event.send(modeFlags, timeout)
        else:
            return ae.newdesc(kae.typeNull, '')

    return customSendProc
Пример #9
0
from typedefs import buildDefs
from handlererror import EventHandlerError


if struct.pack("h", 1) == '\x00\x01': # host is big-endian
	fourCharCode = lambda code: code
else: # host is small-endian
	fourCharCode = lambda code: code[::-1]


######################################################################
# PUBLIC
######################################################################

kMissingValue = ae.newdesc(kae.typeType, fourCharCode('msng')) # 'missing value' constant


class Codecs(aem.Codecs):
	"""Default Codecs for aemreceive; same as aem.Codecs except that None is packed as 'missing value' constant instead of 'null'.
	"""
	def __init__(self):
		aem.Codecs.__init__(self)
		self.encoders[type(None)] = lambda value, codecs: kMissingValue


######################################################################
# PRIVATE
######################################################################
# Constants
Пример #10
0
import aem
from aem import ae, kae

from typedefs import buildDefs
from handlererror import EventHandlerError

if struct.pack("h", 1) == '\x00\x01':  # host is big-endian
    fourCharCode = lambda code: code
else:  # host is small-endian
    fourCharCode = lambda code: code[::-1]

######################################################################
# PUBLIC
######################################################################

kMissingValue = ae.newdesc(kae.typeType,
                           fourCharCode('msng'))  # 'missing value' constant


class Codecs(aem.Codecs):
    """Default Codecs for aemreceive; same as aem.Codecs except that None is packed as 'missing value' constant instead of 'null'.
	"""
    def __init__(self):
        aem.Codecs.__init__(self)
        self.encoders[type(None)] = lambda value, codecs: kMissingValue


######################################################################
# PRIVATE
######################################################################
# Constants
Пример #11
0
				targetRef = app
			
			# render
			for key, renderer in [(kLangPython, pythonrenderer), (kLangRuby, rubyrenderer), (kLangObjC, objcrenderer)]:
				try:
					addResultFn(key, renderer.renderCommand(
							appPath, addressdesc, eventcode, 
							targetRef, directParam, params, 
							resultType, modeFlags, timeout, 
							appData))
				except (UntranslatedKeywordError, UntranslatedUserPropertyError), e:
					s = 'Untranslated event %r\n%s' % (eventcode, e)
					addResultFn(key, s)
				except Exception, e:
					traceback.print_exc()
					s = 'Untranslated event %r' % eventcode
					addResultFn(key, s)

		except Exception, e:
			traceback.print_exc()
			s = 'Untranslated event %r' % eventcode
			addResultFn(kLangAll, s)
		
		# let Apple event execute as normal, if desired
		if isLive:
			return event.send(modeFlags, timeout)
		else:
			return ae.newdesc(kae.typeNull, '')
	return customSendProc