开发者

auto-run for applescript editor

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 开发者_如何学Cdon't have to go through all my files in front of the class. We use macs at school and I have a mac.


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.


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