Exemple #1
0
 def aedesc(self):
     if self._desc is None:
         if self._fsref:
             self._desc = AECreateDesc(kAE.typeFSRef, self._fsref.data)
         elif self._fsspec:
             self._desc = AECreateDesc(kAE.typeFSS, self._fsspec.data)
         else:
             self._desc = AECreateDesc(kAE.typeFileURL, self.url)
     return self._desc
Exemple #2
0
def _packLong(val, codecs):
    if (-2**31) <= val < (2**31):  # pack as typeSInt32 if possible (non-lossy)
        return codecs.pack(int(val))
    elif (-2**63) <= val < (
            2**63):  # else pack as typeSInt64 if possible (non-lossy)
        return AECreateDesc(kAE.typeSInt64, struct.pack('q', val))
    else:  # else pack as typeFloat (lossy)
        return codecs.pack(float(val))
Exemple #3
0
def _packStructTime(val, codecs):
    sec = int(time.mktime(val) - _macEpochT)
    return AECreateDesc(kAE.typeLongDateTime, struct.pack('q', sec))
Exemple #4
0
def _packDatetime(val, codecs):
    delta = val - _macEpoch
    sec = delta.days * 3600 * 24 + delta.seconds
    return AECreateDesc(kAE.typeLongDateTime, struct.pack('q', sec))
Exemple #5
0
def _packLong(val, codecs):
    try:
        return AECreateDesc(kAE.typeSInt64, struct.pack(
            'q', val))  # pack as typeSInt64 if possible (non-lossy)
    except OverflowError:
        return codecs.pack(float(val))  # otherwise pack as typeFloat (lossy)
Exemple #6
0
"""

import struct, types, datetime, time
from Carbon import File
from CarbonX import kAE
from CarbonX.AE import AEDesc, AECreateDesc, AECreateList

import macfile

from typewrappers import AEType, AEEnum, AEProp, AEKey, AEEventName

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

_kNullDesc = AECreateDesc(kAE.typeNull, '')
_macEpoch = datetime.datetime(
    1904, 1, 1)  # used in packing datetime objects as AEDesc typeLongDateTime
_macEpochT = time.mktime(_macEpoch.timetuple())
_shortMacEpoch = _macEpoch.date(
)  # used in packing date objects as AEDesc typeLongDateTime

#######
# Packing functions


def _packLong(val, codecs):
    try:
        return AECreateDesc(kAE.typeSInt64, struct.pack(
            'q', val))  # pack as typeSInt64 if possible (non-lossy)
    except OverflowError:
Exemple #7
0
def _makePSNAddressDesc(psn):
	return AECreateDesc(kAE.typeProcessSerialNumber, struct.pack('LL', *psn))
Exemple #8
0
def remoteapp(url):
	"""Make an AEAddressDesc identifying a running application on another machine.
		url : string -- URL for remote application, e.g. 'eppc://*****:*****@0.0.0.1/TextEdit'
		Result : AEAddressDesc
	"""
	return AECreateDesc(kAE.typeApplicationURL, url)
Exemple #9
0
__all__ = ['launchapp', 'isrunning', 'currentapp', 'localapp', 'remoteapp']

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

_launchContinue = 0x4000
_launchNoFileFlags = 0x0800
_launchDontSwitch = 0x0200

_kNoProcess = 0
_kCurrentProcess = 2

_defaultCodecs = Codecs()

_nullAddressDesc = AECreateDesc(kAE.typeProcessSerialNumber, struct.pack('LL', 0, _kNoProcess)) # CarbonX complains if you pass None as address in AECreateAppleEvent, so we give it one to throw away

_launchEvent = Event(_nullAddressDesc, 'ascrnoop').AEM_event
_runEvent = Event(_nullAddressDesc, 'aevtoapp').AEM_event

#######

def _psnForApplicationPath(path):
	# Search through running processes until one with matching path is found. Raises MacOS error -600 if app isn't running.
	highPSN, lowPSN, fsRef = PSN.GetNextProcess(0, 0) # kNoProcess
	while 1:
		try:
			fsRef.FSCompareFSRefs(path) # raises errors unless paths match, or if fsref is None
			break
		except:
			highPSN, lowPSN, fsRef = PSN.GetNextProcess(highPSN, lowPSN) # error -600 if no more processes left
Exemple #10
0
def _packUInt64(n):  # used to pack csig attributes
    return AECreateDesc(kAE.typeUInt32, struct.pack('L', n))
Exemple #11
0
 def aedesc(self):
     if not self._desc:
         self._desc = AECreateDesc(kAE.typeAlias, self._alias.data)
     return self._desc
Exemple #12
0
def localappbypid(pid):
	"""Make an AEAddressDesc identifying a local process.
		pid : integer -- Unix process id
		Result : AEAddressDesc
	"""
	return AECreateDesc(kAE.typeKernelProcessID, struct.pack('L', pid))
Exemple #13
0
def processexistsforurl(url):
	"""Does an application process specified by the given eppc:// URL exist?
		Note: this will send a 'launch' Apple event to the target application.
	"""
	return processexistsfordesc(AECreateDesc(kAE.typeApplicationURL, url))
Exemple #14
0
"""

import struct, types, datetime, time
from Carbon import File
from CarbonX import kAE
from CarbonX.AE import AEDesc, AECreateDesc, AECreateList

import macfile

from typewrappers import AEType, AEEnum, AEProp, AEKey, AEEventName

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

_kNullDesc = AECreateDesc(kAE.typeNull, '')
_macEpoch = datetime.datetime(
    1904, 1, 1)  # used in packing datetime objects as AEDesc typeLongDateTime
_macEpochT = time.mktime(_macEpoch.timetuple())
_shortMacEpoch = _macEpoch.date(
)  # used in packing date objects as AEDesc typeLongDateTime

_trueDesc = AECreateDesc(kAE.typeTrue, '')
_falseDesc = AECreateDesc(kAE.typeFalse, '')

#######
# Packing functions


def _packLong(val, codecs):
    if (-2**31) <= val < (2**31):  # pack as typeSInt32 if possible (non-lossy)
Exemple #15
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')


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