#!/usr/bin/env pythonw from Carbon.Cm import OpenDefaultComponent from CarbonX.OSA import OSAComponentInstance from CarbonX.kAE import * from CarbonX.AE import * from aem import Codecs codecs = Codecs() osac = OSAComponentInstance(OpenDefaultComponent('osa ', 'ascr')) scriptDesc = codecs.pack(''' tell app "finder" to home ''') f = osac.OSAGetCreateProc() print f def c(*args): # (AEEventClass theAEEventClass, AEEventID theAEEventID, AEAddressDesc target, AEReturnID returnID, AETransactionID transactionID) -> (AppleEvent result) print args #raise 'test error' return f(*args) return AECreateAppleEvent(*args) osac.OSASetCreateProc(c)
#!/usr/bin/env pythonw from Carbon.Cm import OpenDefaultComponent from CarbonX.OSA import OSAComponentInstance from CarbonX.kAE import * from CarbonX.AE import * from aem import Codecs, Application codecs = Codecs() osac = OSAComponentInstance(OpenDefaultComponent('osa ', 'ascr')) scriptDesc = codecs.pack(''' tell app "finder" to home ''') f = osac.OSAGetSendProc() print f 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 print 'RES', ` r.type, r.data[:64] + (r.data[64:] and '...' or '') `
#!/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))
#!/usr/bin/env pythonw from os.path import split, join from Carbon.Cm import OpenDefaultComponent from CarbonX.OSA import OSAComponentInstance from CarbonX.kAE import * from CarbonX.kOSA import * from aem import Codecs # create an aem Codecs instance to pack and unpack AEDescs codecs = Codecs() # open an AppleScript component instance, and wrap it in an OSAComponentInstance to provide the OSA API (clumsy arrangement, but it does the job) osac = OSAComponentInstance(OpenDefaultComponent('osa ', 'ascr')) root = split(__file__)[0] src = join(root, 'test.scpt') dest = join(root, 'test_out.scpt') id, storable = osac.OSALoadFile(src, kOSAModeNull) print id, storable print osac.OSAExecute(id, kOSANullScript, kOSAModeNull) osac.OSAStoreFile(id, typeOSAGenericStorage, kOSAModeNull, dest) print osac.OSALoadExecuteFile(src, kOSANullScript, kOSAModeNull) print `codecs.unpack(osac.OSADoScriptFile(src, kOSANullScript, typeWildCard, kOSAModeNull))`
#!/usr/bin/env pythonw from os.path import split, join from Carbon.Cm import OpenDefaultComponent from CarbonX.OSA import OSAComponentInstance from CarbonX.kAE import * from CarbonX.kOSA import * from aem import Codecs # create an aem Codecs instance to pack and unpack AEDescs codecs = Codecs() # open an AppleScript component instance, and wrap it in an OSAComponentInstance to provide the OSA API (clumsy arrangement, but it does the job) osac = OSAComponentInstance(OpenDefaultComponent('osa ', 'ascr')) root = split(__file__)[0] src = join(root, 'test.scpt') dest = join(root, 'test_out.scpt') id, storable = osac.OSALoadFile(src, kOSAModeNull) print id, storable print osac.OSAExecute(id, kOSANullScript, kOSAModeNull) osac.OSAStoreFile(id, typeOSAGenericStorage, kOSAModeNull, dest) print osac.OSALoadExecuteFile(src, kOSANullScript, kOSAModeNull) print ` codecs.unpack(
(C) 2005 HAS """ import MacOS from aem import Codecs import OSATerminology as _osat __all__ = ['getsdef', 'getaete', 'getaeut'] ###################################################################### # PRIVATE ###################################################################### _codecs = Codecs() _codecs.decoders['aete'] = _codecs.decoders[ 'aeut'] = lambda desc, app: desc.data ###################################################################### # PUBLIC ###################################################################### def getsdef(path): """Get an application's terminology as sdef XML data, if available. path : str | unicode | FSRef -- full path to app Result : str | None -- XML data, or None if OS version < 10.4 """ return _osat.CopyScriptingDefinition(path)
#!/usr/bin/env pythonw from Carbon.Cm import OpenDefaultComponent from CarbonX.OSA import OSAComponentInstance from CarbonX.kAE import * from CarbonX.kOSA import * from CarbonX.AE import * from aem import Codecs, Application codecs = Codecs() osac = OSAComponentInstance(OpenDefaultComponent('osa ', 'ascr')) scriptDesc = codecs.pack(''' continue foo() log 42 99 ''') osac.OSASetDefaultTarget(AECreateDesc(typeNull, '')) scriptID = osac.OSACompile(scriptDesc, kOSAModeCompileIntoContext, 0) 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
#!/usr/bin/env pythonw from Carbon.Cm import OpenDefaultComponent from CarbonX.OSA import OSAComponentInstance from CarbonX.kAE import * from aem import Codecs # create an aem Codecs instance to pack and unpack AEDescs codecs = Codecs() # open an AppleScript component instance, and wrap it in an OSAComponentInstance to provide the OSA API (clumsy arrangement, but it does the job) osac = OSAComponentInstance(OpenDefaultComponent('osa ', 'ascr')) # define some AppleScript source code script = ''' set s to "hello" & space & "world" say s using "Zarvox" return s ''' # pack source code into an AEDesc scriptDesc = codecs.pack(script) # compile and run script, returning its result resultDesc = osac.OSADoScript(scriptDesc, 0, typeChar, 0) # unpack result print ` codecs.unpack(resultDesc) ` # '"hello world"'
#!/usr/bin/env pythonw from Carbon.Cm import OpenDefaultComponent from CarbonX.OSA import OSAComponentInstance from CarbonX.kAE import * from aem import Codecs codecs = Codecs() osac = OSAComponentInstance(OpenDefaultComponent('osa ', 'ascr')) scriptDesc = codecs.pack(''' delay 1 42 ''') i = 0 f = osac.OSAGetActiveProc() def activeProc(): global i i+=1 r = f() if r: print 'Err', r return r print f print f()
#!/usr/bin/env pythonw from Carbon.Cm import OpenDefaultComponent from CarbonX.OSA import OSAComponentInstance from CarbonX.kAE import * from aem import Codecs # create an aem Codecs instance to pack and unpack AEDescs codecs = Codecs() # open an AppleScript component instance, and wrap it in an OSAComponentInstance to provide the OSA API (clumsy arrangement, but it does the job) osac = OSAComponentInstance(OpenDefaultComponent('osa ', 'ascr')) # define some AppleScript source code script = ''' set s to "hello" & space & "world" say s using "Zarvox" return s ''' # pack source code into an AEDesc scriptDesc = codecs.pack(script) # compile and run script, returning its result resultDesc = osac.OSADoScript(scriptDesc, 0, typeChar, 0) # unpack result print `codecs.unpack(resultDesc)` # '"hello world"'
#!/usr/bin/env pythonw from Carbon.Cm import OpenDefaultComponent from CarbonX.OSA import OSAComponentInstance from CarbonX.kAE import * from CarbonX.kOSA import * from CarbonX.AE import * from aem import Codecs, Application codecs = Codecs() osac = OSAComponentInstance(OpenDefaultComponent('osa ', 'ascr')) scriptDesc = codecs.pack(''' continue foo() log 42 99 ''') osac.OSASetDefaultTarget(AECreateDesc(typeNull, '')) scriptID = osac.OSACompile(scriptDesc, kOSAModeCompileIntoContext, 0) 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 '')`
#!/usr/bin/env pythonw from Carbon.Cm import OpenDefaultComponent from CarbonX.OSA import OSAComponentInstance from CarbonX.kOSA import * from CarbonX.kAE import * from aem import Codecs codecs = Codecs() osac = OSAComponentInstance(OpenDefaultComponent('osa ', 'ascr')) script = '''tell app "Finder" to get folder 1 of home''' scriptDesc = codecs.pack(script) scriptID = osac.OSACompile(scriptDesc, kOSAModeNull, kOSANullScript) resultID = osac.OSAExecute(scriptID, kOSANullScript, kOSAModeNull) print `codecs.unpack(osac.OSAGetSource(scriptID, typeWildCard))` print print `codecs.unpack(osac.OSADisplay(resultID, typeWildCard, kOSAModeNull))` print print `codecs.unpack(osac.OSACoerceToDesc(resultID, typeWildCard, 0))` osac.OSADispose(scriptID) osac.OSADispose(resultID)
#!/usr/bin/env pythonw from Carbon.Cm import OpenDefaultComponent from CarbonX.OSA import OSAComponentInstance from CarbonX.kOSA import * from CarbonX.kAE import * from aem import Codecs codecs = Codecs() osac = OSAComponentInstance(OpenDefaultComponent('osa ', 'ascr')) script = '''tell app "Finder" to get folder 1 of home''' scriptDesc = codecs.pack(script) scriptID = osac.OSACompile(scriptDesc, kOSAModeNull, kOSANullScript) resultID = osac.OSAExecute(scriptID, kOSANullScript, kOSAModeNull) print ` codecs.unpack(osac.OSAGetSource(scriptID, typeWildCard)) ` print print ` codecs.unpack(osac.OSADisplay(resultID, typeWildCard, kOSAModeNull)) ` print print ` codecs.unpack(osac.OSACoerceToDesc(resultID, typeWildCard, 0)) ` osac.OSADispose(scriptID) osac.OSADispose(resultID)
#!/usr/bin/env pythonw from Carbon.Cm import OpenDefaultComponent from CarbonX.OSA import OSAComponentInstance from CarbonX.kOSA import * from CarbonX.kAE import * from aem import Codecs, Application codecs = Codecs() osac = OSAComponentInstance(OpenDefaultComponent('osa ', 'ascr')) scriptDesc = codecs.pack(''' on run beep 3 return {"hello", "world"} 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
(C) 2005 HAS """ import MacOS from aem import Codecs from CarbonX.AE import AEDesc import OSATerminology __all__ = ['getsdef', 'getaete', 'getaeut'] ###################################################################### # PRIVATE ###################################################################### _codecs = Codecs() def _extract(fn, type): try: desc = fn() except MacOS.Error, err: if err.args[0] != -192: # re-raise unless aete resource not found raise return [] else: lst = _codecs.unpack(desc) if not isinstance(lst, list): lst = [lst] return [val for val in lst if isinstance(val, AEDesc) and val.type == type and val.data]
#!/usr/bin/env pythonw from Carbon.Cm import OpenDefaultComponent from CarbonX.OSA import OSAComponentInstance from CarbonX.kAE import * from aem import Codecs codecs = Codecs() osac = OSAComponentInstance(OpenDefaultComponent('osa ', 'ascr')) scriptDesc = codecs.pack(''' delay 1 42 ''') i = 0 f = osac.OSAGetActiveProc() def activeProc(): global i i += 1 r = f() if r: print 'Err', r return r print f
#!/usr/bin/env pythonw from Carbon.Cm import OpenDefaultComponent from CarbonX.OSA import OSAComponentInstance from CarbonX.kOSA import * from CarbonX.kAE import * from aem import Codecs, AEEventName codecs = Codecs() osac = OSAComponentInstance(OpenDefaultComponent('osa ', 'ascr')) script = ''' property foo : 1 property bar : 42 property name : "hello" on run end on open x end on baz() end on fub() end ''' scriptDesc = codecs.pack(script)
#!/usr/bin/env pythonw from Carbon.Cm import OpenDefaultComponent from CarbonX.OSA import OSAComponentInstance from CarbonX.kOSA import * from CarbonX.kAE import * from aem import Codecs, Application codecs = Codecs() osac = OSAComponentInstance(OpenDefaultComponent('osa ', 'ascr')) scriptDesc = codecs.pack(''' on run beep 3 return {"hello", "world"} 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))`
#!/usr/bin/env pythonw from Carbon.Cm import OpenDefaultComponent from CarbonX.OSA import OSAComponentInstance from CarbonX.kAE import * from CarbonX.kOSA import * from aem import Codecs from sys import exit # create an aem Codecs instance to pack and unpack AEDescs codecs = Codecs() # open an AppleScript component instance, and wrap it in an OSAComponentInstance to provide the OSA API (clumsy arrangement, but it does the job) scpt = OSAComponentInstance(OpenDefaultComponent("osa ", "scpt")) ascr = OSAComponentInstance(OpenDefaultComponent("osa ", "ascr")) # print `codecs.unpack(osac.OSAScriptingComponentName())` # print `codecs.unpack(scpt.ASGetSourceStyleNames(kOSAModeNull))` # osac.OSASetDefaultScriptingComponent('McPy') # print `osac.OSAGetDefaultScriptingComponent()` # exit() # print dir(OpenDefaultComponent('osa ', 'scpt')) id = scpt.OSACompile(codecs.pack("2+2"), 0, 0) id = scpt.OSACompile(codecs.pack("2+2"), 0, 0)
#!/usr/local/bin/python from Carbon.Cm import OpenDefaultComponent from CarbonX.OSA import OSAComponentInstance from CarbonX.kOSA import * from CarbonX.kAE import * from aem import Codecs, AEEventName codecs = Codecs() osac = OSAComponentInstance(OpenDefaultComponent('osa ', 'ascr')) script = ''' property foo : 1 property bar : 42 property name : "hello" on run end on open x end on baz() end on fub() end ''' scriptDesc = codecs.pack(script)
(C) 2005 HAS """ import MacOS from aem import Codecs import OSATerminology as _osat __all__ = ['getsdef', 'getaete', 'getaeut'] ###################################################################### # PRIVATE ###################################################################### _codecs = Codecs() _codecs.decoders['aete'] = _codecs.decoders['aeut'] = lambda desc,app: desc.data ###################################################################### # PUBLIC ###################################################################### def getsdef(path): """Get an application's terminology as sdef XML data, if available. path : str | unicode | FSRef -- full path to app Result : str | None -- XML data, or None if OS version < 10.4 """ return _osat.CopyScriptingDefinition(path) def getaete(path):
def f(val): print 'LOG', `val` installeventhandler(f, 'ascrcmnt', ('----', 'val', kAE.typeWildCard)) from Carbon.Cm import OpenDefaultComponent from CarbonX.OSA import OSAComponentInstance from CarbonX.kAE import * from CarbonX.kOSA import * from CarbonX.AE import * from aem import Codecs, Application codecs = Codecs() osac = OSAComponentInstance(OpenDefaultComponent('osa ', 'ascr')) scriptDesc = codecs.pack(''' --continue foo() log 42 99 ''') fn = osac.OSAGetSendProc() def c(ae, m, p, t): print print 'EVT', `ae.type, ae.data[:64] + (ae.data[64:] and '...' or '')`