nickrallison / obsidian-python-scripter

Obsidian Plugin to let the user run custom Python scripts
GNU General Public License v3.0
55 stars 8 forks source link

Arguments for Python scripts #9

Open theFlyingCat04 opened 10 months ago

theFlyingCat04 commented 10 months ago

First of all: I like Your Plugin a lot :)

Do you see a possibility to pass more arguments to the scripts? Arguments that one can configure in the plugin settings would be nice. Example: I have an archive script, that moves my daily notes into a dedicated archive folder. It would be nice to be able to configure the archive folder and the age of the files in the settings and therefore expect them as further arguments in the script.

Thanks in advance

nickrallison commented 10 months ago

I appreciate the suggestion! How would that work with a large sum of Python Scripts? One of the reasons I didn't implement something like that I because I could not think of a way to implement that nicely for multiple scripts while not having any pop ups at run time, or clogging the menu if you have 20 or 30 scripts

theFlyingCat04 commented 10 months ago

Great to hear that!

Maybe in the way the excalidraw plugin grouped their settings: obsidian-excalidraw-settings just a little bit less space consuming. You could add such a collapsible entry for every script or folder in the "Python Script Path" - maybe with an indcator if script specific settings are made (a counter?).

And the look and feel under each of these entries could be inspired by the auto class plugin: obsidian-auto-class-settings

This way one would have a relitively good overview of all the executable python scripts if all these collapsible sections are minimized (depending on the text size of course). And if necessary one could change the settings/arguments for a single python program.

Hope that helps :smile:

theFlyingCat04 commented 10 months ago

I tried to insert my above idea as a mock into your plugin with my limited JavaScript skills and a little help of Copilot :wink::

image

Code:

display(): void {
                ...

        containerEl.createEl("h1", {text: "Scripts"})
        let scripts = ["test.1.py", "test.2.py", "test.3.py", "test.4.py"]

        for (const script of scripts) {
            let detailsEl = containerEl.createEl("details");
            detailsEl.createEl("summary", {text: script});

            new Setting(detailsEl)
                .setName("Vault root path")
                .setDesc("Pass the path to the root of the vault to the script")
                .addToggle((toggle) => toggle);

            new Setting(detailsEl)
                .setName("Current file path")
                .setDesc("Pass the path to the current file to the script")
                .addToggle((toggle) => toggle);

            detailsEl.createEl("h2", {text: "Additional arguments"});
            let additionalArguments = {"arg1": "1", "arg2": "22", "arg3": "333"};
            for (const argument in additionalArguments) {
                new Setting(detailsEl)
                    .setName(argument)
                    .setDesc("Pass this argument to the script")
                    .addText(text => text.setValue(additionalArguments[argument]));
            }

            new Setting(detailsEl)
                .setName("new parameter")
                .addText(text => text)
                .addText(text => text)
                .addButton(button => button.setIcon("plus-with-circle"))
nickrallison commented 8 months ago

I like the idea, if you do a PR and it works, i'll merge it in

nickrallison commented 4 months ago

I think I implemented this in the newest release. I'm not very skilled at design or making things look nice but it seems to be functional to me, let me know if you have any feedback or if this solves your issue