public ExternalConsoleProcess(string command, string arguments, string workingDirectory,
                                      IDictionary <string, string> environmentVariables,
                                      string title, bool pauseWhenFinished)
        {
            this.pauseWhenFinished = pauseWhenFinished;

            //build the sh command
            var sb = new StringBuilder();

            sb.AppendFormat("cd \"{0}\"; ", Escape(workingDirectory));

            if (environmentVariables != null)
            {
                foreach (string env in environmentVariables.Keys)
                {
                    sb.AppendFormat("{0}=\"{1}\" ", env, Escape(environmentVariables[env]));
                }
            }
            sb.AppendFormat("{0} {1}", Escape(command), arguments);
            if (pauseWhenFinished)
            {
                sb.Append("; echo; read -p 'Press any key to continue...' -n1");
            }
            sb.Append("; exit");
            var cmd = Escape(sb.ToString());

            //run the command in Terminal.app and extrac tab and window handles
            AppleScript.Run("tell app \"Terminal\" to do script \"{0}\"", LaunchCommandCallback, cmd);

            // Use a timer to stay figure out when the process is done
            timer = new Timer(KillWhenDone, null, 500, 500);
        }
示例#2
0
        internal static void RunTerminal(
            string command, string arguments, string workingDirectory,
            IDictionary <string, string> environmentVariables,
            string title, bool pauseWhenFinished, out string tabId, out string windowId)
        {
            //build the sh command
            var sb = new StringBuilder("clear; ");

            if (!string.IsNullOrEmpty(workingDirectory))
            {
                sb.AppendFormat("cd \"{0}\"; ", Escape(workingDirectory));
            }
            if (environmentVariables != null)
            {
                foreach (string env in environmentVariables.Keys)
                {
                    string val = environmentVariables [env];
                    if (!string.IsNullOrEmpty(val))
                    {
                        val = Escape(val);
                    }
                    sb.AppendFormat("export {0}=\"{1}\"; ", env, val);
                }
            }
            if (command != null)
            {
                sb.AppendFormat("\"{0}\" {1}", Escape(command), arguments);
                if (pauseWhenFinished)
                {
                    sb.Append("; echo; read -p 'Press any key to continue...' -n1");
                }
                sb.Append("; exit");
            }

            //run the command in Terminal.app and extract tab and window IDs
            var ret = AppleScript.Run("tell app \"Terminal\" to do script \"{0}\"", Escape(sb.ToString()));
            int i   = ret.IndexOf("of", StringComparison.Ordinal);

            tabId    = ret.Substring(0, i - 1);
            windowId = ret.Substring(i + 3);

            //rename tab and give it focus
            sb.Clear();
            sb.Append("tell app \"Terminal\"\n");
            if (!string.IsNullOrEmpty(title))
            {
                sb.AppendFormat("\tset custom title of {0} of {1} to \"{2}\"\n", tabId, windowId, Escape(title));
            }
            sb.AppendFormat("\tset frontmost of {0} to true\n", windowId);
            sb.AppendFormat("\tset selected of {0} of {1} to true\n", tabId, windowId);
            sb.Append("\tactivate\n");
            sb.Append("end tell");

            try {
                AppleScript.Run(sb.ToString());
            } catch (AppleScriptException) {
                //it may already have closed
            }
        }
示例#3
0
 /// <summary>
 /// Fügt einen Apfel dem Apfel-Array hinzu
 /// </summary>
 /// <param name="apple">Dem Array hinzuzufügender Apfel</param>
 public void AddApple(AppleScript apple)
 {
     if (AppleList.Count == 4)
     {
         AppleList.Clear();
     }
     this.AppleList.Add(apple);
 }
示例#4
0
        public override void OpenInTerminal(FilePath directory)
        {
            AppleScript.Run(string.Format(
                                @"tell application ""Terminal""
activate
do script with command ""cd {0}""
end tell", directory.ToString().Replace("\"", "\\\"")));
        }
