Getting the application path at runtime + cocoa

I want my application to start from removable storage devices, and it should get the path to the removable storage on which it runs, or to the storage device from which the application starts. I saw how nsworkspace gets the path to a removable storage device, but doesn't know how to get the path at runtime.

suggest a way to do this. I also searched the network and found out that on Mac systems there is no autostart function. I want my application to start automatically when removable storage is connected to the Mac system. is there any workaround for this?

thanks

+4
source share
2 answers

[[NSBundle mainBundle] bundlePath] will give you the path to your .app wrapper.

From there, you will need to use the NSFileManager to list the volumes and determine which application is included and whether it meets your criteria for removal. The APIs have been significantly updated in Snow Leopard.

Aside; This is clearly an odd requirement for the application. Atypical, at least.

+9
source

To your second question about autostart function, there are several ways to detect that a volume has been mounted and then used to start an action (for example, starting a program). But all of them require that your software is already installed, so that you can run the daemon to view volumes. I do not assume that a program should do such a thing (it almost never should), but it is a method. I suspect this is not what you are asking for.

The issue that the system automatically starts something based on the volume has been removed with the release of OS X. It is almost impossible to imagine that such behavior was re-added. This is an invitation to a wide range of abuses, and the user has very little benefit. OS X will open the Finder window when a new volume is installed, and you can provide a useful background image for your root directory that will instruct the user on how to start the application.

+5
source

All Articles