geddski / macros

macros support for VS Code
MIT License
166 stars 36 forks source link

Executing scripts through macros #56

Closed elyasaf755 closed 4 years ago

elyasaf755 commented 4 years ago

tl;dr: As the title says, is it possible to run a script through a macro? I've tried it, but unsuccessfully.

long story: There is this extension called "powertools", and I used it to add a custom button that runs a script when I click it. I wanna add a functionality to this button, such that each time I click the button, it saves all of my files using this command ID "workbench.action.files.saveAll", and then shall it run the script.

defining the button goes like this:

"ego.power-tools": {  
        "buttons": 
        [
            {
                "text": "Compile Folder",
                "tooltip": "Compile all the .Jack files in the current folder.",
                "action":
                {
                    "type": "command",
                    "command": "macros.compile_button_click",
                }
            }
        ],
    }

And I want the macro to look something like this:

"macros": {
        "compile_button_click": [
            "workbench.action.files.saveAll",
            {
                "action":
                    {
                        "type": "script",
                        "script": "compile_folder.js"
                    }
            },
          ]
    }

Thanks in advance!

P.S - It is important that the macro will first save the files, and only then shall it execute the script

elyasaf755 commented 4 years ago

I've found a solution to this. this is how i did it:

"ego.power-tools": {
        "buttons": 
        [
            {
                "text": "Save & Compile",
                "tooltip": "Compile all the .Jack files in the current folder.",

                // Running the macro on button click
                "action":
                    {
                        "type": "command",
                        "command": "macros.compile_button_click"
                    }
            }
        ],

        "commands": {

            // Define a command that runs a script
            "compile_folder": {
                "script": "compile_folder.js"
            }
        }
    },

    "macros": {

        // Define a macro command
        "compile_button_click": [
            "workbench.action.files.saveAll",
            "compile_folder"
          ]
    }