Skip to content

Commit 9548a6c

Browse files
committed
Trash app using AppleScript to get around problem caused by Sierra's App Translocation
1 parent fa599d6 commit 9548a6c

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

PFMoveApplication.m

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,23 @@ static BOOL Trash(NSString *path) {
375375
tag:NULL];
376376
}
377377
#endif
378+
379+
// As a last resort try trashing with AppleScript
380+
if (!result) {
381+
NSAppleScript *appleScript = [[[NSAppleScript alloc] initWithSource:
382+
[NSString stringWithFormat:@"\
383+
set theFile to POSIX file \"%@\" \n\
384+
tell application \"Finder\" \n\
385+
move theFile to trash \n\
386+
end tell", path]] autorelease];
387+
NSDictionary *errorDict = nil;
388+
NSAppleEventDescriptor *scriptResult = [appleScript executeAndReturnError:&errorDict];
389+
if (scriptResult == nil) {
390+
NSLog(@"Trash AppleScript error: %@", errorDict);
391+
}
392+
result = (scriptResult != nil);
393+
}
394+
378395
if (!result) {
379396
NSLog(@"ERROR -- Could not trash '%@'", path);
380397
}

0 commit comments

Comments
 (0)