【问题标题】:Create AppleScript for a program that isn't installed on the current computer为当前计算机上未安装的程序创建 AppleScript
【发布时间】:2011-06-10 02:40:26
【问题描述】:

我正在尝试制作两份 AppleScript,一份适用于 Entourage,一份适用于 Outlook。我只在当前计算机上安装了 Entourage。

根据微软网站上的信息,两个应用程序都有相同的 AppleScript 命令库,我应该可以简单地更改脚本中引用的应用程序名称。

变化:

Tell application "Microsoft Entourage"

Tell application "Microsoft Outlook"

阻止我保存脚本,因为我没有在这台计算机上安装 Outlook。有没有办法解决?我是否需要使用文本编辑器来编辑实际的脚本文件并在那里进行更改?

谢谢!

【问题讨论】:

    标签: applescript


    【解决方案1】:

    以下解决方法可能会解决问题。在安装 Entourage 的计算机上,using terms 指令将让您编译脚本,即使未安装 Outlook:

    set theApp to a reference to application "Microsoft Outlook"
    using terms from application "Microsoft Entourage"
        tell theApp
            get version
            ...
        end tell
    end using terms from
    

    在编译和保存脚本时,AppleScript 编辑器会提示您缺少 Outlook 应用程序,但它仍然会生成一个已编译的 AppleScript 文件 (.scpt)。

    【讨论】:

      【解决方案2】:

      Applescript 是一种预编译的文件格式,这意味着每次单击“保存”时,它都会运行一系列步骤以确保脚本能够正常工作,但实际上并没有真正运行脚本的逻辑。这些步骤的一部分是查找应用程序以查看它是否存在于 Mac 上。

      简而言之,如果要将脚本保存为Applescript,则需要安装目标应用程序,否则您可以将脚本保存为文本文件并将文件移动到目标Mac以在那里保存为Applescript .

      【讨论】:

        【解决方案3】:

        应该可以制作一个同时适用于 Entourage 和 Outlook 的脚本,而不会在编译或运行时找不到脚本时给您带来麻烦。我没有 Entourage 或 Outlook,但它应该像这样工作:

        using terms from application "Microsoft Entourage"
            script theScript
                tell application "Finder" to try
                    set theApp to application file id "Entourage's Bundle ID" as text
                on error
                    set theApp to application file id "Outlook's Bundle ID" as text
                end try
                tell application theApp
                    -- do stuff
                end tell
            end script
        end using terms from
        store script theScript in "MyScript.scpt"
        

        “使用术语”仅在编译脚本时相关 - 运行时不需要它,但由于某种原因,如果找不到该应用程序,您仍然会遇到错误。因此,通过将其包装在脚本对象周围,然后将该脚本写入文件,生成的脚本仍将运行,但不会包含“使用术语来自”,因此不会给用户带来麻烦。

        为了获得对正确应用程序的引用,Finder 可以通过 ID 查找它,如果找不到它就会简单地出错,而不是给用户带来麻烦。您需要在此处插入正确的 ID,我不知道它们是什么。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-02-28
          • 1970-01-01
          • 2019-10-01
          • 1970-01-01
          相关资源
          最近更新 更多