Reputation: 335
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.
Upvotes: 0
Views: 1851
Reputation: 993
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):
Upvotes: 1
Reputation: 18132
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.
Upvotes: 1