views:

266

answers:

2

Hi guys i want my application to run from removable storage devices and it should get the path of the removable storage it is running from or the rem storage device from which the app is launched. I have seen nsworkspace to get path of removable storage device but dont know how to get the path at run time.

please suggest a way to do this. also i have searched the net and came to know that there is no autorun feature on mac systems. I want my app to auto launch itself whenever a removable storage is attached to a mac system. is there any workaround for this?

Thanks

+5  A: 

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

From there, you'll need to use the NSFileManager APIs to enumerate the volumes and figure out which one your app is on and whether it meets your criteria for removable-ness. The APIs have been updated significantly in Snow Leopard.

An aside; this is a distinctly odd requirement for an application. Atypical, to say the least.

bbum
Alternatively, `[[NSBundle mainBundle] executablePath]` if you're running a FoundationTool.
Dave DeLong
Thanks guys for the replys
King
+3  A: 

To your second question of an autorun feature, there are several techniques for detecting that a volume has been mounted and then using that to trigger an action (like launching a program). But all of them require that your software has already been installed so that you can run a daemon to watch for volume mounts. I am not suggesting that a program should do such a thing (it almost never should), but it is a technique. I suspect this is not what you're asking.

The questionable feature of having the system automatically run something based on a volume mount was removed with the release of OS X. It is almost inconceivable that such a behavior would be re-added. It is an invitation to a wide variety of abuses, with very little benefit for the user. OS X will open a Finder window when a new volume is mounted, and you are free to provide a helpful background image for your root directory that will instruct the user on how to launch your app.

Rob Napier
Thank you Rob for the reply
King