public static Dictionary <string, int> GetFileListFromEventRef(IntPtr eventRef) { AEDesc list = GetEventParameter <AEDesc> (eventRef, CarbonEventParameterName.DirectObject, CarbonEventParameterType.AEList); try { int line = 0; try { SelectionRange range = GetEventParameter <SelectionRange> (eventRef, CarbonEventParameterName.AEPosition, CarbonEventParameterType.Char); line = range.lineNum + 1; } catch { } var arr = AppleEvent.GetListFromAEDesc <string, FSRef> (ref list, (ref FSRef t) => FSRefToPath(ref t), (OSType)(int)CarbonEventParameterType.FSRef); var files = new Dictionary <string, int> (); foreach (var s in arr) { if (!string.IsNullOrEmpty(s)) { files[s] = line; } } return(files); } finally { CheckReturn((int)AppleEvent.AEDisposeDesc(ref list)); } }
private static void ProcessRequests(object sender) { while (true) { Tuple request = GetRequest(); AEDesc sourceData = new AEDesc(); string result; try { //apparently UnicodeText doesn't work AppleEvent.AECreateDescAscii(request.Request, out sourceData); result = Run(true, ref sourceData); if (request.Callback != null) { request.Callback.Invoke(result, null); } } catch (Exception ex) { if (request.Callback != null) { request.Callback.Invoke(null, ex); } } finally { AppleEvent.AEDisposeDesc(ref sourceData); } } }
public static IList <string> GetUrlListFromEventRef(IntPtr eventRef) { AEDesc list = GetEventParameter <AEDesc> (eventRef, CarbonEventParameterName.DirectObject, CarbonEventParameterType.AEList); try { return(AppleEvent.GetUtf8StringListFromAEDesc(ref list, true)); } finally { Carbon.CheckReturn((int)AppleEvent.AEDisposeDesc(ref list)); } }
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); } }
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); } }
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); } } }