How do I use the OS.shell_open method on Mac OS?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By netimu

I’m working on an application where I can add attachments and open them etc.
I’m using the following code to open pdf files:

func open_attachment(filename):
    var path = OS.get_executable_path().get_base_dir()+"/"+filename
    OS.shell_open(path)

It works just fine on Windows export, but on Mac export it gives me an error: “Unable to open Application. -50”
note: the filename is of the sort: “name.pdf”
Would you please help by providing insight as to why this is happening? And maybe a solution?
Thank you very much in advance :slight_smile:

Edit:
I looked further into it and I’m not sure why the OS.get_executable_path().get_base_dir() function returns the path to the file within the package i.e. “/Contents/MacOS”.

:bust_in_silhouette: Reply From: bruvzg

OS.get_executable_path().get_base_dir() function returns the path to the file within the package i.e. “/Contents/MacOS”.

This is correct path, actual executable is {name.app}/Contents/MacOS/{name}.

There’s no special function to get .app bundle path, but it’s always the same. You can use OS.get_name() to detect OS and add ../.. to the path.

Thank you for the clarification, I was under the impression that it returns the .app bundle’s path.
But the initial problem still persists, could it be a “special permissions” issue? Or a codesign issue? Hmmm

netimu | 2020-10-09 22:28

“Unable to open Application. -50”

I think macOS expects URL style filename OS.shell_open, try adding file:/ to the beginning.

bruvzg | 2020-10-09 22:37

I totally forgot about that. Thank you from the bottom of my heart!

netimu | 2020-10-09 23:09

THANK YOU!! @bruvzg I’ve been hunting all over for this issue and you’ve solved it for me… except in my case i had to add file:// to the beginning

CheckMateMrBond | 2021-08-24 11:57