Created June 1, 2003 © Copyright SuzShook
Property of SuzShook
| : | : | |
| : |
|
: |
| : | : | |
This tutorial is my own creation;
however, most of the techniques used in this tutorial, I have learned from others.
Therefore, if you recognize any contribution you have made, I thank you.
And I thank you as well for respecting this as my work by not posting it,
in whole or in part,
in any other location without written permission from me.
Individuals and PSP graphics groups are invited to share my tutorials with others with TEXT LINKS ONLY.
You can e-mail me to let me know you are adding one or more of my tutorials to your list if you like -
it's always fun to know who is doing them.
I've been asked by several people to write a simple tutorial showing the basics of recording and editing scripts. I had originally placed much of this material in my Tips and Tricks for PSP 8, but decided to move the material and expand upon it in a tutorial. This tutorial will teach you how to record a simple script, how to run the script you record, and how to use the PSP Script Editor to make simple changes in your script. Once you come to an understanding of the steps required, you can automate many of the common tasks you do daily in PSP.
This tutorial assumes you are a relatively new user to Paint Shop Pro, Version 8, and is written in and for that version. Many screen shots in this tutorial are resized - your work will be larger than this.
Supplies - For this tutorial, you will need the following:
- Jasc's Paint Shop Pro 8 - you can get the 30-day trial version HERE.
~ ~ ~ ~ ~ ~ ~ ~ ~ ~
OK, now we're ready to begin. Grab your mouse and let's get started.
Remember to save often.
~ ~ ~ ~ ~ ~ ~ ~ ~ ~
STEP 1
Scripting is an exciting new feature in PSP 8 which allows you to automate lengthy or repetitive tasks that you want repeated on multiple images. It saves you the trouble of doing all the steps by hand every time. Nearly everything you do in PSP can be recorded into a script and played back later.
PSP 8 scripts are written in the Python programming language, but you don't even have to know anything about the language to create your own scripts. PSP 8 includes a built-in script recorder that does all the work for you. Let's take a look at the script toolbar:
![]()
- Select Script drop-down list - shows the scripts saved in PSP 8's Scripts-Trusted and Scripts-Restricted folders.
- Run Selected Script button - runs the script displayed in the Select Script drop-down list.
- Edit Selected Script button - edits the script displayed in the Select Script drop-down list.
- Interactive Script Playback Toggle - switches between silent and interactive modes when running scripts.
- Run Script button - opens and runs a script located anywhere on your system; usually used to run scripts located outside the Scripts-Restricted and Scripts-Trusted folders.
- Stop Script button - stops the running script. This button only active when script running, when it looks like this:
![]()
- Start Script Recording button - begins recording actions that will comprise a script.
- Pause Script Recording button - pauses recording of a script. This button only active when script being recorded, when it looks like this:
![]()
- Cancel Script Recording button - cancels script recording. This button only active when script being recorded, when it looks like this:
![]()
- Save Script Recording button - saves the actions you have been recording. This button only active when script being recorded, when it looks like this:
![]()
To turn recording on, press the Record Script button
on the Script toolbar. From this point forward, every action you perform in PSP will be recorded until you press the Save Script Recording button
, or the Cancel Script Recording button
. Once you save the script, you can play it back by finding it in the Select Script drop-down list, and using the Run Selected Script button
.
Now that we've taken a look at the scripting toolbar, let's use it to record a script. As I said before, scripts help automate repetitive tasks. In this tutorial, we'll record a script for a simple, often-used task, that normally takes several keystrokes: select all, float the selection, apply a cutout, and then deselect. Once you see how to record the script, you can use the process to record other scripts that help make your work easier.
STEP 2
To record a script for select-float-cutout-deselect, we need an image open. So, create a new transparent image and insert a tube. Any tube will do - we just need something to select.
Before we begin, let's review exactly what we want to do, because once the recording starts, the script recorder will record all actions we take, and we don't want to record anything unnecessary. It's really important to plan your actions before recording a script, even running through them to be sure you have all the steps you need, in the correct order. Of course, the script we're going to record today is really simple - it won't take much practice, but it will give you the general idea of how to record a script.
All we're going to do is select all (Selections...Select All, or CTRL + A), float the selection (Selections...Float, or CTRL + F), apply the cutout (Effects...3D Effects...Cutout), and deselect (Selections...Select None, or CTRL + D). For the Cutout, let's use these settings, so we're all singing from the same sheet of music:
Vertical offset (0)
Horizontal offset (0)
Opacity (90)
Blur (30)
Shadow color (Black)
Fill interior with color UNcheckedWhen you're ready to start recording:
- Click the Record Script button
on the Script toolbar.
- Perform the actions you want to record, one after the other:
- Select all (CTRL + A).
- Float the selection (CTRL + F).
- Open the Cutout dialog (Effects...3D Effects...Cutout), enter your settings, and click the OK button.
- Deselect (CTRL + D).
- Click the Save Script button
, which brings up the Save As dialog:
Note: The dialog opens to your default Scripts-Restricted folder - change folders if necessary. Restricted scripts are those that cannot run any system type commands. These scripts are usually safe to run on your system. Most of the scripts you write or receive from others should be placed in this folder. The Scripts-Trusted folder is reserved for scripts that execute such commands as Save commands, Close commands, Delete commands, Send, Exit, Export, Save Preferences, or run Batch Process or Renames. Always be very careful about placing scripts in the Scripts-Trusted folder. These scripts run UNrestricted and have full access to your system. Be sure you know what the script is doing that requires it to be placed in the Trusted folder, and be sure you can trust the script source. If you have any doubts, DO NOT RUN the script on your system.- Enter the name you want for your script in the File name box.
- Click the Description button to add your name, copyright information, and a brief description of the script, if you wish:
![]()
- Click Save when you have entered everything the way you want it.
And that's it - you've recorded your first script. Congratulations!
Before we run the script, let's look back at the script Save as dialog - there are 2 other options in the lower left corner we need to mention. The first of these, Save Materials, saves the names and paths to any patterns or gradients you use in the script. Of course, in our simple script, there are no colors or patterns or gradients used, but keep this in mind as you record more complex scripts. And if you share any of your scripts with others, be sure to include any patterns and/or gradients you used, so the script won't fail because it can't find them. For our simple script, you can leave this option checked - it won't really matter.
The second option, Save Dialog Positions, will place any dialogs used in this script in exactly the same positions, and with exactly the same size, as they were when you recorded the script. If you are planning to share your scripts with others, it is a good idea NOT to check this option, as it may make undesirable changes for others. As a general practice, I'd recommend leaving this option UNchecked.
Note: Should you change your mind and decide not to name this script, and click on the Cancel button, that just cancels the Save As dialog - the script recorder is still running. To cancel the recording, you must click the Cancel Script Recording button.
STEP 3
Now that we've recorded our script, let's play it back and see if it works! First of all, undo the changes you made to your tube, or just delete it and add another tube, so you can see the changes made by your script.
Before we play the script back, I want you to notice the Interactive Script Playback Toggle button - it's number 4 on the script toolbar pictured above. This is a very important button, and allows the script either to play "silently", or to allow for user interaction. Here's what it looks like in Silent mode:
![]()
When this toggle is in Interactive mode, it has a border around it:
![]()
Set your Interactive Script Playback Toggle to play the script in Silent mode this first time. Find the script you just recorded in the Select Script drop-down list. Then click the Run Selected Script button
, and watch what happens. Did it work? Did you add the cutout to your image? Neat, huh.
Undo the changes again, and let's try playing the script in Interactive mode - be sure the Interactive Script Playback Toggle is pressed, as above, and has the border around it. Now press the Run Selected Script button again, and watch what happens. Because you are in Interactive mode, the script will stop at the Cutout dialog so you can enter/change the parameters. Cool or what! Change the Blur in this one, click on the OK button, and the script completes.
That's it - you've recorded a script, and played it back in both silent and interactive mode. But what if you want to change something about the script?
STEP 4
Let's look at what we can do to change our script. There are 2 ways to edit scripts: PSP has a built-in Script Editor, which is the most common way to edit the script, especially at first. You can also edit the Python code itself, using a text editor. But that's for advanced "scriptaholics"! Let's just use the PSP Script Editor for now.
To edit the currently selected script, click the Edit Selected Script button
. The Script Editor dialog will appear, listing the actions that comprise the script, as well as some basic information such as the author, copyright information, etc.
Note: If the PSP Script Editor cannot open the script for any reason, the script will open in the default text editor application set in the File Locations dialog (we'll look at the Text Editor option below). This often happens if the script was created or edited manually in a text editor.Shown below is a portion of the Script Editor dialog from our script:
![]()
The first column of the Script Editor contains check boxes - you use these to either use, or omit parts of the script. This is a good way to test out parts of a script without deleting commands. For instance, if you were to clear the check box for the Select None command, save and close the script, and then run it again, it would run all commands except that one, leaving the tube selected. Go ahead and try it if you want. Click the Save button, then the Close button, and run the script again, noticing what happens. Then return to the Script Editor by clicking the Edit Selected Script button again. We'll wait for you!
The second column contains the command Mode, and the drop-down list is used to set a mode for the script's actions. The available modes are:
- Silent: Skip all dialogs - the command in the script is executed without displaying any dialogs.
- Interactive: Allows for user interaction with dialogs and other settings.
- Default: Executes the command based on the Interactive Script Playback Mode currently set - if the Playback Mode is set to Silent, all dialogs are skipped; if the Playback Mode toggle is set to Interactive, the dialogs are displayed.
Usually, when a script is recorded from PSP actions as ours was, the command modes will be set to Default. To change one of these, click the drop-down arrow and select another execution mode. Try this for the Cutout command - change the mode to silent for that command:
![]()
Click the Save button, then close the Script Editor. Try running the script again, with the Interactive Script Playback Toggle set to Silent, and then set to Interactive. Notice the Cutout dialog never comes up, because we set the Mode to Silent within the script.
Note: For any commands of a script that have been set to run in either Silent or Interactive mode, the position of the Interactive Script Playback Toggle is ignored - it will NOT override that setting. For any commands of a script that have been set to run in Default mode, the position of the Interactive Script Playback Toggle WILL override the Default setting.Let's go back into the Script Editor again (click the Edit Selected Script button). Look at the 3rd column, which contains the actual commands in the script. If these commands are italicized and marked NOT editable, they cannot be selected for editing. However, the settings can be modified for other commands, such as the Cutout command. To modify the settings, select the command and then click the Edit button below the Script Commands box, or just double-click the command. The Cutout dialog will pop-up, with the settings we used when we recorded the script. These settings can be changed here - if your tube image is visible, notice the new settings are temporarily reflected in the image. When you are finished, click Save, and then Close. You might want to run the script again to verify your changes.
If you want to delete a command from the script, select the command and click the Delete button.
Finally, to view and/or edit the Python code associated with the script, click the Text Editor button. The default text editor on your system will open the script for edit.
Note: Unless you specify another text editor, the default editor is Notepad. To change the default text editor, choose File...Preferences...File locations. In the File Types list, choose Python Source Editor, and enter the path for the editor application you wish to use. Click the Browse button if you need to navigate for the correct path.Let's click the Text Editor button now, just so you can see what the code looks like. Don't worry, it won't bite! Some things to notice when you're looking at the Python code:
- Scripts always begin with the "from JascApp import *" statement.
- The next statement is always the "def ScriptProperties():" statement - this statement contains basic script information (title, author, copyright, description), and serves as documentation for the script.
- The third statement is always a "def Do(Environment):" statement - this statement will contain all the commands for the script, in individual "App.Do" statements.
Notice all our commands in the "def Do(Environment):" statement - you should be able to pick out the SelectAll, FloatSelection, Cutout, and SelectNone commands. Also, notice the parameters in the Cutout command - do you recognize the settings we used? Experienced script writers can edit the script right here, changing settings, adding commands, etc. But this is not for the fainthearted. In the Python language, every quote, comma, space and indentation is significant - insert a single extra space, and the entire script may fail. For now, though, we're just looking! When you have finished exploring the script, close the window without saving (click the Close button in the upper right corner, or select File...Exit).
STEP 5
Is there an easier way to run those scripts, you might ask, without having to find them in the Select Script drop-down list? There surely is - if you save your scripts as boundscripts, you can assign shortcut keys to them, or add them to menus or toolbars. For more information on boundscripts, visit my Using Boundscripts tutorial.
Another thing you might ask - can I run scripts that are not in the Script-Restricted or Scripts-Trusted folders? The answer is "yes" - just use the Run Script button
to activate the Run Script dialog. Navigate to the folder containing the script that you want to run, select the script, and click the Open button to execute the script.
Note: The Execution Mode for scripts run in this manner is set on the Run Script dialog, at the bottom of the panel - the position of the Interactive Script Playback Toggle is ignored. In addition, be aware that scripts run from unconfigured paths are always treated as Restricted scripts.Each step of a running script is recorded in the Script Output palette or window. This palette is probably not visible, but should the script fail for any reason, this palette will automatically appear to display script error information. You can view the Script Output window by choosing View...Palettes and clicking on Script Output, or use its shortcut key, F3. This same key also makes it disappear from view.
To clear the commands listed in the Script Output window, choose File...Script...Clear Output Window.
STEP 6
And there you have it - you've recorded your first script, played it back, edited it, and perhaps even made it a boundscript and added it to a toolbar. Now you're ready to record other scripts to automate your PSP world.
Here are a few examples of some simple repetitive actions I have recorded as scripts:
- Duplicate an image and close the original.
- Save a PSP file in PSP 7 format and reset the options to PSP 8 format.
- Select All, Float, and Defloat.
- Open the Preferences...File Locations dialog directly to the Picture Tubes File Type.
- Open the Preferences...File Locations dialog directly to the Selections File Type.
These scripts make my everyday work in PSP easier - at a touch of a single button, I can add another folder to my tubes list, or save a file in PSP 7 format for Animation Shop! To me, this is the real value in scripting. You can use scripting for fun stuff, like recording all the steps in a tutorial so the user gets the results by simply running the script. But when it comes to recording all the steps of a simple repetitive task I perform often so that it becomes a one-step routine - it's priceless!
PSP 8 comes with a "Scripting for Script Authors" document, which you can find in the PDF Files folder within the Learning Center folder of the PSP 8 program. This document is called "Scripting HowTo.pdf". A more recent version of this document can be found at the Jasc site HERE.
Enjoy automating tasks by recording your own scripts in PSP 8!
If you have any problems, comments, or questions, please do not hesitate to Email me.
PSP8 Tutorials ~ PSP8 Tips & Tricks ~ About Me ~ Links ~ Home ~ Email
All graphics and content © 2003 by SuzShook