I'm trying to work out a way to identify the executable path of a command line tool in Objective C.
Hence, if the executable is /Applications/Utils/MyTool, then that method would return /Applications/Utils
I'm using the Foundation framework.
Call me a purist - or a bundle-hater - if you must.. but I "like"
NSString *myLittleCLIToolPath = NSProcessInfo.processInfo.arguments[0];
I'm assuming that by /Applications/Utils/MyTool
, you mean an application named "MyTool" in the "Utils" directory within the "Application" directory (which is actually the path /Applications/Utils/MyTools.app
). In that case, you could get the directory in which the application resides (/Applications/Utils
) with the following bit of code:
NSString *appParentDirectory = [[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With