コード例 #1
0
        public static string Run(byte[] compiledBytes)
        {
            AEDesc sourceData = new AEDesc();

            try {
                AppleEvent.AECreateDesc((OSType)(int)OsaType.OsaGenericStorage, compiledBytes, out sourceData);
                return(Run(false, ref sourceData));
            } finally {
                AppleEvent.AEDisposeDesc(ref sourceData);
            }
        }
コード例 #2
0
        public static string Run(string scriptSource)
        {
            AEDesc sourceData = new AEDesc();

            try {
                //apparently UnicodeText doesn't work
                AppleEvent.AECreateDescAscii(scriptSource, out sourceData);
                return(Run(true, ref sourceData));
            } finally {
                AppleEvent.AEDisposeDesc(ref sourceData);
            }
        }
コード例 #3
0
        public static T AEGetNthPtr <T> (ref AEDesc descList, int index, OSType desiredType) where T : struct
        {
            int    len       = Marshal.SizeOf(typeof(T));
            IntPtr bufferPtr = Marshal.AllocHGlobal(len);

            try {
                CheckReturn(AEGetNthPtr(ref descList, index, desiredType, 0, 0, bufferPtr, len, 0));
                T val = (T)Marshal.PtrToStructure(bufferPtr, typeof(T));
                return(val);
            } finally{
                Marshal.FreeHGlobal(bufferPtr);
            }
        }
コード例 #4
0
        public static T[] GetListFromAEDesc <T, TRef> (ref AEDesc list, AEDescValueSelector <TRef, T> sel, OSType type)
            where TRef : struct
        {
            long count = AppleEvent.AECountItems(ref list);

            T[] arr = new T[count];
            for (int i = 1; i <= count; i++)
            {
                TRef r = AppleEvent.AEGetNthPtr <TRef> (ref list, i, type);
                arr [i - 1] = sel(ref r);
            }
            return(arr);
        }
コード例 #5
0
        static string Run(bool compile, ref AEDesc scriptData)
        {
            string value;
            var    ret = Run(compile, ref scriptData, out value);

            if (ret == OsaError.Success)
            {
                return(value);
            }
            else
            {
                throw new Exception(string.Format("Error {0}: {1}", ret, value));
            }
        }
コード例 #6
0
        public static IList <string> GetUtf8StringListFromAEDesc(ref AEDesc list, bool skipEmpty)
        {
            long count = AppleEvent.AECountItems(ref list);
            var  items = new List <string> ();

            for (int i = 1; i <= count; i++)
            {
                string str = AppleEvent.GetUtf8StringFromAEPtr(ref list, i);
                if (!string.IsNullOrEmpty(str))
                {
                    items.Add(str);
                }
            }
            return(items);
        }
コード例 #7
0
        public static string GetStringFromAEDesc(ref AEDesc desc)
        {
            int size = AEGetDescDataSize(ref desc);

            if (size > 0)
            {
                IntPtr buffer = Marshal.AllocHGlobal(size);
                try {
                    if (AEGetDescData(ref desc, buffer, size) == AEDescStatus.Ok)
                    {
                        return(Marshal.PtrToStringAuto(buffer, size));
                    }
                } finally {
                    Marshal.FreeHGlobal(buffer);
                }
            }
            return(null);
        }
コード例 #8
0
        //FIXME: this might not work in some encodings. need to test more.
        static string GetUtf8StringFromAEPtr(ref AEDesc descList, int index)
        {
            int size;
            var type = (OSType)(int)CarbonEventParameterType.UnicodeText;

            if (AESizeOfNthItem(ref descList, index, ref type, out size) == AEDescStatus.Ok)
            {
                IntPtr buffer = Marshal.AllocHGlobal(size);
                try {
                    if (AEGetNthPtr(ref descList, index, type, 0, 0, buffer, size, 0) == AEDescStatus.Ok)
                    {
                        return(Marshal.PtrToStringAuto(buffer, size));
                    }
                } finally {
                    Marshal.FreeHGlobal(buffer);
                }
            }
            return(null);
        }
コード例 #9
0
 static extern OsaError OSAScriptError(ComponentInstance scriptingComponent, OsaErrorSelector selector,
                                       DescType desiredType, out AEDesc resultingErrorDescription);
コード例 #10
0
 static extern OsaError OSALoad(ComponentInstance scriptingComponent, ref AEDesc sourceData,
                                OsaMode modeFlags, ref OsaId previousAndResultingScriptID);
コード例 #11
0
 static extern OsaError OSALoadExecute(ComponentInstance scriptingComponent, ref AEDesc scriptData,
                                       OsaId contextID, OsaMode modeFlags, ref OsaId resultingScriptValueID);
コード例 #12
0
 static extern OsaError OSADoScript(ComponentInstance scriptingComponent, ref AEDesc sourceData,
                                    OsaId contextID, DescType desiredType, OsaMode modeFlags,
                                    ref AEDesc resultingText);
