Python MacOS.Error() Examples

The following are 30 code examples of MacOS.Error(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module MacOS , or try the search function .
Example #1
Source File: gensuitemodule.py    From Splunking-Crime with GNU Affero General Public License v3.0 6 votes vote down vote up
def processfile(fullname, output=None, basepkgname=None,
        edit_modnames=None, creatorsignature=None, dump=None,
        verbose=None):
    """Ask an application for its terminology and process that"""
    if not is_scriptable(fullname) and verbose:
        print >>verbose, "Warning: app does not seem scriptable: %s" % fullname
    if verbose:
        print >>verbose, "\nASKING FOR aete DICTIONARY IN", repr(fullname)
    try:
        aedescobj, launched = OSATerminology.GetAppTerminology(fullname)
    except MacOS.Error, arg:
        if arg[0] in (-1701, -192): # errAEDescNotFound, resNotFound
            if verbose:
                print >>verbose, "GetAppTerminology failed with errAEDescNotFound/resNotFound, trying manually"
            aedata, sig = getappterminology(fullname, verbose=verbose)
            if not creatorsignature:
                creatorsignature = sig
        else:
            raise 
Example #2
Source File: buildtools.py    From Computable with MIT License 6 votes vote down vote up
def findtemplate(template=None):
    """Locate the applet template along sys.path"""
    if MacOS.runtimemodel == 'macho':
        return None
    if not template:
        template=TEMPLATE
    for p in sys.path:
        file = os.path.join(p, template)
        try:
            file, d1, d2 = Carbon.File.FSResolveAliasFile(file, 1)
            break
        except (Carbon.File.Error, ValueError):
            continue
    else:
        raise BuildError, "Template %r not found on sys.path" % (template,)
    file = file.as_pathname()
    return file 
Example #3
Source File: gensuitemodule.py    From Splunking-Crime with GNU Affero General Public License v3.0 6 votes vote down vote up
def is_scriptable(application):
    """Return true if the application is scriptable"""
    if os.path.isdir(application):
        plistfile = os.path.join(application, 'Contents', 'Info.plist')
        if not os.path.exists(plistfile):
            return False
        plist = plistlib.Plist.fromFile(plistfile)
        return plist.get('NSAppleScriptEnabled', False)
    # If it is a file test for an aete/aeut resource.
    currf = CurResFile()
    try:
        refno = macresource.open_pathname(application)
    except MacOS.Error:
        return False
    UseResFile(refno)
    n_terminology = Count1Resources('aete') + Count1Resources('aeut') + \
        Count1Resources('scsz') + Count1Resources('osiz')
    CloseResFile(refno)
    UseResFile(currf)
    return n_terminology > 0 
Example #4
Source File: aetools.py    From Splunking-Crime with GNU Affero General Public License v3.0 6 votes vote down vote up
def _get(self, _object, asfile=None, _attributes={}):
        """_get: get data from an object
        Required argument: the object
        Keyword argument _attributes: AppleEvent attribute dictionary
        Returns: the data
        """
        _code = 'core'
        _subcode = 'getd'

        _arguments = {'----':_object}
        if asfile:
            _arguments['rtyp'] = mktype(asfile)

        _reply, _arguments, _attributes = self.send(_code, _subcode,
                _arguments, _attributes)
        if 'errn' in _arguments:
            raise Error, decodeerror(_arguments)

        if '----' in _arguments:
            return _arguments['----']
            if asfile:
                item.__class__ = asfile
            return item 
Example #5
Source File: gensuitemodule.py    From Computable with MIT License 6 votes vote down vote up
def is_scriptable(application):
    """Return true if the application is scriptable"""
    if os.path.isdir(application):
        plistfile = os.path.join(application, 'Contents', 'Info.plist')
        if not os.path.exists(plistfile):
            return False
        plist = plistlib.Plist.fromFile(plistfile)
        return plist.get('NSAppleScriptEnabled', False)
    # If it is a file test for an aete/aeut resource.
    currf = CurResFile()
    try:
        refno = macresource.open_pathname(application)
    except MacOS.Error:
        return False
    UseResFile(refno)
    n_terminology = Count1Resources('aete') + Count1Resources('aeut') + \
        Count1Resources('scsz') + Count1Resources('osiz')
    CloseResFile(refno)
    UseResFile(currf)
    return n_terminology > 0 
Example #6
Source File: gensuitemodule.py    From Computable with MIT License 6 votes vote down vote up
def processfile(fullname, output=None, basepkgname=None,
        edit_modnames=None, creatorsignature=None, dump=None,
        verbose=None):
    """Ask an application for its terminology and process that"""
    if not is_scriptable(fullname) and verbose:
        print >>verbose, "Warning: app does not seem scriptable: %s" % fullname
    if verbose:
        print >>verbose, "\nASKING FOR aete DICTIONARY IN", repr(fullname)
    try:
        aedescobj, launched = OSATerminology.GetAppTerminology(fullname)
    except MacOS.Error, arg:
        if arg[0] in (-1701, -192): # errAEDescNotFound, resNotFound
            if verbose:
                print >>verbose, "GetAppTerminology failed with errAEDescNotFound/resNotFound, trying manually"
            aedata, sig = getappterminology(fullname, verbose=verbose)
            if not creatorsignature:
                creatorsignature = sig
        else:
            raise 
Example #7
Source File: aetools.py    From Splunking-Crime with GNU Affero General Public License v3.0 6 votes vote down vote up
def open(self, _object, _attributes={}, **_arguments):
        """open: Open the specified object(s)
        Required argument: list of objects to open
        Keyword argument _attributes: AppleEvent attribute dictionary
        """
        _code = 'aevt'
        _subcode = 'odoc'

        if _arguments: raise TypeError, 'No optional args expected'
        _arguments['----'] = _object


        _reply, _arguments, _attributes = self.send(_code, _subcode,
                _arguments, _attributes)
        if 'errn' in _arguments:
            raise Error, decodeerror(_arguments)
        # XXXX Optionally decode result
        if '----' in _arguments:
            return _arguments['----']
#pass 
Example #8
Source File: buildtools.py    From Splunking-Crime with GNU Affero General Public License v3.0 6 votes vote down vote up
def findtemplate(template=None):
    """Locate the applet template along sys.path"""
    if MacOS.runtimemodel == 'macho':
        return None
    if not template:
        template=TEMPLATE
    for p in sys.path:
        file = os.path.join(p, template)
        try:
            file, d1, d2 = Carbon.File.FSResolveAliasFile(file, 1)
            break
        except (Carbon.File.Error, ValueError):
            continue
    else:
        raise BuildError, "Template %r not found on sys.path" % (template,)
    file = file.as_pathname()
    return file 
Example #9
Source File: aetools.py    From Computable with MIT License 6 votes vote down vote up
def _get(self, _object, asfile=None, _attributes={}):
        """_get: get data from an object
        Required argument: the object
        Keyword argument _attributes: AppleEvent attribute dictionary
        Returns: the data
        """
        _code = 'core'
        _subcode = 'getd'

        _arguments = {'----':_object}
        if asfile:
            _arguments['rtyp'] = mktype(asfile)

        _reply, _arguments, _attributes = self.send(_code, _subcode,
                _arguments, _attributes)
        if 'errn' in _arguments:
            raise Error, decodeerror(_arguments)

        if '----' in _arguments:
            return _arguments['----']
            if asfile:
                item.__class__ = asfile
            return item 
Example #10
Source File: aetools.py    From Computable with MIT License 6 votes vote down vote up
def open(self, _object, _attributes={}, **_arguments):
        """open: Open the specified object(s)
        Required argument: list of objects to open
        Keyword argument _attributes: AppleEvent attribute dictionary
        """
        _code = 'aevt'
        _subcode = 'odoc'

        if _arguments: raise TypeError, 'No optional args expected'
        _arguments['----'] = _object


        _reply, _arguments, _attributes = self.send(_code, _subcode,
                _arguments, _attributes)
        if 'errn' in _arguments:
            raise Error, decodeerror(_arguments)
        # XXXX Optionally decode result
        if '----' in _arguments:
            return _arguments['----']
#pass 
Example #11
Source File: aetools.py    From Splunking-Crime with GNU Affero General Public License v3.0 5 votes vote down vote up
def decodeerror(arguments):
    """Create the 'best' argument for a raise MacOS.Error"""
    errn = arguments['errn']
    err_a1 = errn
    if 'errs' in arguments:
        err_a2 = arguments['errs']
    else:
        err_a2 = MacOS.GetErrorString(errn)
    if 'erob' in arguments:
        err_a3 = arguments['erob']
    else:
        err_a3 = None

    return (err_a1, err_a2, err_a3) 
Example #12
Source File: gensuitemodule.py    From Splunking-Crime with GNU Affero General Public License v3.0 5 votes vote down vote up
def main_interactive(interact=0, basepkgname='StdSuites'):
    if interact:
        # Ask for save-filename for each module
        edit_modnames = None
    else:
        # Use default filenames for each module
        edit_modnames = []
    appsfolder = Carbon.Folder.FSFindFolder(-32765, 'apps', 0)
    filename = EasyDialogs.AskFileForOpen(
        message='Select scriptable application',
        dialogOptionFlags=0x1056,       # allow selection of .app bundles
        defaultLocation=appsfolder)
    if not filename:
        return
    if not is_scriptable(filename):
        if EasyDialogs.AskYesNoCancel(
                "Warning: application does not seem scriptable",
                yes="Continue", default=2, no="") <= 0:
            return
    try:
        processfile(filename, edit_modnames=edit_modnames, basepkgname=basepkgname,
        verbose=sys.stderr)
    except MacOS.Error, arg:
        print "Error getting terminology:", arg
        print "Retry, manually parsing resources"
        processfile_fromresource(filename, edit_modnames=edit_modnames,
            basepkgname=basepkgname, verbose=sys.stderr) 
Example #13
Source File: aetools.py    From Splunking-Crime with GNU Affero General Public License v3.0 5 votes vote down vote up
def _start(self):
        """Start the application, if it is not running yet"""
        try:
            self.send('ascr', 'noop')
        except AE.Error:
            _launch(self.target_signature)
            for i in range(LAUNCH_MAX_WAIT_TIME):
                try:
                    self.send('ascr', 'noop')
                except AE.Error:
                    pass
                else:
                    break
                time.sleep(1) 
Example #14
Source File: platform.py    From Splunking-Crime with GNU Affero General Public License v3.0 5 votes vote down vote up
def _mac_ver_lookup(selectors,default=None):

    from gestalt import gestalt
    import MacOS
    l = []
    append = l.append
    for selector in selectors:
        try:
            append(gestalt(selector))
        except (RuntimeError, MacOS.Error):
            append(default)
    return l 
Example #15
Source File: platform.py    From medicare-demo with Apache License 2.0 5 votes vote down vote up
def _mac_ver_lookup(selectors,default=None):

    from gestalt import gestalt
    import MacOS
    l = []
    append = l.append
    for selector in selectors:
        try:
            append(gestalt(selector))
        except (RuntimeError, MacOS.Error):
            append(default)
    return l 
Example #16
Source File: test_gestalt.py    From medicare-demo with Apache License 2.0 5 votes vote down vote up
def leak():
    # taken from platform._mac_ver_lookup()
    from gestalt import gestalt
    import MacOS

    try:
        gestalt('sysu')
    except MacOS.Error:
        pass 
Example #17
Source File: platform.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def _mac_ver_lookup(selectors,default=None):

    from gestalt import gestalt
    import MacOS
    l = []
    append = l.append
    for selector in selectors:
        try:
            append(gestalt(selector))
        except (RuntimeError, MacOS.Error):
            append(default)
    return l 
Example #18
Source File: platform.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def _mac_ver_lookup(selectors,default=None):

    from gestalt import gestalt
    import MacOS
    l = []
    append = l.append
    for selector in selectors:
        try:
            append(gestalt(selector))
        except (RuntimeError, MacOS.Error):
            append(default)
    return l 
Example #19
Source File: test_gestalt.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def leak():
    # taken from platform._mac_ver_lookup()
    from gestalt import gestalt
    import MacOS

    try:
        gestalt('sysu')
    except MacOS.Error:
        pass 
Example #20
Source File: platform.py    From RevitBatchProcessor with GNU General Public License v3.0 5 votes vote down vote up
def _mac_ver_lookup(selectors,default=None):

    from gestalt import gestalt
    import MacOS
    l = []
    append = l.append
    for selector in selectors:
        try:
            append(gestalt(selector))
        except (RuntimeError, MacOS.Error):
            append(default)
    return l 
Example #21
Source File: platform.py    From PokemonGo-DesktopMap with MIT License 5 votes vote down vote up
def _mac_ver_lookup(selectors,default=None):

    from gestalt import gestalt
    import MacOS
    l = []
    append = l.append
    for selector in selectors:
        try:
            append(gestalt(selector))
        except (RuntimeError, MacOS.Error):
            append(default)
    return l 
Example #22
Source File: test_gestalt.py    From PokemonGo-DesktopMap with MIT License 5 votes vote down vote up
def leak():
    # taken from platform._mac_ver_lookup()
    from gestalt import gestalt
    import MacOS

    try:
        gestalt('sysu')
    except MacOS.Error:
        pass 
Example #23
Source File: platform.py    From unity-python with MIT License 5 votes vote down vote up
def _mac_ver_lookup(selectors,default=None):

    from gestalt import gestalt
    import MacOS
    l = []
    append = l.append
    for selector in selectors:
        try:
            append(gestalt(selector))
        except (RuntimeError, MacOS.Error):
            append(default)
    return l 
Example #24
Source File: platform.py    From canape with GNU General Public License v3.0 5 votes vote down vote up
def _mac_ver_lookup(selectors,default=None):

    from gestalt import gestalt
    import MacOS
    l = []
    append = l.append
    for selector in selectors:
        try:
            append(gestalt(selector))
        except (RuntimeError, MacOS.Error):
            append(default)
    return l 
Example #25
Source File: platform.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def _mac_ver_lookup(selectors,default=None):

    from gestalt import gestalt
    import MacOS
    l = []
    append = l.append
    for selector in selectors:
        try:
            append(gestalt(selector))
        except (RuntimeError, MacOS.Error):
            append(default)
    return l 
Example #26
Source File: platform.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def _mac_ver_lookup(selectors,default=None):

    from gestalt import gestalt
    import MacOS
    l = []
    append = l.append
    for selector in selectors:
        try:
            append(gestalt(selector))
        except (RuntimeError, MacOS.Error):
            append(default)
    return l 
Example #27
Source File: test_gestalt.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def leak():
    # taken from platform._mac_ver_lookup()
    from gestalt import gestalt
    import MacOS

    try:
        gestalt('sysu')
    except MacOS.Error:
        pass 
Example #28
Source File: aetools.py    From Computable with MIT License 5 votes vote down vote up
def _start(self):
        """Start the application, if it is not running yet"""
        try:
            self.send('ascr', 'noop')
        except AE.Error:
            _launch(self.target_signature)
            for i in range(LAUNCH_MAX_WAIT_TIME):
                try:
                    self.send('ascr', 'noop')
                except AE.Error:
                    pass
                else:
                    break
                time.sleep(1) 
Example #29
Source File: platform.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def _mac_ver_lookup(selectors,default=None):

    from gestalt import gestalt
    import MacOS
    l = []
    append = l.append
    for selector in selectors:
        try:
            append(gestalt(selector))
        except (RuntimeError, MacOS.Error):
            append(default)
    return l 
Example #30
Source File: test_gestalt.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def leak():
    # taken from platform._mac_ver_lookup()
    from gestalt import gestalt
    import MacOS

    try:
        gestalt('sysu')
    except MacOS.Error:
        pass