Example #1
0
def systemattribute(attribute, testbits=None):
    """Test attributes of this computer
		attribute : str -- 4-letter code; the attribute to test (either a "Gestalt" value or a shell environment variable). # TO CHECK: Which codes? Does it take long strings too? (Apple's documentation is hopeless...)
		testbits : int -- test specific bits of response
		Result: int | str -- the result of the query (or a list of all environment variables, if no attribute is provided)
	"""
    return osax('fndrgstl',
                _params({'----': AEType(attribute)}, ('has ', testbits)))
Example #2
0
def clipboardinfo(desiredtype=None):
    """Return information about the clipboard
		desiredtype : str -- 4-letter code; restricts result to information about only this data type
		Result: list of list -- one list of [data type, size] for each type of data on the clipboard
	"""
    return osax('JonsiClp',
                _params({}, ('for ', desiredtype and AEType(desiredtype))),
                target=_SystemEvents)
Example #3
0
def getclipboard(desiredtype=None):
    """Return the contents of an application's clipboard. Activate the target application first
		desiredtype : str -- 4-letter code; the type of data desired (see also clipboardinfo)
		Result: list of anything -- the data from its clipboard
	"""
    return osax('JonsgClp',
                _params({}, ('rtyp', desiredtype and AEType(desiredtype))),
                target=_SystemEvents)
Example #4
0
def pathto(location, domain=None, asstring=False):
    """Returns full path name to the folder specified
		location : kApplicationSupport | kCurrentUser | kDesktop | kDesktopPictures | kFolderActions | kFonts | kHelp | kKeychain | kModemScripts | kPreferences | kPrinterDescriptions | kScriptingAdditions | kScripts | kSharedLibraries | kStartupDisk | kSystem | kSystemPreferences | kTemporaryItems | kTrash | kUsers | kVoices -- the folder to return
		domain : kNetworkDomain | kSystemDomain | kLocalDomain | kUserDomain -- where to look for the indicated folder
		asstring : boolean -- return unicode string (Mac path) instead of alias
		Result: macfile.Alias | str -- the path name to the folder or application specified
	"""
    return osax(
        'earsffdr',
        _params({'----': location}, ('from', domain),
                ('rtyp', asstring and AEType('utxt') or None)))
Example #5
0
 def AEM_unpack(self, desc, codecs):
     try:
         return self._unpack(desc, codecs)
     except MacOS.Error, e:
         number, message = e[0], e.args[1:] and e[1] or None
         if number == -1700:  # coercion error
             return False, EventHandlerError(number,
                                             message,
                                             object=desc,
                                             coercion=AEType(self.AEM_code))
         else:
             return False, EventHandlerError(number, message, object=desc)
Example #6
0
def chooseapp(title=None,
              prompt=None,
              multiselect=None,
              app=kCurrentApplication):
    """Choose an application on this machine or the network
		title : str -- the dialog window title
		prompt : str -- the prompt to appear at the top of the application chooser dialog box
		multiselect : bool -- Allow multiple items to be selected?
		app : aem.send.Application -- the application to use (default = kCurrentApplication)
		Result : macfile.Alias | list of macfile.Alias -- path(s) to application(s)
	"""
    try:
        return osax(
            'sysoppcb',
            _params({'rtyp': AEType('alis')}, ('appr', title),
                    ('prmp', prompt), ('mlsl', multiselect)),
            target=app,
            timeout=3600 * 5
        )  # extra-long timeout as making multiple selections can take some time
    except MacOS.Error, err:
        if err[0] == -128:  # user cancelled
            raise UserCancelled
        else:
            raise
Example #7
0
# e.g. k.ask <-> AEEnum('ask ')

_typebyname = {}  # used to encode class and enumerator keywords
_typebycode = {
}  # used to decode class (typeType) and enumerator (typeEnum) descriptors

for _, enumerators in appscripttypedefs.enumerations:
    for name, code in enumerators:
        _typebyname[name] = AEEnum(code)
        _typebycode[code] = Keyword(name)
for defs in [
        appscripttypedefs.alltypes, appscripttypedefs.commontypes,
        appscripttypedefs.properties
]:
    for name, code in defs:
        _typebyname[name] = AEType(code)
        _typebycode[code] = Keyword(name)

# Reference tables; used to translate references and commands
# e.g. app(...).documents.text <-> app.elements('docu').property('ctxt')
# e.g. app(...).quit(saving=k.ask) <-> Application(...).event('aevtquit', {'savo': AEEnum('ask ')})

