Applescript 编辑器自动运行

发布于 2024-08-22 12:25:01 字数 128 浏览 9 评论 0原文

我可以制作一个苹果脚本,当我放入闪存驱动器时自动运行吗?我希望能够做到这一点,这样当我将闪存驱动器放入学校的计算机中时,我可以自动播放我的演示文稿以节省时间,这样我就不必在全班同学面前浏览所有文件。我们在学校使用 Mac,我也有一台 Mac。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

偷得浮生 2024-08-29 12:25:01

当驱动器插入时,无法使用普通的 AppleScript 接收事件。

您可以做的是创建一个轮询计时器,以指定的时间间隔检查驱动器:

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

我随手写下了这一点,但我还没有测试过它,但沿着这些思路的东西应该有效。 delay 5 告诉脚本在再次轮询之前等待 5 秒,请更改此值以满足您的需要。我以前没有尝试过使用 AppleScript 进行类似的操作,因此它可能会占用资源。

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.

奢望 2024-08-29 12:25:01

您可以激活文件夹操作苹果脚本来监视新附加的卷。

复制脚本/Library/Scripts/Folder Action Scripts/add - new itemalert.scpt并修改副本以打开您的演示文稿或您拥有的内容。

通过/Library/Scripts/Folder Actions/Configure Folder Actions(指向/System/Library/CoreServices/Folder Actions Setup.app的链接)激活脚本:

  1. 启动 >配置文件夹操作并使用顶部复选框启用它。
  2. 单击左侧加号可添加要观看的文件夹。
  3. 按 ⇧g(command-shift-g)导航到不可见的文件夹。键入:/Volumes 并按 Enter 键
  4. 或单击“打开”按钮,而不选择任何内容附加到 /Volumes 目录本身。
  5. 从“附加”窗格中选择修改后的添加 - 新项目alert.scpt

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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文