【问题标题】:Applescript droplet doesn't run another handlerApplescript droplet 不运行另一个处理程序
【发布时间】:2015-03-18 05:03:08
【问题描述】:

我正在尝试使用下面的代码在 Applescript 中制作一个 droplet 脚本。

我有一个处理程序,它使用所选文件的 POSIX 路径运行命令行。

当我运行脚本时,一切正常(我的命令行处理程序工作正常)。但是,如果我将文件放到我的脚本中,什么都不会发生。

我需要帮助

on run
   set thePath to POSIX path of (choose file of type "img" default location (path to downloads folder from user domain))
   doIt(thePath)
end run

on open myImageFile
    tell application "Finder"
        if (count of myImageFile) is greater than 1 then
            display alert "A message" as critical
        else if name extension of item 1 of myImageFile is not "img"  then
            display alert "A message" as critical
        else
            set thePath to POSIX path of item 1 of myImageFile
            doIt(thePath)
        end if
    end tell
end open

【问题讨论】:

    标签: applescript


    【解决方案1】:

    将打开处理程序中的行:doIt(thePath) 更改为:my doIt(thePath)

    错误的原因是您尝试在 finder 范围内使用您的处理程序,而 finder 并没有将其视为自己的东西。所以必须在前面加上my,才能解析handler。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-16
      • 2011-05-16
      • 2017-02-03
      • 1970-01-01
      相关资源
      最近更新 更多