This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

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

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 :)

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".

in Engine by (106 points)
edited by

1 Answer

+1 vote
Best answer

OS.getexecutablepath().getbasedir() function returns the path to the file within the package i.e. "/Contents/MacOS".

This is correct path, actual executable is {}/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.

by (360 points)
selected by

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

"Unable to open Application. -50"

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

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

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.