From a644a04b1743cb1302983c08ad9a07f14f5bd86b Mon Sep 17 00:00:00 2001 From: leo Date: Sun, 18 Feb 2024 20:17:44 +0800 Subject: [PATCH] fix: new way to launch Terminal.app --- src/Native/MacOS.cs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/Native/MacOS.cs b/src/Native/MacOS.cs index 8dd89db8..a4aa3ca8 100644 --- a/src/Native/MacOS.cs +++ b/src/Native/MacOS.cs @@ -1,6 +1,7 @@ using System.Diagnostics; using System.IO; using System.Runtime.Versioning; +using System.Text; namespace SourceGit.Native { [SupportedOSPlatform("macOS")] @@ -31,11 +32,20 @@ namespace SourceGit.Native { } public void OpenTerminal(string workdir) { - Process.Start(new ProcessStartInfo() { - WorkingDirectory = workdir, - FileName = "/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal", - UseShellExecute = false, - }); + var dir = string.IsNullOrEmpty(workdir) ? "~" : workdir; + var builder = new StringBuilder(); + builder.AppendLine("on run argv"); + builder.AppendLine(" tell application \"Terminal\""); + builder.AppendLine($" do script \"cd '{dir}'\""); + builder.AppendLine(" activate"); + builder.AppendLine(" end tell"); + builder.AppendLine("end run"); + + var tmp = Path.GetTempFileName(); + File.WriteAllText(tmp, builder.ToString()); + + var proc = Process.Start("/usr/bin/osascript", $"\"{tmp}\""); + proc.Exited += (o, e) => File.Delete(tmp); } public void OpenWithDefaultEditor(string file) {