From 996fbfd6bc17c288b75eb2906ce9bad2b126d2ea Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Wed, 4 Mar 2026 16:14:15 +0100 Subject: [PATCH] chore: remove applescript from trash (#50065) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, when trashItemAtURL: failed (e.g. on network shares or under app translocation), the code fell back to constructing an AppleScript that interpolated the bundle path directly into a string literal via %@ with no escaping. This was fragile and unnecessary — trashItemAtURL: has been the standard API since 10.8 and covers the relevant cases. The fix simply removes the AppleScript fallback entirely, so Trash() now returns the result of trashItemAtURL: directly. Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr --- .../browser/ui/cocoa/electron_bundle_mover.mm | 32 +++---------------- 1 file changed, 4 insertions(+), 28 deletions(-) diff --git a/shell/browser/ui/cocoa/electron_bundle_mover.mm b/shell/browser/ui/cocoa/electron_bundle_mover.mm index 630b98c337..bbc5b3bb78 100644 --- a/shell/browser/ui/cocoa/electron_bundle_mover.mm +++ b/shell/browser/ui/cocoa/electron_bundle_mover.mm @@ -270,34 +270,10 @@ void Relaunch(NSString* destinationPath) { } bool Trash(NSString* path) { - bool result = false; - - if (floor(NSAppKitVersionNumber) >= NSAppKitVersionNumber10_8) { - result = [[NSFileManager defaultManager] - trashItemAtURL:[NSURL fileURLWithPath:path] - resultingItemURL:nil - error:nil]; - } - - // As a last resort try trashing with AppleScript. - // This allows us to trash the app in macOS Sierra even when the app is - // running inside an app translocation image. - if (!result) { - auto* code = R"str( -set theFile to POSIX file "%@" -tell application "Finder" -move theFile to trash -end tell -)str"; - NSAppleScript* appleScript = [[NSAppleScript alloc] - initWithSource:[NSString stringWithFormat:@(code), path]]; - NSDictionary* errorDict = nil; - NSAppleEventDescriptor* scriptResult = - [appleScript executeAndReturnError:&errorDict]; - result = (scriptResult != nil); - } - - return result; + return [[NSFileManager defaultManager] + trashItemAtURL:[NSURL fileURLWithPath:path] + resultingItemURL:nil + error:nil]; } bool DeleteOrTrash(NSString* path) {