繁体   English   中英

AppleScript Tell 应用程序 Microsoft Excel 使用 Parallels 在 Mac 上打开 Windows Excel?

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

我正在尝试使用 AppleScript 在运行 OSX Mavericks 的 Macbook Air 上操作 Mac Excel 2011 文件。 我还安装了 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

我尝试用“Mac Excel”替换“Microsoft Excel”,但编译器不断将其改回。

我在这里错过了一些简单的东西吗?

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

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

您可以尝试从tell application "Finder"内部运行该应用tell application "Finder" ,如下所示:

tell application "Finder"
    tell application "Microsoft Excel"

        -- Your code

    end tell
end tell

编辑

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

  1. 使用“硬路径”,如下所示:

     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

为了在 Excel 中编写更复杂的操作脚本,我需要摆脱正在启动的“Windows”应用程序(尝试使用我的“Mac”应用程序的路径的解决方法不适用于复杂的命令)。 为了摆脱“Windows”版本,我用苹果脚本启动了“Microsoft Excel”。 我调出了在 Dock 中启动的项目的上下文菜单,并从选项项目中选择了“在 Finder 中显示”。 然后我退出了已启动的项目,并将其放入垃圾箱。 这些“应用程序”的位置似乎随着 Parallels 的版本而变化。

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

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

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

结束告诉

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM