【问题标题】:Run Apple Script before application start?在应用程序启动之前运行 Apple 脚本?
【发布时间】:2018-08-09 11:25:05
【问题描述】:

想知道当我在 OS X 上启动应用程序时是否有任何方法可以运行一小段苹果脚本? 我有一个需要安装的硬盘驱动器才能使应用程序正常运行。我已经做了这个苹果脚本:

on run
try

    do shell script "diskutil mountDisk disk2"

    delay 3
    tell application "Application"
        run
    end tell

on error
    tell application "Application"
        quit
    end tell
    set question to display dialog "Error." buttons {"OK"}
    set answer to button returned of question
    if answer is equal to "OK" then
        close
    end if

end try
end run

但即使这样效果很好,并且硬盘驱动器会在应用程序启动之前启动。 我想添加diskutil mountDisk disk2 并在实际应用程序启动时直接延迟,这样我就可以双击该应用程序的文件,例如在我的下载文件夹中。它将在打开应用程序中单击的文件之前运行脚本。因此,每次我为它下载新文件时,我都不必使用另一个应用程序启动该应用程序。这甚至可能吗?

【问题讨论】:

  • 您可以运行fswatch(可以使用homebrew 安装)并监控您的应用程序的可执行二进制文件以查看它何时打开,然后运行您的@987654325 @命令...希望你能及时到达那里。这里有一些相关stackoverflow.com/a/47978505/2836621
  • 我使用的解决方法是创建首先运行 diskutil 的 applescript,然后打开应用程序。我从文档中删除了应用程序图标并将其替换为脚本的图标。我总是点击这个脚本来启动脚本和应用程序。

标签: macos applescript mount automator


【解决方案1】:

很快:

这是不可能,除非应用程序本身支持某些inhookouthook功能。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-11
    • 2020-09-19
    • 1970-01-01
    • 2021-03-30
    相关资源
    最近更新 更多