Loading
Conversation 14 exercises
lesson

Generate a Script Header with AI

Create a new "Add Script Header" script by duplicating "Create Novella".

Update the metadata's name, and set the description to "Create a header from the selected script".

Selecting the Script

We can remove all of the existing filePath related code because Script Kit has its own built-in `se

Loading lesson

Transcript

00:00 Let's duplicate our createNovella and call this addScriptHeader. We'll change the name to addScriptHeader and create a header from the selected script.

00:15 So to select this script we can actually get rid of all of this Because Script Kit comes with a built-in Select script and this returns a script object Which has a file path on it. So if we run this right now, you'll see this looks like the main menu but you're actually selecting a script to act on in your script. And once you hit escape you go back to the real main menu with the tabs and the actions and everything. Now the prompt I'm going to copy and paste into this 1 is telling GPT to create the multi-line JS comment following this example. So it's going to read in the script and make like 5 bullet points so that we have something to present at the top of the script to explain it.

00:57 Now once this is done pushing into the editor, instead of a novella we will have a header and our new script contents, so new script contents, can be our header with the contents from up above since we already read in the contents here and that's being passed in as the first call already. Then we can write the file of the file path with the new script contents, and then we'll go ahead and open that in our editor. So once I run this script you can see it's asking me to select a script. Let's select the create novella, and then it fills out a description we can use as our header. And 1 tweak I need to make here is cut this and paste it in there, and I'll adjust my prompt next time around, but for now I'll hit submit.

01:52 And now this is at the top of my script so that when I open the main menu you'll see some nice markdown explaining the CreateNovella script before you get to the bottom. So let's go and do that again. 1 thing I also noticed is I should trim the whitespace since this new line was being added to the top and that 1 to the bottom. And we'll say always keep the markdown inside of the multi-line JS comment. And let's try running this again with a different script.

02:22 Let's find our continue adventure script. I'll hit enter here. And we'll see the description generate. Looks like our prompt worked that time to keep the notes inside of there. So hit submit.

02:36 And once I open the main menu you'll see the nice markdown for the script above that. Now the reason why Script Kit is the perfect match with AI is because these scripts are all individual files which AIs can explain, AIs can create, AIs can understand and comment, and it opens up infinite possibilities for you to customize your workflows. So hold on to your hats because the sections coming up are going to have some amazing demos, and super user power workflows.