示例#5
0
        public bool OpenProject()
        {
            SyncProject();
            var success = AppleScript.Run(XCODE_OPEN_PROJECT, AppleSdkSettings.XcodePath, projectDir) == "true";

            XC4Debug.Log("Opening project: {0}", success);
            return(success);
        }
示例#6
0
 public bool IsProjectOpen()
 {
     if (!CheckRunning())
     {
         return(false);
     }
     return(AppleScript.Run(XCODE_CHECK_PROJECT_OPEN, AppleSdkSettings.XcodePath, xcproj) == "true");
 }
示例#7
0
        public void TestAppleScript()
        {
            // Include the quotes in the test string because AppleScript is a bit janky
            string testStr = "\"hello world\"";
            string result  = AppleScript.Run("return {0}", testStr);

            Assert.AreEqual(result, testStr);
        }
示例#8
0
 void Start()
 {
     all_apples = new GameObject[apple_num];
     for (int i = 0; i < apple_num; i++)
     {
         all_apples[i] =
             Instantiate(applePrefab, getNewPos(), applePrefab.transform.rotation);
         AppleScript a = all_apples[i].GetComponent <AppleScript>();
         a.manager = this;
     }
 }
示例#9
0
        public bool CloseProject()
        {
            if (!CheckRunning())
            {
                return(true);
            }

            var success = AppleScript.Run(XCODE_CLOSE_IN_PATH, AppleSdkSettings.XcodePath, projectDir) == "true";

            XC4Debug.Log("Closing project: {0}", success);
            return(success);
        }
