Topic was automatically imported from the old Question2Answer platform.
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
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”.
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