示例#1
0
def dump(apppath, modulepath):
    """Dump application terminology data to Python module.
		apppath : str -- name or path of application
		modulepath : str -- path to generated module
		
	Generates a Python module containing an application's basic terminology 
	(names and codes) as used by appscript.
	
	Call the dump() function to dump faulty aetes to Python module, e.g.:
	
		dump('MyApp', '/path/to/site-packages/myappglue.py')
	
	Patch any errors by hand, then import the patched module into your script 
	and pass it to appscript's app() constructor via its 'terms' argument, e.g.:
	
		from appscript import *
		import myappglue
		
		myapp = app('MyApp', terms=myappglue)

	Note that dumped terminologies aren't used by appscript's built-in help system.
	"""
    apppath = findapp.byname(apppath)
    tables = buildtablesforaetes(aetesforapp(Application(apppath)))
    dumptables(tables, apppath, modulepath)
def fn(ae):
    print
    print 'EVT', ` ae.type, ae.data[:64] + (ae.data[64:] and '...' or '') `
    #raise 'fuk'
    r = Application().event('aevtansr', {'----': 10000}).AEM_event
    print 'RES', ` r.type, r.data[:64] + (r.data[64:] and '...' or '') `
    print
    return r
示例#3
0
def c(ae, m, p, t):
    print
    print 'EVT', ` ae.type, ae.data[:64] + (ae.data[64:] and '...' or '') `

    try:
        r = f(ae, m, p, t)
    except Exception, e:
        print 'ERROR', e
        r = Application().event('aevtansr', {'errn': e[0]}).AEM_event
示例#4
0
def getaetedata(path=None, url=None):
    """Get aetes from local/remote app via an ascrgdte event; result is a list of byte strings."""
    try:
        aetes = Application(path, url).event('ascrgdte', {
            '----': 0
        }).send(60 * 30)
    except Exception, e:  # (e.g.application not running)
        if isinstance(e, CommandError) and e.number == -192:
            aetes = []
        else:
            raise RuntimeError, "Can't get terminology for application (%s): %s" % (
                path or url, e)
示例#5
0
def tablesforapp(path=None, url=None):
    if not _terminologyCache.has_key(path or url):
        try:
            aetes = Application(path, url).event('ascrgdte', {
                '----': 0
            }).send()
        except Exception, e:  # (e.g.application not running)
            raise RuntimeError, "Can't get terminology for application (%s): %s" % (
                path or url, e)
        if not isinstance(aetes, list):
            aetes = [aetes]
        #print [aete.data for aete in aetes if aete.type == 'aete']
        classes, enums, properties, elements, commands = buildtablesforaetes(
            [aete.data for aete in aetes if aete.type == 'aete'])
        _terminologyCache[path or url] = _makeTypeTable(
            classes, enums, properties) + _makeReferenceTable(
                properties, elements, commands)
示例#6
0
end

on open x
	beep 2
	return reverse of x
end
''')

scriptID = osac.OSACompile(scriptDesc, kOSAModeCompileIntoContext, 0)

print 'SOURCE:', ` codecs.unpack(osac.OSAGetSource(scriptID,
                                                   typeUnicodeText)) `

print

event1 = Application().event('aevtoapp', {}).AEM_event
resultID = osac.OSAExecuteEvent(event1, scriptID, kOSAModeNull)

print 'DISPLAY:', ` codecs.unpack(osac.OSADisplay(
    resultID, typeWildCard, 0)) `  # u'{"hello", "world"}'

print 'RESULT:', ` codecs.unpack(
    osac.OSACoerceToDesc(resultID, typeWildCard, 0)) `  # ['hello', 'world']

print

event2 = Application().event('aevtodoc', {'----': [1, 2, 3]}).AEM_event
replyEvent = Application().event('aevtansr').AEM_event
osac.OSADoEvent(event2, scriptID, kOSAModeNull, replyEvent)

print 'REPLY EVENT:', ` codecs.unpack(
示例#7
0
def parseapp(path, style='appscript'):
    return parseaetes(
        TerminologyTableBuilder(style).aetesforapp(Application(path)), path,
        style)
示例#8
0
#!/usr/bin/env pythonw

from aem import Application, app, AEType, k

textedit = Application('/Applications/TextEdit.app')

# name of application "TextEdit"
print textedit.event('coregetd', {'----': app.property('pnam')}).send()

print Application('/System/Library/CoreServices/Finder.app').event(
    'coregetd', {
        k.Direct: app.property('home').elements('cobj'),
        k.ResultType: 'alis'
    }).send()
示例#9
0
#!/usr/bin/env pythonw

from aem import Application, app, AEType, k


textedit = Application("/Applications/TextEdit.app")

# name of application "TextEdit"
print textedit.event("coregetd", {"----": app.property("pnam")}).send()

print Application("/System/Library/CoreServices/Finder.app").event(
    "coregetd", {k.Direct: app.property("home").elements("cobj"), k.ResultType: "alis"}
).send()
示例#10
0
(C) 2004 HAS"""

from CarbonX.AE import AECreateDesc
import CarbonX.kAE as _k
import MacOS

from aem import Application, CommandError

__all__ = ['osax', 'CommandError', 'kCurrentApplication']

######################################################################
# PRIVATE
######################################################################

kCurrentApplication = Application()

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


def osax(event,
         params={},
         atts={},
         target=kCurrentApplication,
         timeout=_k.kAEDefaultTimeout):
    """Call an OSAX ('OSA eXtension').
		event : str -- 8-letter code indicating event's class, e.g. 'sysobeep'
		params : dict -- a dict of form {code:anything,...} containing zero or more parameters for the event
		atts : dict -- a dict of form {code:anything,...} containing zero or more attributes for the event
示例#11
0
# TO DECIDE: what do do about event timeouts?
# TO DECIDE: what to use for app arguments? Should name/path/id/creator expansion be moved from appscript.app to aem.send.Application to improve ease of use?

import MacOS
from CarbonX.AE import AECreateDesc
from aem import Application, AEType, AEEnum
from main import osax, kCurrentApplication
import macfile

######################################################################
# PRIVATE
######################################################################

_SystemEvents = Application(
    desc=AECreateDesc('sign', 'sevs')
)  # used by clipboard commands, which need to target another application to work


def _params(params, *optparams):  # pack optional parameters into params dict
    for code, value in optparams:
        if value is not None:
            params[code] = value
    return params


def _aliasToPath(alias):
    return unicode(alias.ResolveAlias(None)[0].as_pathname(), 'utf8')


######################################################################