macOS check if application is running by path












0














I have a path string to application. For example /Users/username/Applications/MyApp.app
All that I need, is to check is it running or not.



I've tried to compare bundle path of running applications with path that I have:



-(BOOL)isApplicationAtPathRunning:(NSString *)applicationPath {
for (NSRunningApplication * application in NSWorkspace.sharedWorkspace.runningApplications) {
if ([application.bundleURL.absoluteString isEqualToString:applicationPath]) {
return YES;
}
}

return NO;
}


But if application was moved to another folder application.bundleURL of running application will be the old one.
Please suggest, thanks!










share|improve this question




















  • 2




    If you just care about the app "identity", you should use NSBundle to get the bundle ID of the app bundle at the path and compare that to the bundle ID (bundleIdentifier) of the NSRunningApplication. If you really care about whether the bundle's executable is the precise file that the process is running even if it's been moved, that will be harder. You may need to run lsof in a subprocess and parse its output.
    – Ken Thomases
    Dec 29 '18 at 16:41










  • Wow, thanks! I think lsof is exactly what I need.
    – Andrew Vergunov
    Jan 2 at 9:08
















0














I have a path string to application. For example /Users/username/Applications/MyApp.app
All that I need, is to check is it running or not.



I've tried to compare bundle path of running applications with path that I have:



-(BOOL)isApplicationAtPathRunning:(NSString *)applicationPath {
for (NSRunningApplication * application in NSWorkspace.sharedWorkspace.runningApplications) {
if ([application.bundleURL.absoluteString isEqualToString:applicationPath]) {
return YES;
}
}

return NO;
}


But if application was moved to another folder application.bundleURL of running application will be the old one.
Please suggest, thanks!










share|improve this question




















  • 2




    If you just care about the app "identity", you should use NSBundle to get the bundle ID of the app bundle at the path and compare that to the bundle ID (bundleIdentifier) of the NSRunningApplication. If you really care about whether the bundle's executable is the precise file that the process is running even if it's been moved, that will be harder. You may need to run lsof in a subprocess and parse its output.
    – Ken Thomases
    Dec 29 '18 at 16:41










  • Wow, thanks! I think lsof is exactly what I need.
    – Andrew Vergunov
    Jan 2 at 9:08














0












0








0







I have a path string to application. For example /Users/username/Applications/MyApp.app
All that I need, is to check is it running or not.



I've tried to compare bundle path of running applications with path that I have:



-(BOOL)isApplicationAtPathRunning:(NSString *)applicationPath {
for (NSRunningApplication * application in NSWorkspace.sharedWorkspace.runningApplications) {
if ([application.bundleURL.absoluteString isEqualToString:applicationPath]) {
return YES;
}
}

return NO;
}


But if application was moved to another folder application.bundleURL of running application will be the old one.
Please suggest, thanks!










share|improve this question















I have a path string to application. For example /Users/username/Applications/MyApp.app
All that I need, is to check is it running or not.



I've tried to compare bundle path of running applications with path that I have:



-(BOOL)isApplicationAtPathRunning:(NSString *)applicationPath {
for (NSRunningApplication * application in NSWorkspace.sharedWorkspace.runningApplications) {
if ([application.bundleURL.absoluteString isEqualToString:applicationPath]) {
return YES;
}
}

return NO;
}


But if application was moved to another folder application.bundleURL of running application will be the old one.
Please suggest, thanks!







objective-c macos nsworkspace






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 29 '18 at 16:11









rmaddy

239k27311376




239k27311376










asked Dec 28 '18 at 11:06









Andrew VergunovAndrew Vergunov

563317




563317








  • 2




    If you just care about the app "identity", you should use NSBundle to get the bundle ID of the app bundle at the path and compare that to the bundle ID (bundleIdentifier) of the NSRunningApplication. If you really care about whether the bundle's executable is the precise file that the process is running even if it's been moved, that will be harder. You may need to run lsof in a subprocess and parse its output.
    – Ken Thomases
    Dec 29 '18 at 16:41










  • Wow, thanks! I think lsof is exactly what I need.
    – Andrew Vergunov
    Jan 2 at 9:08














  • 2




    If you just care about the app "identity", you should use NSBundle to get the bundle ID of the app bundle at the path and compare that to the bundle ID (bundleIdentifier) of the NSRunningApplication. If you really care about whether the bundle's executable is the precise file that the process is running even if it's been moved, that will be harder. You may need to run lsof in a subprocess and parse its output.
    – Ken Thomases
    Dec 29 '18 at 16:41










  • Wow, thanks! I think lsof is exactly what I need.
    – Andrew Vergunov
    Jan 2 at 9:08








