1

Microsoft outlook我们有一个脚本可以使用或应用程序发送电子邮件Apple mail。它将从系统首选项(也可能是用户输入)动态加载默认电子邮件,并使用它来决定使用哪个邮件客户端。

所以代码如下:

if (mailClientStr contains "outlook")
   tell application id "com.microsoft.outlook" 
   -- <<< there will be error if there is no outlook installed 
   -- <<< even else branch will be run.
      ...
   end tell
else
   tell application id "com.apple.mail"
      ...
   end tell
end if

在没有安装 Outlook 的机器上,mailClientStr将是“com.apple.mail”,但此脚本无法运行osascript

它抱怨Can’t get application id "com.microsoft.outlook"即使第一个分支也不会被执行。我的理解是osascript在加载和编译这个脚本时(在运行它之前)需要访问 Outlook 苹果脚本界面。

我可以将outlook相关的代码分离成一个单独的脚本,但是因为要传递的数据很多,会比较复杂,所以我不想要这个变通方法。那么苹果脚本语言方面有什么解决方案吗?

4

1 回答 1

0

来自 AppleScript 语言指南:

Entering Script Information in Raw Format

You can enter double angle brackets, or chevrons («»), directly into a script by typing Option-Backslash and Shift-Option-Backslash. You might want to do this if you’re working on a script that needs to use terminology that isn’t available on your current machine—for example, if you’re working at home and don’t have the latest dictionary for a scriptable application you are developing, but you know the codes for a supported term.

You can also use AppleScript to display the underlying codes for a script, using the following steps:

    Create a script using standard terms compiled against an available application or scripting addition.

    Save the script as text and quit Script Editor.

    Remove the application or scripting addition from the computer.

    Open the script again and compile it.

    When AppleScript asks you to locate the application or scripting addition, cancel the dialog.

Script Editor can compile the script, but displays chevron format for any terms that rely on a missing dictionary
于 2013-11-11T11:58:21.827 回答