简体   繁体   中英

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. I also have Parallels installed with Windows 8.1 and Windows Excel 2013.

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.

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.

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 "Microsoft Excel"

        -- Your code

    end tell
end tell

EDIT

It might be something else, outside of Applescript. I've tried two alternatives.

  1. 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
  2. Make sure the default editor for excel-files is the correct program, like shown here:

在此处输入图片说明

You could open it with it's ID, however not sure if the Windows version carries the same generic, for example:

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). To get rid of the "Windows" version I launched "Microsoft Excel" with an apple script. I brought up the contextual menu for the item that launched in the dock, and selected "Show in Finder" from he Options item. 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.

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

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

end tell

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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