_defaultcommands = {
    # 'run', 'open', 'print' and 'quit' are Required Suite commands so should always be available.
    'run': (kCommand, ('aevtoapp', {})),
    'open': (kCommand, ('aevtodoc', {})),
    'print_': (kCommand, ('aevtpdoc', {})),
    'quit': (kCommand, ('aevtquit', {
        'saving': 'savo'
    })),
    # 'reopen' and 'activate' aren't normally listed in terminology.
Example #8
0
# e.g. k.document <-> AEType('docu')
# e.g. k.ask <-> AEEnum('ask ')

_defaulttypebyname = {}  # used to encode class and enumerator keywords
_defaulttypebycode = {
}  # used to decode class (typeType) and enumerator (typeEnum) descriptors
_defaulttypecodebyname = {}  # used to check for name collisions

for _, enumerators in defaultterminology.enumerations:
    for name, code in enumerators:
        _defaulttypebyname[name] = AEEnum(code)
        _defaulttypebycode[code] = Keyword(name)
        _defaulttypecodebyname[name] = code
for defs in [defaultterminology.types, defaultterminology.properties]:
    for name, code in defs:
        _defaulttypebyname[name] = AEType(code)
        _defaulttypebycode[code] = Keyword(name)
        _defaulttypecodebyname[name] = code

# Reference tables; used to translate references and commands
# e.g. app(...).documents.text <-> app.elements('docu').property('ctxt')
# e.g. app(...).quit(saving=k.ask) <-> Application(...).event('aevtquit', {'savo': AEEnum('ask ')})

_defaultreferencebycode = {}  # used to decode property and element specifiers
_defaultreferencebyname = {
}  # used to encode property and element specifiers and Apple events
_defaultcommandcodebyname = {}  # used to check for name collisions

for name, code in defaultterminology.properties:
    _defaultreferencebycode[kProperty + code] = (kProperty, name)
    _defaultreferencebyname[name] = (kProperty, code)
Example #9
0
 def _unpack(self, desc, codecs):
     desc = desc.AECoerceDesc(kAE.typeEnumerated)
     if desc.data not in self._codes:
         return False, EventHandlerError(-1704, "Bad enumerator.", desc,
                                         AEType(kAE.typeEnumerated))
     return True, codecs.unpack(desc)
Example #10
0
#!/usr/bin/env pythonw

from CarbonX.OSA import OSAComponentInstance
from Carbon.Cm import OpenDefaultComponent
from CarbonX.kAE import *
from CarbonX.kOSA import *
from aem import Codecs, AEType
from sys import exit
from pprint import pprint

codecs = Codecs()

ascr = OSAComponentInstance(OpenDefaultComponent('osa ', 'ascr'))

names = codecs.unpack(ascr.ASGetSourceStyleNames(kOSAModeNull))
values = codecs.unpack(ascr.ASGetSourceStyles())
#print `st.type, st.data`
pprint(zip(names, values))

values[0][AEType('ptsz')] = 42

ascr.ASSetSourceStyles(codecs.pack(values))
values = codecs.unpack(ascr.ASGetSourceStyles())
pprint(zip(names, values))
Example #11
0
		app : aem.send.Application -- the application to use (default = kCurrentApplication)
		Result : (str, str, bool) -- the button clicked (or '' if dialog gave up), text entered (or None if no defaultanswer given), dialog timed-out flag (or None if no timeout given)
	"""
    try:
        reply = osax('sysodlog',
                     _params({'----': text}, ('dtxt', defaultanswer),
                             ('btns', buttons), ('dflt', defaultbutton),
                             ('disp', icon), ('givu', timeout)),
                     target=app)
    except MacOS.Error, err:
        if err[0] == -128:  # user cancelled
            raise UserCancelled
        else:
            raise
    else:
        return reply.get(AEType('bhit')), reply.get(AEType('ttxt')), reply.get(
            AEType('gavu'))


# some dialog wrappers for convenience:


def displaymessage(text, timeout=None, app=kCurrentApplication):
    displaydialog(text, ['OK'], 1, icon=kNote, timeout=timeout, app=app)


def displaywarning(text, stopbydefault=True, app=kCurrentApplication):
    return displaydialog(text, ['Stop', 'Continue'],
                         not stopbydefault + 1,
                         icon=kCaution,
                         app=app)[0] == 'Continue'