[英]AppleScript Tell Application Microsoft Excel Opens Windows Excel on Mac with Parallels?
I am trying to use AppleScript to manipulate Mac Excel 2011 files on a Macbook Air running OSX Mavericks.我正在尝试使用 AppleScript 在运行 OSX Mavericks 的 Macbook Air 上操作 Mac Excel 2011 文件。 I also have Parallels installed with Windows 8.1 and Windows Excel 2013.
我还安装了 Windows 8.1 和 Windows Excel 2013 的 Parallels。
When I run the following test script, it starts up Parallels, Windows 8.1 and Windows Excel 2013 instead of Mac Excel 2011. It doesn't even do this consistently - sometimes it will open Mac Excel 2011 after prompting for a file.当我运行以下测试脚本时,它会启动 Parallels、Windows 8.1 和 Windows Excel 2013 而不是 Mac Excel 2011。它甚至不会始终如一地执行此操作 - 有时它会在提示输入文件后打开 Mac Excel 2011。
Here's the simple test script:这是简单的测试脚本:
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
I tried replacing "Microsoft Excel" with "Mac Excel" but the compiler keeps changing it back.我尝试用“Mac Excel”替换“Microsoft Excel”,但编译器不断将其改回。
Am I missing something simple here?我在这里错过了一些简单的东西吗?
You can use the path of the application, like this :您可以使用应用程序的路径,如下所示:
tell application "/Applications/Microsoft Office 2011/Microsoft Excel.app"
open theWorkbookFile
end tell
You could try to run the application from inside a tell application "Finder"
, like this:您可以尝试从
tell application "Finder"
内部运行该应用tell application "Finder"
,如下所示:
tell application "Finder"
tell application "Microsoft Excel"
-- Your code
end tell
end tell
EDIT编辑
It might be something else, outside of Applescript.它可能是 Applescript 之外的其他东西。 I've tried two alternatives.
我已经尝试了两种选择。
Use a 'hard path', like so:使用“硬路径”,如下所示:
set pathToExcel to "Macintosh HD:Applications:Microsoft Office 2011:Microsoft Excel.app" tell application pathToExcel -- Your code end tell
Make sure the default editor for excel-files is the correct program, like shown here:确保 excel 文件的默认编辑器是正确的程序,如下所示:
You could open it with it's ID, however not sure if the Windows version carries the same generic, for example:您可以使用它的 ID 打开它,但不确定 Windows 版本是否具有相同的通用性,例如:
set exID to get id of application "Microsoft Excel"
tell application id exID
make new document
end tell
In order to script the more complex actions in Excel, I needed to get rid of the "Windows" application that was launching (the work around of trying to use the path to my '"Mac" application was not good for complex commands).为了在 Excel 中编写更复杂的操作脚本,我需要摆脱正在启动的“Windows”应用程序(尝试使用我的“Mac”应用程序的路径的解决方法不适用于复杂的命令)。 To get rid of the "Windows" version I launched "Microsoft Excel" with an apple script.
为了摆脱“Windows”版本,我用苹果脚本启动了“Microsoft Excel”。 I brought up the contextual menu for the item that launched in the dock, and selected "Show in Finder" from he Options item.
我调出了在 Dock 中启动的项目的上下文菜单,并从选项项目中选择了“在 Finder 中显示”。 I then quit the item that had launched, and put it in the trash.
然后我退出了已启动的项目,并将其放入垃圾箱。 The location of these "apps" seem to change from version to version of Parallels.
这些“应用程序”的位置似乎随着 Parallels 的版本而变化。
I also added the following bit to the top of my complex script.我还在复杂脚本的顶部添加了以下内容。 I don't know if the path will remain consistent or not, but in case it does, this gives me a chance to fix the issue before my script starts:
我不知道路径是否会保持一致,但如果是这样,这让我有机会在脚本开始之前解决问题:
tell application "Finder" if exists POSIX file "/Users/davidacox/Applications (Parallels)/{56aed35f-dfb1-41ea-8ade-aebd86441327} Applications.localized/Microsoft Excel.app" then告诉应用程序“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
end tell结束告诉
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.