26

Is there any way to automatically launch an application on USB attach or CD insert on Mac OS X? it's easy on Windows, but I found that AutoRun.Inf does not work on the Mac at all.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Yigang Wu
  • 3,596
  • 5
  • 40
  • 54
  • Lots and lots of keyloggers were implanted because of this. It's impossible on a Mac though! (and it makes me glad!) –  Jun 22 '13 at 18:06

5 Answers5

29

You can't. Autostarting applications is impossible under Mac OS X.

The next-best thing, opening the CD folder and showing the installer icon, can be done by using (AutoOpen version 1.0) to make a .dmg which can then be burnt to a CD.

Edgar
  • 6,022
  • 8
  • 33
  • 66
Sophie Alpert
  • 139,698
  • 36
  • 220
  • 238
  • 10
    And I can't tell you how happy I am that this is so :) – Jason Coco Jan 04 '09 at 07:03
  • 3
    I disagree.. Android File Transfer starts up each time I connect my Android phone. Apparently it is able to have a service that monitors when USB is inserted and then does some action. However, I don't know how Google managed to do it and I just came here to find out where these services might be registered. – Eduard Feicho Jul 16 '14 at 09:37
  • HTC's Sync Manager does this as well, it's annoying, that 's why I found this question! I – Big Rich Jun 19 '15 at 13:08
10

Basically, auto-run is considered a security problem and so is not supported in OSX. Sophie Alpert's answer is also a bit overkill. Most installers for OSX simply open up a folder to show the application and, possibly, a readme. Installing is done by dragging the app to your Applications folder.

For other kinds of apps on CDs (say, a slide show or something like that), the developer generally uses hidden folders to hide support data to ensure that the only thing the user will see when they open the CD is the single icon they're supposed to double click to start the app.

E_net4
  • 27,810
  • 13
  • 101
  • 139
Mike Heinz
  • 1,787
  • 1
  • 17
  • 23
4

It is possible to install a background service that monitors whenever a USB device is plugged in and then launches an App. Google's "Android File Transfer Agent" is such a service that is running in the background and launches "Android File Transfer" whenever you plug in an Android device.

Eduard Feicho
  • 568
  • 4
  • 8
2

If you are looking for something for just yourself, you could write a small mac app that runs in the background and watches for a particular USB device (by id) to be attached and then run the program. Ideally a small XML plist could be used to map device IDs to the correct program to run. The XCode SDK has sample code that monitors for device additional and removal to get you started.

JavaCoderEx
  • 336
  • 2
  • 9
0

I agree with JavaCoderEx. I would crontab a task that looks for /Volumes/*/autorun.sh, then runs it once. Maybe touch a file in /tmp/ so you know its already been run, then remove it if the volume disappears.

tc0nn
  • 61
  • 1
  • 3
  • This should be a comment on JavaCoderEx's answer, not a standalone answer. – Jake Reece Sep 06 '18 at 15:15
  • Granted, but I can't comment as I don't yet have a reputation of 50. How am I supposed to get a reputation of 50 without replying? – tc0nn Sep 07 '18 at 20:00
  • It's a common conundrum for new users. Essentially, users don't get the privilege of commenting until they've answered enough questions (i.e. received 50 rep) to show that they can contribute. People have mixed feelings about the rule because of this exact scenario. That is, you had something meaningful to add, but you couldn't do it the way you're supposed to because you don't have enough rep. You'll get to 50 in no time, though. – Jake Reece Sep 07 '18 at 20:11