You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

FSPathMakeRef error in python after upgrade to Catalina 10.15.1

Hi,


I get a lot of errors in my script's. In python i see this one a lot "FSPathMakeRef(/Applications/Preview.app) failed with error -43."


version IOS: Catalina 10.15.1

HJow to solve this?

in a terminal  "open -a Preview" is working correctly.


any ideas?


MacBook Pro 15", OS X 10.11

Posted on Nov 4, 2019 5:56 AM

Reply
Question marked as Top-ranking reply

Posted on Nov 4, 2019 7:00 AM

If you are attempting to open Preview with a PDF or image from within Python, the following works. I have commented out the lines that involve returning data from the launched task. This will work with Apple's Python 2.7.17 in Catalina because it retains the scripting bridge, but not with Python 2.7 or v3.n.n from other sources.


#!/usr/bin/python
# coding: utf-8

from Foundation import NSString, NSPipe, NSTask, NSUTF8StringEncoding
import os
import sys


def main():

    pdfpath = os.path.expanduser(sys.argv[1])
    apath = NSString.alloc().initWithString_(pdfpath)
#   pipe = NSPipe.pipe()
    task = NSTask.alloc().init()
    task.setLaunchPath_('/usr/bin/open')
    task.setArguments_(["-a", "Preview", apath])
    # only if task sending back results through pipe
#   task.setStandardError_(pipe)
#   afile = pipe.fileHandleForReading()
    task.launch()

#   only if task sending back results through pipe
#   outStr = NSString.alloc().initWithData_encoding_(afile.readDataToEndOfFile(),
#                                                    NSUTF8StringEncoding)
#   print(outStr.UTF8String().rstrip())


if __name__ == "__main__":
    sys.exit(main())


2 replies
Question marked as Top-ranking reply

Nov 4, 2019 7:00 AM in response to Norover

If you are attempting to open Preview with a PDF or image from within Python, the following works. I have commented out the lines that involve returning data from the launched task. This will work with Apple's Python 2.7.17 in Catalina because it retains the scripting bridge, but not with Python 2.7 or v3.n.n from other sources.


#!/usr/bin/python
# coding: utf-8

from Foundation import NSString, NSPipe, NSTask, NSUTF8StringEncoding
import os
import sys


def main():

    pdfpath = os.path.expanduser(sys.argv[1])
    apath = NSString.alloc().initWithString_(pdfpath)
#   pipe = NSPipe.pipe()
    task = NSTask.alloc().init()
    task.setLaunchPath_('/usr/bin/open')
    task.setArguments_(["-a", "Preview", apath])
    # only if task sending back results through pipe
#   task.setStandardError_(pipe)
#   afile = pipe.fileHandleForReading()
    task.launch()

#   only if task sending back results through pipe
#   outStr = NSString.alloc().initWithData_encoding_(afile.readDataToEndOfFile(),
#                                                    NSUTF8StringEncoding)
#   print(outStr.UTF8String().rstrip())


if __name__ == "__main__":
    sys.exit(main())


FSPathMakeRef error in python after upgrade to Catalina 10.15.1

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.