簡體   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