AppleScript Tell Application Microsoft Excel 使用 Parallels 在 Mac 上打开 Windows Excel?

AppleScript Tell Application Microsoft Excel Opens Windows Excel on Mac with Parallels?

我正在尝试使用 AppleScript 操作 Mac Excel 2011 年 Macbook Air 运行ning OSX Mavericks 上的文件。我还安装了 Windows 8.1 和 Windows Excel 2013 的 Parallels。

当我 运行 以下测试脚本时,它启动了 Parallels,Windows 8.1 和 Windows Excel 2013 而不是 Mac Excel 2011。它甚至不会始终如一地执行此操作 - 有时它会在提示输入文件后打开 Mac Excel 2011。

这是简单的测试脚本:

set theWorkbookFile to choose file with prompt "Please select an Excel   workbook file:"
set theWorkbookName to name of (info for theWorkbookFile)

tell application "Microsoft Excel"
    open theWorkbookFile

end tell

我尝试将 "Microsoft Excel" 替换为 "Mac Excel",但编译器一直将其改回。

我是不是漏掉了一些简单的东西?

您可以尝试从 tell application "Finder" 中 运行 应用程序,如下所示:

tell application "Finder"
    tell application "Microsoft Excel"

        -- Your code

    end tell
end tell

编辑

它可能是 Applescript 之外的其他东西。我已经尝试了两种选择。

  1. 使用 'hard path',像这样:

    set pathToExcel to "Macintosh HD:Applications:Microsoft Office 2011:Microsoft Excel.app"
    
    tell application pathToExcel
    
        -- Your code
    
    end tell
    
  2. 确保 excel 文件的默认编辑器是正确的程序,如下所示:

您可以使用它的 ID 打开它,但不确定 Windows 版本是否带有相同的通用名称,例如:

set exID to get id of application "Microsoft Excel"
tell application id exID
   make new document
end tell

您可以使用应用程序的路径,如下所示:

tell application "/Applications/Microsoft Office 2011/Microsoft Excel.app"
    open theWorkbookFile
end tell

为了在 Excel 中编写更复杂的操作脚本,我需要摆脱正在启动的 "Windows" 应用程序(尝试使用我的 '"Mac" 应用程序不适合复杂的命令)。为了摆脱 "Windows" 版本,我使用苹果脚本启动了 "Microsoft Excel"。我调出了在停靠栏中启动的项目的上下文菜单,并从选项项目中选择了 "Show in Finder"。然后我退出已经启动的项目,并将其放入垃圾箱。这些 "apps" 的位置似乎因 Parallels 版本而异。

我还在复杂脚本的顶部添加了以下位。我不知道路径是否会保持一致,但如果是这样,这让我有机会在我的脚本开始之前解决问题:

告诉应用程序"Finder" 如果存在 POSIX 文件“/Users/davidacox/Applications (Parallels)/{56aed35f-dfb1-41ea-8ade-aebd86441327} Applications.localized/Microsoft Excel.app” then

    display dialog "The evil excel stub is back"
end if

结束讲述