示例#10
0
        public bool CloseFile(string fileName)
        {
            if (!CheckRunning())
            {
                return(true);
            }

            var success = AppleScript.Run(XCODE_CLOSE_IN_PATH, AppleSdkSettings.XcodePath, fileName) == "true";

            XC4Debug.Log("Closing file {0}: {1}", fileName, success);
            return(success);
        }
        void CloseTerminalWindow()
        {
            try {
                AppleScript.Run(
                    @"tell application ""Terminal""
	activate
	set frontmost of {1} to true
	close {1}
	tell application ""System Events"" to tell process ""Terminal"" to keystroke return
end tell", null, tabId, windowId);
            } catch {}
        }
示例#12
0
        static void CloseTerminalWindow(string tabId, string windowId)
        {
            try {
                AppleScript.Run(
                    @"tell application ""Terminal""
	activate
	set frontmost of {1} to true
	close {1}
	tell application ""System Events"" to tell process ""Terminal"" to keystroke return
end tell", tabId, windowId);
            } catch (AppleScriptException) {
                //it may already have closed
            }
        }
        private void LaunchCommandCallback(string result, Exception ex)
        {
            int i = result.IndexOf("of");

            tabId    = result.Substring(0, i - 1);
            windowId = result.Substring(i + 3);

            //rename tab and give it focus
            AppleScript.Run(
                @"tell app ""Terminal""
					set frontmost of {1} to true
					set selected of {0} of {1} to true
					set custom title of {0} of {1} to ""{2}""
					activate
				end tell"                , null, tabId, windowId, Escape("MonoTools Terminal"));
        }
示例#14
0
        // Note: This method may throw TimeoutException or AppleScriptException
        public void OpenProject(IProgressMonitor monitor)
        {
            SyncProject(monitor);

            monitor.Log.WriteLine("Asking Xcode to open the {0} project...", name);
            try {
                AppleScript.Run(XCODE_OPEN_PROJECT, AppleSdkSettings.XcodePath, projectDir);
                monitor.Log.WriteLine("Xcode successfully opened the {0} project.", name);
            } catch (AppleScriptException asex) {
                monitor.Log.WriteLine("Xcode failed to open the {0} project: OSAError {1}: {2}", name, (int)asex.ErrorCode, asex.Message);
                throw;
            } catch (TimeoutException) {
                monitor.Log.WriteLine("Xcode timed out trying to open the {0} project.", name);
                throw;
            }
        }
示例#15
0
        // Note: This method may throw TimeoutException or AppleScriptException
        public void OpenFile(IProgressMonitor monitor, string relativeName)
        {
            SyncProject(monitor);

            string path = projectDir.Combine(relativeName);

            monitor.Log.WriteLine("Asking Xcode to open '{0}'...", path);
            try {
                AppleScript.Run(XCODE_OPEN_PROJECT_FILE, AppleSdkSettings.XcodePath, xcproj, path);
                monitor.Log.WriteLine("Xcode successfully opened '{0}'", path);
            } catch (AppleScriptException asex) {
                monitor.Log.WriteLine("Xcode failed to open '{0}': OSAError={1}: {2}", path, (int)asex.ErrorCode, asex.Message);
                throw;
            } catch (TimeoutException) {
                monitor.Log.WriteLine("Xcode timed out trying to open '{0}'.", path);
                throw;
            }
        }
        public MacExternalConsoleProcess(string command, string arguments, string workingDirectory,
                                         IDictionary <string, string> environmentVariables,
                                         string title, bool pauseWhenFinished)
        {
            //build the sh command
            var sb = new StringBuilder("clear; ");

            if (!string.IsNullOrEmpty(workingDirectory))
            {
                sb.AppendFormat("cd \"{0}\"; ", Escape(workingDirectory));
            }
            foreach (string env in environmentVariables.Keys)
            {
                string val = environmentVariables[env];
                if (!string.IsNullOrEmpty(val))
                {
                    val = Escape(val);
                }
                sb.AppendFormat("{0}=\"{1}\" ", env, val);
            }
            sb.AppendFormat("\"{0}\" {1}", Escape(command), arguments);
            if (pauseWhenFinished)
            {
                sb.Append("; echo; read -p 'Press any key to continue...' -n1");
            }
            sb.Append("; exit");
            var cmd = Escape(sb.ToString());

            //run the command in Terminal.app and extrac tab and window handles
            var ret = AppleScript.Run("tell app \"Terminal\" to do script \"{0}\"", cmd);
            int i   = ret.IndexOf("of");

            tabId    = ret.Substring(0, i - 1);
            windowId = ret.Substring(i + 3);

            //rename tab and give it focus
            AppleScript.Run(
                @"tell app ""Terminal""
	set custom title of {0} of {1} to ""{2}""
	set frontmost of {1} to true
	set selected of {0} of {1} to true
	activate
end tell", tabId, windowId, Escape(title));
        }
示例#17
0
        // Note: This method may throw TimeoutException or AppleScriptException
        void CloseFile(IProgressMonitor monitor, string fileName)
        {
            if (!CheckRunning())
            {
                return;
            }

            monitor.Log.WriteLine("Asking Xcode to close '{0}'...", fileName);
            try {
                AppleScript.Run(XCODE_CLOSE_IN_PATH, AppleSdkSettings.XcodePath, fileName);
                monitor.Log.WriteLine("Xcode successfully closed '{0}'", fileName);
            } catch (AppleScriptException asex) {
                monitor.Log.WriteLine("Xcode failed to close '{0}': OSAError {1}: {2}", fileName, (int)asex.ErrorCode, asex.Message);
                throw;
            } catch (TimeoutException) {
                monitor.Log.WriteLine("Xcode timed out trying to close '{0}'.", fileName);
                throw;
            }
        }
示例#18
0
        public void CloseProject()
        {
            if (!CheckRunning())
            {
                return;
            }

            XC4Debug.Log("Asking Xcode to close the {0} project...", name);

            try {
                // Exceptions closing the project are non-fatal.
                bool closed = AppleScript.Run(XCODE_CLOSE_IN_PATH, AppleSdkSettings.XcodePath, projectDir) == "true";
                XC4Debug.Log("Xcode {0} the project.", closed ? "successfully closed" : "failed to close");
            } catch (AppleScriptException asex) {
                XC4Debug.Log("Xcode failed to close the project: OSAError {0}: {1}", (int)asex.ErrorCode, asex.Message);
            } catch (TimeoutException) {
                XC4Debug.Log("Xcode timed out trying to close the project.");
            }
        }
示例#19
0
    private void check_col()
    {
        Rigidbody rb = this.GetComponent <Rigidbody>();

        RaycastHit[] hit = rb.SweepTestAll(
            transform.forward,
            // DEBUG
            control_json.move
            // 0.2f
            );
        foreach (RaycastHit h in hit)
        {
            Collider col = h.collider;
            if (col.gameObject.tag == "Apple")
            {
                AppleScript apple_script = h.collider.GetComponent <AppleScript>();
                if (!apple_script.isColliding)
                {
                    gameinfo_json.reward += apple_reward;
                }
                apple_script.hit_mouse();
            }
        }
    }
    public IEnumerator spawn()
    {
        tree.seed *= getPedigree();
        yield return(new WaitForSeconds(tree.spawnSleep));

        GameObject g;
        CellScript t;

        if (ancestors < tree.limit)
        {
            g            = Instantiate(tree.rootCell, transform);
            t            = g.GetComponent <CellScript>();
            t.ancestors  = ancestors + 1;
            t.branches   = branches;
            t.nextBranch = nextBranch;
            t.spawnSide  = spawnSide;
            t.tree       = tree;
            t.parent     = this;
            t.StartCoroutine(t.grow());

            if (branches < tree.branchLimit)
            {
                int num           = ancestors - tree.lowestBranch;
                int branchPenalty = tree.limit / (num == 0?1:num);

                if (branches > 0)
                {
                    for (int i = 0; i < 3; i += 2)
                    {
                        g = Instantiate(tree.leaf, transform);
                        g.transform.rotation *= rotations[i];
                    }
                }

                for (int i = 0; i < 4; i++)
                {
                    if (ancestors > nextBranch && getPedigree() % ((ulong)i + 3ul) == 1)
                    {
                        t.nextBranch          = ancestors + tree.branchGap;
                        g                     = Instantiate(tree.rootCell, transform);
                        g.transform.rotation *= rotations[i];
                        t                     = g.GetComponent <CellScript>();
                        t.spawnSide           = (Side)i;
                        t.ancestors           = ancestors + (branchPenalty * (1 + branches));
                        t.nextBranch          = t.ancestors + tree.lowestBranch;
                        t.branches            = branches + 1;
                        t.tree                = tree;
                        t.parent              = this;
                        yield return(new WaitForEndOfFrame());
                    }
                }
            }
        }

        else if (branches > 0)
        {
            g = Instantiate(tree.apple, transform);
            AppleScript a = g.GetComponent <AppleScript>();
            a.parentCell = this;
        }
    }
 private void KillWhenDone(object state)
 {
     AppleScript.Run("tell app \"Terminal\" to get processes of {0} of {1}", KillCallback, tabId, windowId);
 }
示例#22
0
        internal static Task <int> RunTerminal(
            string command, string arguments, string workingDirectory,
            IDictionary <string, string> environmentVariables,
            string title, bool pauseWhenFinished, out string tabId, out string windowId, CancellationToken cancelToken = default(CancellationToken))
        {
            TaskCompletionSource <int> taskSource = new TaskCompletionSource <int> ();

            cancelToken.Register(delegate {
                taskSource.SetCanceled();
            });
            //build the sh command
            var sb = new StringBuilder("clear; ");

            if (!string.IsNullOrEmpty(workingDirectory))
            {
                sb.AppendFormat("cd \"{0}\"; ", Escape(workingDirectory));
            }
            if (environmentVariables != null)
            {
                foreach (string env in environmentVariables.Keys)
                {
                    string val = environmentVariables [env];
                    if (!string.IsNullOrEmpty(val))
                    {
                        val = Escape(val);
                    }
                    sb.AppendFormat("export {0}=\"{1}\"; ", env, val);
                }
            }

            if (command != null)
            {
                sb.AppendFormat("\"{0}\" {1}", Escape(command), arguments);
                var tempFileName = Path.GetTempFileName();
                sb.Append($"; echo $? > {tempFileName}");
                var fileWatcher = new FileSystemWatcher(Path.GetDirectoryName(tempFileName), Path.GetFileName(tempFileName));
                fileWatcher.EnableRaisingEvents = true;
                fileWatcher.Changed            += delegate {
                    lock (taskSource) {
                        if (taskSource.Task.IsCompleted)
                        {
                            return;
                        }
                        taskSource.SetResult(int.Parse(File.ReadAllText(tempFileName)));
                        File.Delete(tempFileName);
                    }
                };

                if (pauseWhenFinished)
                {
                    sb.Append("; echo; read -p \"Press any key to continue...\" -n1");
                }
                sb.Append("; exit");
            }

            //run the command in Terminal.app and extract tab and window IDs
            string appleScript;

            if (string.IsNullOrEmpty(command))
            {
                appleScript = string.Format("tell app \"{0}\" to do script \"{1}\"", TERMINAL_APP, Escape(sb.ToString()));
            }
            else
            {
                // run the command inside Bash because we do echo $? and that is a bash extension and breaks when people
                // use other shells such as zsh or fish. https://bugzilla.xamarin.com/show_bug.cgi?id=56053
                appleScript = string.Format("tell app \"{0}\" to do script \"bash -c '{1}'; exit\"", TERMINAL_APP, Escape(sb.ToString()));
            }
            var ret = AppleScript.Run(appleScript);
            int i   = ret.IndexOf("of", StringComparison.Ordinal);

            tabId    = ret.Substring(0, i - 1);
            windowId = ret.Substring(i + 3);

            //rename tab and give it focus
            sb.Clear();
            sb.AppendFormat("tell app \"{0}\"\n", TERMINAL_APP);
            if (!string.IsNullOrEmpty(title))
            {
                sb.AppendFormat("\tset custom title of {0} of {1} to \"{2}\"\n", tabId, windowId, Escape(title));
            }
            sb.AppendFormat("\tset frontmost of {0} to true\n", windowId);
            sb.AppendFormat("\tset selected of {0} of {1} to true\n", tabId, windowId);
            sb.Append("\tactivate\n");
            sb.Append("end tell");

            try {
                AppleScript.Run(sb.ToString());
            } catch (Exception ex) {
                taskSource.SetException(ex);
            }
            return(taskSource.Task);
        }
示例#23
0
 static bool TabExists(string tabId, string windowId)
 {
     return(AppleScript.Run("tell app \"{0}\" to get exists of {1} of {2}", TERMINAL_APP, tabId, windowId) == "true");
 }
示例#24
0
 static bool TabExists(string tabId, string windowId)
 {
     return(AppleScript.Run("tell app \"Terminal\" to get exists of {0} of {1}", tabId, windowId) == "true");
 }
示例#25
0
 public void OpenFile(string relativeName)
 {
     XC4Debug.Log("Opening file in Xcode: {0}", relativeName);
     SyncProject();
     AppleScript.Run(XCODE_OPEN_PROJECT_FILE, AppleSdkSettings.XcodePath, xcproj, projectDir.Combine(relativeName));
 }
示例#26
0
 public void OpenProject()
 {
     SyncProject();
     AppleScript.Run(XCODE_OPEN_PROJECT, AppleSdkSettings.XcodePath, xcproj);
 }
示例#27
0
 public void SaveProject()
 {
     AppleScript.Run(XCODE_SAVE_IN_PATH, AppleSdkSettings.XcodePath, projectDir);
 }
示例#28
0
        public void FindMissingTagsAndComments(List <Song> iTunesSongList, Func <Song, bool> compare)
        {
            string top100     = "Top 100";
            Regex  comment    = new Regex("(?<year>^[0-9][0-9][0-9][0-9]), #(?<number>[01][0-9][0-9]).*");
            Regex  badComment = new Regex("^[0-9][0-9][0-9][0-9], #[01][0-9][0-9] [0-9][0-9][0-9][0-9], #[0-9]?[1-9].*");

            var timer = Top100Timer.Start("FindMissingTagsAndComments");

            foreach (Song dbSong in dbSongsList.List.FindAll(x => x.Own.Equals(true) && compare(x)))
            {
                var list = iTunesSongList.FindAll(x => x.IsMatch(dbSong));
                if ((list != null) && (list.Count >= 1))
                {
                    foreach (Song s in list)
                    {
                        bool   updateSong  = false;
                        string appleScript = "tell application \"iTunes\"\n" +
                                             "  activate\n" +
                                             String.Format("  set results to (every file track of playlist \"Library\" whose name contains (\"{0}\") and artist contains (\"{1}\"))\n", scrubString(s.Title), scrubString(s.Artist)) +
                                             "  repeat with t in results\n";
                        if (!s.Grouping.Contains(top100))
                        {
                            appleScript += String.Format("    set t's grouping to \"{0}\" as text\n", addTag(s.Grouping, top100));
                            Top100Util.Debug(String.Format("Missing Grouping: {0}=>{1}", s, addTag(s.Grouping, top100)));
                            updateSong = true;
                        }

                        if (badComment.IsMatch(s.Comments))
                        {
                            appleScript += String.Format("    set t's comment to \"{0}\" as text\n", prependComment(s.Comments, dbSong.Year, dbSong.Number));
                            Top100Util.Debug(String.Format("Bad Comment: {0}=>{1}", s, prependComment(s.Comments, dbSong.Year, dbSong.Number)));
                            updateSong = true;
                        }
                        else if (!comment.IsMatch(s.Comments))
                        {
                            appleScript += String.Format("    set t's comment to \"{0}\" as text\n", prependComment(s.Comments, dbSong.Year, dbSong.Number));
                            Top100Util.Debug(String.Format("Missing Comment: {0}=>{1}", s, prependComment(s.Comments, dbSong.Year, dbSong.Number)));
                            updateSong = true;
                        }
                        else if (comment.IsMatch(s.Comments))
                        {
                            if (dbSong.Number < s.Number)
                            {
                                appleScript += String.Format("    set t's comment to \"{0}\" as text\n", prependComment(s.Comments, dbSong.Year, dbSong.Number));
                                Top100Util.Debug(String.Format("Updating Comment: {0}=>{1}", s, prependComment(s.Comments, dbSong.Year, dbSong.Number)));
                                updateSong = true;
                            }
                        }
                        if (updateSong)
                        {
                            appleScript += "  end repeat\n" + "end tell\n";
                            try
                            {
                                if (!Top100Settings.Preview)
                                {
                                    AppleScript.Run(appleScript);
                                }
                            }
                            catch (Exception e)
                            {
                                Top100Util.Error(String.Format("Cannot update song: {0}\n\tException: {1}\n\tUsing: {2}", s, e, appleScript));
                            }
                        }
                    }
                }
                else
                {
                    Top100Util.Error("Cannot find owned song in Library. " + dbSong);
                }
            }
            timer.End();
        }
 // Note: This method may throw TimeoutException or AppleScriptException
 public void SaveProject(IProgressMonitor monitor)
 {
     monitor.Log.WriteLine("Asking Xcode to save pending changes for the {0} project", name);
     AppleScript.Run(XCODE_SAVE_IN_PATH, AppleSdkSettings.XcodePath, projectDir);
 }
 private void OnEnable()
 {
     current = this;
     Debug.Log("OnEnable currentSet to " + current.ToString());
     //currentRB = this.GetRB();
 }