Mac permissions for add-ons

It turns out if you try and read a .blend file from a folder in the add-ons on the Mac, you get an error. I figured a way around this for our users, but is there possibly a better way? I know other add-on developers are having the same problem.

Here’s the video with the workaround. Any suggestions are welcome :slight_smile:


@chippwalters, is this true for any MacOS version, or is it perhaps only for certain versions, say the latest Catalina only?

Also, it would be interesting to get the blender log of what happens when you click the Sketch button of your addon. Just run Blender from a terminal to see that output.

Hi jesterKing,

The problem is, when I run from terminal, it all works. But, when not run from terminal, it doesn’t. So, it is a bit hard to debug.

And this happens with all MacOS versions?

Yes. Tested on Mojave and High Sierra

I am also running a Mojave system here. Perhaps you could share with me your add-on so I could have a look into this as well? Feel free to do so either in this thread or in a PM.

Sure, just DM me and I’ll get you a copy

I did some testing and digging and found this is rather a path construction issue.

So I was reading a bit through the code to see what is going on.

I see you’re using os.getcwd(), but at least on MacOS that is problematic. Running Blender from the launcher has that return /, so the path you construct is wrong.

With a terminal where you’re not in the homedirectory loading of the add-on also fails , since os.getcwd() will be wrong.

A better and more portable way would be to use some of the utility functions provided by Blender.

For my own import_3dm add-on I use bpy.utils.script_path_user(), which on the different machines translates to all the 2.81 folders you are interested in (getBasePath() in your sketch_style/ On my Mac this gives /Users/nathan/Library/Application Support/Blender/2.81/scripts

I believe the following getBasePath() revision will work on all platforms you choose to support:

def getBasePath():
    p = bpy.utils.script_path_user()
    p = os.path.join(p, "addons", "sketch_style")
    p += os.sep
    return p

For proper and cross-platform fiddling I suggest to use at minimum os.path.join and os.sep, but also do look into using the module pathlib where possible. Anyway, the os.path.join() together with os.sep should be used where-ever you are creating paths. There are quite a few spots in the add-on where you do set up paths. Revisit those and switch to using the suggestion.

The improved getBasePath() has your add-on work much better at least here on MacOS :slight_smile:

I use a Mac and find this code in our add-on works well for a blend file in the addons directory:

path = (
            str(bpy.utils.user_resource("SCRIPTS", "addons")) + "/clockworxpdt/parts_library.blend"

I am not sure if this meets all the requirements set out by @jesterKing, if not then I will change to his methods quoted above.

Cheers, Clock.

@clockmender, looks mostly good, I’d write it like

path =  os.path.join(bpy.utils.user_resource("SCRIPTS", "addons"), "clockworxpdt", "parts_library.blend")

Not sure why you enclose it in ().

1 Like

We ran “Black” (black -l100 *.py) formatter on it… Thanks for the tip, I’ll modify things.

Cheers, Clock.

First time I heard of it :slight_smile:

@ermo put me on to it (I think he thought my code could do with a cleanup, which was an understatement);

I noticed that it seems that Black is now hosted on the python software foundation’s github project:

I’m inclined to think that this means that Black is intended to eventually occupy the same spot in the python ecosystem as gofmt does in the Go ecosystem. Time will tell I suppose.

In any case, Black is a strict pep8 formatter with configurable line-lengths. I arbitrarily set the line length to 100, which is presumably why Black formatted the piece of code you commented on like it did.

1 Like

Thanks a lot Nathan, much appreciated. We’ve implemented these changes and are now in a final QC check.

1 Like

Hope your problem was solved, I had an error with Mac where I was trying to integrate an add-on, I saw error messages like apple error 4013. I cannot fix this issue yet.

You will have to give us more detail here and show us some code.

Oh, yes “Welcome to Devtalk”

Cheers, Clock.