File tree Expand file tree Collapse file tree 1 file changed +10
-5
lines changed
Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -159,13 +159,18 @@ void PFMoveToApplicationsFolderIfNecessary() {
159159 // If a copy already exists in the Applications folder, put it in the Trash
160160 if ([fm fileExistsAtPath: destinationPath]) {
161161 // But first, make sure that it's not running
162- NSString *script = [NSString stringWithFormat: @" ps ax -o comm | grep '%@ /' | grep -v grep >/dev/null" , destinationPath];
163- NSTask *task = [NSTask launchedTaskWithLaunchPath: @" /bin/sh" arguments: [NSArray arrayWithObjects: @" -c" , script, nil ]];
164- [task waitUntilExit ];
165-
162+ BOOL destinationIsRunning = NO ;
163+ for (NSRunningApplication *runningApplication in [[NSWorkspace sharedWorkspace ] runningApplications ]) {
164+ NSString *executablePath = [[runningApplication executableURL ] path ];
165+ if ([[executablePath substringToIndex: [destinationPath length ]] isEqualToString: destinationPath]) {
166+ destinationIsRunning = YES ;
167+ break ;
168+ }
169+ }
170+
166171 // If the task terminated with status 0, it means that the final grep produced 1 or more lines of output.
167172 // It means that the app is already running
168- if ([task terminationStatus ] == 0 ) {
173+ if (destinationIsRunning ) {
169174 // Give the running app focus and terminate myself
170175 NSLog (@" INFO -- Switching to an already running version" );
171176 [[NSTask launchedTaskWithLaunchPath: @" /usr/bin/open" arguments: [NSArray arrayWithObject: destinationPath]] waitUntilExit ];
You can’t perform that action at this time.
0 commit comments