コード例 #13
0
 static extern OsaError OSADisplay(ComponentInstance scriptingComponent, OsaId scriptValueID,
                                   DescType desiredType, OsaMode modeFlags, out AEDesc resultingText);
コード例 #14
0
 static extern AEDescStatus AECreateDesc(OSType typeCode, IntPtr dataPtr, int dataSize, out AEDesc desc);
コード例 #15
0
        static OsaError Run(bool compile, ref AEDesc scriptData, out string value)
        {
            var component = ComponentManager.OpenDefaultComponent((OSType)(int)OsaType.OsaComponent, (OSType)(int)OsaType.AppleScript);

            if (component.IsNull)
            {
                throw new Exception("Could not load component");
            }
            AEDesc resultData = new AEDesc();
            OsaId  contextId = new OsaId(), scriptId = new OsaId(), resultId = new OsaId();

            try {
                AppleEvent.AECreateDescNull(out resultData);
                //apparently UnicodeText doesn't work
                var resultType = new DescType()
                {
                    Value = (OSType)"TEXT"
                };

                //var result = OSADoScript (component, ref sourceData, contextId, resultType, OsaMode.Default, ref resultData);

                OsaError result;
                if (compile)
                {
                    result = OSACompile(component, ref scriptData, OsaMode.Default, ref scriptId);
                }
                else
                {
                    result = OSALoad(component, ref scriptData, OsaMode.Default, ref scriptId);
                }

                if (result == OsaError.Success)
                {
                    result = OSAExecute(component, scriptId, contextId, OsaMode.Default, out resultId);
                    if (result == OsaError.Success)
                    {
                        result = OSADisplay(component, resultId, resultType, OsaMode.Default, out resultData);
                        if (result == OsaError.Success)
                        {
                            value = AppleEvent.GetStringFromAEDesc(ref resultData);
                            return(result);
                        }
                    }
                }
                AEDesc errorDesc = new AEDesc();
                try {
                    AppleEvent.AECreateDescNull(out resultData);
                    if (OsaError.Success == OSAScriptError(component, OsaErrorSelector.Message, resultType, out errorDesc))
                    {
                        value = AppleEvent.GetStringFromAEDesc(ref errorDesc);
                        return(result);
                    }
                    else
                    {
                        throw new InvalidOperationException(string.Format("Unexpected result {0}", (long)result));
                    }
                } finally {
                    AppleEvent.AEDisposeDesc(ref errorDesc);
                }
            } finally {
                AppleEvent.AEDisposeDesc(ref scriptData);
                AppleEvent.AEDisposeDesc(ref resultData);
                if (!contextId.IsZero)
                {
                    OSADispose(component, contextId);
                }
                if (!scriptId.IsZero)
                {
                    OSADispose(component, scriptId);
                }
                if (!resultId.IsZero)
                {
                    OSADispose(component, resultId);
                }
                if (!component.IsNull)
                {
                    ComponentManager.CloseComponent(component);
                }
            }
        }
コード例 #16
0
 public static void AECreateDesc(OSType typeCode, byte[] data, out AEDesc result)
 {
     CheckReturn(AECreateDesc(typeCode, data, data.Length, out result));
 }
コード例 #17
0
 public static void AECreateDescNull(out AEDesc desc)
 {
     CheckReturn(AECreateDesc((OSType)0, IntPtr.Zero, 0, out desc));
 }
コード例 #18
0
 static extern AEDescStatus AEGetNthPtr(ref AEDesc descList, int index, OSType desiredType, uint keyword,
                                        out CarbonEventParameterType actualType, IntPtr buffer, int bufferSize, out int actualSize);
コード例 #19
0
 static extern AEDescStatus AECreateDesc(OSType typeCode, byte[] data, int dataSize, out AEDesc desc);
コード例 #20
0
 static extern AEDescStatus AEGetDescData(ref AEDesc desc, IntPtr ptr, int maximumSize);
コード例 #21
0
 public static extern AEDescStatus AESizeOfNthItem(ref AEDesc descList, int index, ref OSType type, out int size);
コード例 #22
0
 public static extern AEDescStatus AEDisposeDesc(ref AEDesc desc);
コード例 #23
0
 static extern AEDescStatus AEGetNthPtr(ref AEDesc descList, int index, OSType desiredType, uint keyword,
                                        uint zero, out IntPtr outPtr, int bufferSize, int zero2);
コード例 #24
0
 static extern AEDescStatus AECountItems(ref AEDesc descList, out int count);          //return an OSErr
コード例 #25
0
 static extern int AEGetDescDataSize(ref AEDesc desc);
コード例 #26
0
 static extern AEDescStatus AECoerceDesc(ref AEDesc theAEDesc, DescType toType, ref AEDesc result);