diff --git a/scripts/SettingsManager.cs b/scripts/SettingsManager.cs
index dc99e357..955d4ab9 100644
--- a/scripts/SettingsManager.cs
+++ b/scripts/SettingsManager.cs
@@ -6,6 +6,7 @@
using System.Text.RegularExpressions;
using Godot;
using Godot.Collections;
+using util;
[GlobalClass]
public partial class SettingsManager : Node
@@ -269,11 +270,10 @@ private static void restartGame()
OS.CreateProcess("powershell.exe", ["-Command", $"Wait-Process -Id {pid}; Start-Process '{executablePath}'"]);
break;
case "macOS":
- string executablePathMac = Path.Combine(executablePath, "../..");
- OS.CreateProcess("/bin/sh", [$"while kill -0 {pid} 2>/dev/null; do sleep 0.1; done; open {executablePathMac}"]);
+ OS.CreateProcess("/bin/sh", ["-c", $"{Platform.WaitForExitScript}; open {Platform.ShellQuote(Platform.MacAppBundlePath)}"]);
break;
case "Linux":
- OS.CreateProcess("/bin/sh", [$"while kill -0 {pid} 2>/dev/null; do sleep 0.1; done; exec {executablePath}"]);
+ OS.CreateProcess("/bin/sh", ["-c", $"{Platform.WaitForExitScript}; exec {Platform.ShellQuote(executablePath)}"]);
break;
}
diff --git a/scripts/util/Platform.cs b/scripts/util/Platform.cs
new file mode 100644
index 00000000..593d4669
--- /dev/null
+++ b/scripts/util/Platform.cs
@@ -0,0 +1,22 @@
+using System.IO;
+using Godot;
+
+namespace util;
+
+public static class Platform
+{
+ ///
+ /// Path to the running .app bundle on macOS, the executable lives at Rhythia.app/Contents/MacOS/Rhythia
+ ///
+ public static string MacAppBundlePath => Path.GetFullPath(Path.Combine(OS.GetExecutablePath(), "../../.."));
+
+ ///
+ /// Wraps a value in single quotes so it is passed to /bin/sh as one literal argument
+ ///
+ public static string ShellQuote(string value) => $"'{value.Replace("'", "'\\''")}'";
+
+ ///
+ /// Shell snippet that blocks until the current process has exited
+ ///
+ public static string WaitForExitScript => $"while kill -0 {OS.GetProcessId()} 2>/dev/null; do sleep 0.1; done";
+}
diff --git a/scripts/util/Platform.cs.uid b/scripts/util/Platform.cs.uid
new file mode 100644
index 00000000..8124b9d7
--- /dev/null
+++ b/scripts/util/Platform.cs.uid
@@ -0,0 +1 @@
+uid://d0b88m1ycctvg