How can I get a sound to play when I insert a specific USB key ?

Discussion in 'Mac Basics and Help' started by Neyiox, Jul 16, 2017.

Tags:
  1. Neyiox macrumors newbie

    Neyiox

    Joined:
    Jul 16, 2017
    #1
    Hi everyone,

    This is my first post on the forum and I would need some answers for a problem.

    Everything is in the title! I recently bought an USB key of BB-8 (Star Wars) and I would like to get a sound (that I already have) when I insert my key.

    I'm under Sierra 10.12.5

    Thank you in advance for your answers which I hope will help me.

    Good night!
     
  2. organicCPU, Jul 19, 2017
    Last edited: Jul 19, 2017

    organicCPU macrumors 6502

    organicCPU

    Joined:
    Aug 8, 2016
    #2
    AFAIK, there is no such easy solution on a Mac like writing an autorun.inf on Windows.
    Maybe better ask this at the programmers forum.

    I guess writing a Launch Daemon to watch the USB key insertion would be best practice over running some other kind of background app. Then you could involve an AppleScript or some other script to play the sound.

    A specific volume can be identified by its UUID. To get it, plug-in your USB key and type the following in Terminal with the proper name of your USB key
    Code:
    diskutil info /Volumes/NameOfUSBDrive | grep UUID
    To get an idea for the Launch Daemon take a look here:
    https://stackoverflow.com/questions...when-a-particular-type-of-usb-device-is-conne
    https://developer.apple.com/library...stemStartup/Chapters/CreatingLaunchdJobs.html

    For the AppleScript something like this could work:
    http://www.leancrew.com/all-this/2007/12/playing-sounds-in-applescript/

    Edit: better than a third party sound app to play the sound is the use of built-in afplay
    https://discussions.apple.com/thread/2408021

    Hope this helps to get the direction.
     
  3. Neyiox thread starter macrumors newbie

    Neyiox

    Joined:
    Jul 16, 2017
    #3
    Thank you for your answer!

    I'm gonna check this even if I'm not an expert in code
     

Share This Page