Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting the path of a application at runtime + cocoa

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

like image 362
King Avatar asked Dec 08 '22 06:12

King


2 Answers

[[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.

like image 116
bbum Avatar answered Jan 21 '23 12:01

bbum


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.

like image 43
Rob Napier Avatar answered Jan 21 '23 12:01

Rob Napier