views:

51

answers:

2

Can I make an apple script that auto runs when I put in my flash drive? I want to be able to do this so that when I put my flash drive in the computer at school I can make my presentation automatically play to save time and so i don't have to go through all my files in front of the class. We use macs at school and I have a mac.

+1  A: 

There's no way using plain AppleScript to receive events when a drive is plugged in.

What you could do is create a poll timer that checks for the drive at a specified interval:

repeat
    set driveName to "YOURDRIVENAME"
    set driveExists to (do shell script "ls /Volumes | grep " & driveName)
    if driveExists contains driveName then
        -- do whatever
    end if
    delay 5
end repeat

I wrote that off the top of my head, and I haven't tested it, but something along those lines should work. delay 5 tells the script to wait 5 seconds before polling again, change this to suit your needs. I haven't tried anything like this with AppleScript before so it may be taxing on resources.

macatomy
Thanks I'll try this.
mtwisterr
+1  A: 

You can activate a Folder Action applescript to watch for newly attached volumes.

Duplicate the script /Library/Scripts/Folder Action Scripts/add - new item alert.scpt and modify the copy to open your presentation or what-have-you.

Activate the script via /Library/Scripts/Folder Actions/Configure Folder Actions (a link to /System/Library/CoreServices/Folder Actions Setup.app):

  1. Launch Configure Folder Actions and enable it with the top check box.
  2. Click the left plus sign to add a folder to watch.
  3. Hit ⇧g (command-shift-g) to navigate to an invisible folder. Type: /Volumes and hit enter
  4. Hit Enter or click the Open button without selecting anything to attach to the /Volumes directory itself.
  5. Choose your modified add - new item alert.scpt from the Attach pane.
Joel Reid