2




2




If you just care about the app "identity", you should use NSBundle to get the bundle ID of the app bundle at the path and compare that to the bundle ID (bundleIdentifier) of the NSRunningApplication. If you really care about whether the bundle's executable is the precise file that the process is running even if it's been moved, that will be harder. You may need to run lsof in a subprocess and parse its output.
– Ken Thomases
Dec 29 '18 at 16:41




If you just care about the app "identity", you should use NSBundle to get the bundle ID of the app bundle at the path and compare that to the bundle ID (bundleIdentifier) of the NSRunningApplication. If you really care about whether the bundle's executable is the precise file that the process is running even if it's been moved, that will be harder. You may need to run lsof in a subprocess and parse its output.
– Ken Thomases
Dec 29 '18 at 16:41












Wow, thanks! I think lsof is exactly what I need.
– Andrew Vergunov
Jan 2 at 9:08




Wow, thanks! I think lsof is exactly what I need.
– Andrew Vergunov
Jan 2 at 9:08












1 Answer
1






active

oldest

votes


















2














Better check the application by bundle identifier



-(BOOL)isApplicationWithBundleIdentifierRunning:(NSString *)bundleIdentifier {
NSArray *applications = [NSRunningApplication runningApplicationsWithBundleIdentifier: bundleIdentifier];
return applications.count > 0;
}





share|improve this answer





















  • Thanks for the advise! But if the application was started from another bundle's executable this function will return YES.
    – Andrew Vergunov
    Jan 2 at 9:06











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53957535%2fmacos-check-if-application-is-running-by-path%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














Better check the application by bundle identifier



-(BOOL)isApplicationWithBundleIdentifierRunning:(NSString *)bundleIdentifier {
NSArray *applications = [NSRunningApplication runningApplicationsWithBundleIdentifier: bundleIdentifier];
return applications.count > 0;
}





share|improve this answer





















  • Thanks for the advise! But if the application was started from another bundle's executable this function will return YES.
    – Andrew Vergunov
    Jan 2 at 9:06
















2














Better check the application by bundle identifier



-(BOOL)isApplicationWithBundleIdentifierRunning:(NSString *)bundleIdentifier {
NSArray *applications = [NSRunningApplication runningApplicationsWithBundleIdentifier: bundleIdentifier];
return applications.count > 0;
}





share|improve this answer





















  • Thanks for the advise! But if the application was started from another bundle's executable this function will return YES.
    – Andrew Vergunov
    Jan 2 at 9:06














2












2








2






Better check the application by bundle identifier



-(BOOL)isApplicationWithBundleIdentifierRunning:(NSString *)bundleIdentifier {
NSArray *applications = [NSRunningApplication runningApplicationsWithBundleIdentifier: bundleIdentifier];
return applications.count > 0;
}





share|improve this answer












Better check the application by bundle identifier



-(BOOL)isApplicationWithBundleIdentifierRunning:(NSString *)bundleIdentifier {
NSArray *applications = [NSRunningApplication runningApplicationsWithBundleIdentifier: bundleIdentifier];
return applications.count > 0;
}






share|improve this answer












share|improve this answer



share|improve this answer










answered Dec 29 '18 at 16:42









vadianvadian

144k13154170




144k13154170












  • Thanks for the advise! But if the application was started from another bundle's executable this function will return YES.
    – Andrew Vergunov
    Jan 2 at 9:06


















  • Thanks for the advise! But if the application was started from another bundle's executable this function will return YES.
    – Andrew Vergunov
    Jan 2 at 9:06
















Thanks for the advise! But if the application was started from another bundle's executable this function will return YES.
– Andrew Vergunov
Jan 2 at 9:06




Thanks for the advise! But if the application was started from another bundle's executable this function will return YES.
– Andrew Vergunov
Jan 2 at 9:06


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53957535%2fmacos-check-if-application-is-running-by-path%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas