4

In earlier iterations of macOS I would use

open -a Finder.app <filename>

In Sonoma that is resulting in two of the following dialog boxes :

The application "Microsoft Word" can't be opened
-128

enter image description here

Note: the same document can be successfully opened directly from Finder.app by double clicking or hitting CMD-O . So Word is functioning properly and the document is intact.

I did look at some microsoft-learn pages and they do not address this scenario.

How to open a Microsoft Word document from the commandline in Sonoma?

bmike
  • 235,889
  • 4
    What's wrong with open path/to/doc? Also see https://apple.stackexchange.com/questions/212583/how-to-open-files-in-another-app-via-terminal-on-macos – Tetsujin Jan 28 '24 at 18:12
  • @Tetsujin That actually works in sonoma: it did not in earlier iterations of macOS. – WestCoastProjects Jan 28 '24 at 21:50
  • 2
    It worked in 2015, as per the linked answer! – benwiggy Jan 29 '24 at 08:04
  • @WestCoastProjects It's essentially equivalent to double clicking on the document, so it should have worked forever. The only issue would be if you changed the "open with" application for the document. – Barmar Jan 29 '24 at 15:38

2 Answers2

14

I think that -a Finder.app is an incorrect syntax. You don't want to open it 'in' the Finder, you want to open it in Word.

The following works for me in Sonoma:

open -a "Microsoft Word.app" document.docx

open document.docx (as Word is the default).

That having been said, open -a Finder.app document.docx also works for me in Sonoma, briefly revealing a Finder window of the enclosing folder, before Word then launches and the file is loaded.

Obviously, this is for a document.docx that's in the current directory, or contains a full filepath.

It's possible that it's not working for you because of a Launch Services DB corruption, or a file cache or something.

benwiggy
  • 35,635
  • The open -a <app name> syntax has apparently changed. I used Finder.app because that did actually work [better] for several iterations of macOS. Apparently simply open is fine now. – WestCoastProjects Jan 28 '24 at 21:50
  • 1
    @WestCoastProjects The man page for open is dated 2017. I've used those options for many years. I'd recommend resetting your LaunchServices database. – benwiggy Jan 29 '24 at 08:03
  • 3
    The open syntax for this has not changed since 2000 (and I suspect since 1990 from NeXT) – mmmmmm Jan 29 '24 at 08:49
  • 2
    I don’t think that .app is necessary. – Carsten S Jan 29 '24 at 14:14
  • 1
    @CarstenS The example in the man pages includes it, but you're right, it isn't necessary. – benwiggy Jan 29 '24 at 16:09
3

I would type open then drag the document to the shell. (Skip the app entirely)

See if the full path opens, no need to involve Finder. Worst case specify “Microsoft Word” as the app to open the document.

bmike
  • 235,889