I am not at my computer so I cannot verify, but it should get you in a close direction of you dig into NSClassFromString and store that cass in a variable. Then you might be able to call its functions. (Typed on a phone)
I made a Palette plugin with a button to display different layers in a new tab.
I would like to write a Python script to trigger the same function as one of my buttons.
But importing one into the other is tricky. So using the plugin class might be easier.
make that method a class method, then you can call it like this:
With a palette plugin, each document gets its own instance of the plugin class. If you want to call a method that takes self as an argument (not a class method), you first need to get the plugin instance that you want to call the method on.
For example, when two documents are open, there are two instances of your plugin. What do you want to happen? For which of those two instances do you want to call the method? Or do you want to call the method on both instances? If so, in what order? What should happen if no document is open?
This all depends heavily on your specific use case and in general I don’t think it is a good idea to call palette plugin methods from an outside script. Perhaps the functionality can be moved out of the plugin method so it no longer relies on self and can thus be called by both the plugin method and your script.
It depends on what you like to do. There are the problems that Florian mentioned. If you need to do something with the font object, you need to acquire that in your script and add it as an argument to TEST(). It could work like this:
(Off topic — A word of caution: Try to avoid periods in defaults keys. If a key contains a period, you cannot reliably observe changes to that value, which you might want to do in the future. Instead, use keys like MyPluginSomeKeyName.)
(jumping on the off-topic) @FlorianPircher What about underscores instead of PascalCase?
Georg once told me about this, where my keys used to be of type "com.markfromberg.plugin.somekey" (which as a practice I took over from the Glyphs SDK and old python plugins like Rainer’s back in the early 2016-ish days), and went to use "com_markfromberg_plugin_somekey" instead.
I still have both versions flying around because I have so many plugins around. I hesitate to change all of them, because users will then suddenly being dropped to default once. Maybe that’s not too bad.
Underscores work as well. I needed to observe default values in my Guten Tag plugin where I originally used periods in the defaults keys. So I wrote migration code that checks for the old defaults keys, and, if present, copies the values to the new key and deletes the value for the old key: