Often called “data types” what we’re going to discuss today are the types of things Python can store inside of a variable.  What kinds of information can we store, edit, and check in order to make a program?

Odd as it may sound, all of our extremely advanced programs are done with only a few basic types of information.  Each programming language has their own data types but they can usually be summed up as numbers, text, and lists of numbers and text.  There are other types of data, variations on these basic ones, and other things that are completely different.  But for today we’re going to focus on Numbers, text, and lists.

## Numbers

Python has three main types of numbers: Integers, Real numbers, and imaginary numbers.  We’ll ignore imaginary numbers for now.  I never properly understood how they worked anyway.  Part of the reason I failed College Algebra two times.

We only care about Integers and Real Numbers.  Because PSP doesn’t make use of imaginary numbers in its script options.

Integers are whole numbers.  That is any number that isn’t a fraction or a decimal.  So 0,1,2,3,4,5 are all integers.  As are -1,-2,-3,-4,-5.  In Python, if you divide two integers, you get an integer back.   This is because Integers and Real numbers are different and Python won’t force convert an integer into a real number.  There technically isn’t a real limit to the size of an integer.  Want to record 10000000 in a variable?  Go for it.  Though do be aware that eventually a maximum will be reached, simply because of how much memory on your computer is available.  But no one can give a practical limit to the size of an integer.

Real numbers, also known as floats, doubles, decimals, etc., are numbers with a decimal place.  If it has a decimal, it’s a real number.  In Python these are called floats but in PSP if you’re reading the API documentation they always call them Reals.  So we’ll alternate between calling them Real and Float from time to time but for the most part we’ll stick to Real so we can match the documentation of PSP.

Just like with integers, if you divide two floats, you get a float.  However, if you divide an integer by a float, you get a float.

There are several math operators that you can use to manipulate numbers inside of Python.

+  – is used to add two numerical values together.

–  – is used to subtract

* – is used to multiply

/ – is used to divide

// – Floor division, used with floats it rounds the result down to the floor

** – Exponential operator – raises the front value to the power of the back value

% – Divides two numbers and returns the remainder

There are other commands such as sqrt(), round(), abs() and others.  Commands are different from operators but we won’t get into those for now.

Math is handled from left to right according to the order of operations.  So  10 + 2 * 20 is different from (10 + 2) * 20.   And 10 – 2 is different from 2 – 10.

Here is an example of performing math using variables.  Keep in mind the variable you assign a number to must be on the left side of the = sign.  And yes I am aware that this is not accurate because of leap years.  xD

```my_Age = 33
my_Age_In_Days = my_Age * 365
my_Age_In_Weeks = my_Age_In_Days / 7

my_Age_Times_7 = my_Age * 7
```

## Strings(text)

The next data type is text, also known as a “String” because you “string” individual characters together.

Text is defined by enclosing the text between two matching “(quotation) characters.  You can use double quotes or single quotes.  The important thing is that the quote at the beginning and at the end match.  So if you’re writing a string “Hello I’m Bob” although the word “I’m” contains a single quote the string works just fine because the beginning and ending quotes match.  However, if I did this “Mom said “buy milk” and so I did” Python doesn’t know what to do with this.  It sees this as “Mom said” and then two variable buy and milk and then another string “and so I did.”  But because you don’t have any operators, and have not created a buy or milk variable it’s going to throw a fit.

Likewise, if I wrote ‘This string has quotes “like this” ‘ this is also a perfectly valid string because the beginning and end quotes are both single quotes.

Strings are also immutable.  This means they cannot be changed once they’ve been made.  Once you’ve made a string, you can use that string as a parameter in an equation of a command, you can delete it, but you cannot change it.

So, you’re probably wondering what good is a string if I can’t change it?  A lot of good as it turns out, I won’t go into the reasons but essentially it doesn’t usually come up because although you can’t change a string, you can make a brand new string out of an old one.  So most of the time you won’t even notice this limitation.  But it is important to be aware of.

Here’s an example

```first_Name = "Jack"
last_Name = "Dorsey"
whole_Name = first_Name + " " + last_name
first_Name = "Steve"```

So, in this example I created a new variable called “whole_Name” and assigned it the value of adding three strings together.  first_Name, a space, and last_Name.  I then replaced the value of “Jack” inside the variable first_Name with the string “Steve”.  This doesn’t change “Jack” into “Steve” it simply deletes the string “Jack” from the variable first_Name and places “Steve” into the variable instead.  This also doesn’t change the value in whole_Name.  That remains “Jack Dorsey” because we passed in the result of our equation and then we left it alone.

Strings can be added together (called Concatenation) but they cannot be subtracted.

You can also multiply a string by a number to create a new repeating string that repeats several times.  So “ten” * 10  results in “tentententententententententen.”

“10”*4 = “10101010”

Which brings up another point.  You cannot add, subtract, or divide like you can numbers.  So “10” / 2 will throw an error as Python doesn’t know how to deal with division on a string.  Attempting to add a number to a string will also give an error.  You need to either convert the string into a number or convert the number into a string.  We’ll come back to this later.

## Lists

Finally there are lists.  Lists hold a bunch of different types of data in an ordered way,  and there are several different kinds in Python.

So, for example, let’s say you had a program that you wanted to track the ages of several people.  It would take forever to add enough variables for each new person, and everytime you got someone new you’d have to add them in.  And you’d have to keep track of every single one.  That’s not very useful.

A list lets you keep track of several different items inside a single variable.  They are defined by putting a series of comma-separated values between two square brackets.  Like this

`student_Ages = [33,23,19,56,35,45,20]`

Then, if I wanted to access a particular student I would grab it using the index of the list.  So each item in the list is given an index starting with 0 and going up.  So student 1 is at index 0, student 2 is at index 1 and so on.  The notation for this is to put the variable name followed by brackets and the index.  my_var[0].

Lists can also hold mixtures of data, they don’t all have to be numerical.

`student_Ages = ["Jack", 33, "Steve", 23, "David", 19,56,35,45,20]`

You can also create a list by calling the list() command

`student_Ages = list(19,56,35,45,20)`

You can also change the value of individual items in a list by using its index

`student_Ages[3] = 5`

The end result is now a list that looks like this [19,56,35,5,20].

Another type of list in Python is a Dictionary.  Dictionaries are lists of Key and Value pairs.  This means that instead of each value having an index from 0 to whatever, it has a key that you can use to look up the information.

Keys can also be any type of information, though most often people use strings as keys.  Take the student_Ages example.  We could use the student’s name as a key to get their age.  Dictionaries are created by placing these Key and value pairs between two curly braces. Each key and its matching value are separated by a colon “:” and each key and value pair are separated by commas.

`student_Ages = {"Jack": 33, "Steve": 23, "David":19, "George":56,"Alex":35, "Stacey":45,"John":20]`

I can then retrieve the proper age using the key between two square brackets.

`student_Ages["Stacey"]`

Dictionaries are the most heavily used type of list in PSP.   YOu can also create a dictionary by calling the command dict()

And finally there are Tuples.

A tuple is an immutable list.  This means that unlike the regular lists and dictionaries you can’t change the value of any item in the tuple.  Tuples are defined either by using parenthesis and at least one comma even if the tuple only has one value, or by calling the tuple() command.

`color = (255,0,255)`

You access tuples the same way you do a list, with an index, starting with zero.

Next tutorial we’ll go over using these different types to do something very simple.  I’ll also be introducing some new commands you can use.

I would like to preface this post with: I am not a python expert.  I might, at best, be identified as an intermediate coder and even that might be a bit generous.  I am also not a teacher.  So attempting to learn the basics of Python from me is not the best idea.

That being said, I would like to re-emphasize the Resources post I made which links to several great learning resources for the basics.

If you’re still here, then let’s get started.  I’m going to do this using a combination of code, pseudo code, and video demos.

Pseudocode is regular English, something you won’t normally be able to just put into an interpreter or compiler to make it do something.  It explains a concept in a way that looks like code but is a bit easier to read.  I will make sure you’re aware of what is what as we go along.

I’m also not going into depth on programming in Python.  I am only going to cover the basic topics I think you’ll need to understand in order to properly read a PSPScript file and know what’s going on.

## Variables

If you’ve ever taken a basic algebra course, or a science course where math was involved, then you’re already familiar with the basic concept of a variable.  It’s a name that you use as a placeholder for some piece of information.

For example if I wrote the following: “knee” + x is a piece of anatomy

You would know that “x” is a placeholder for the text “cap”.  A “kneecap” is a piece of anatomy.

Or if I did this: x = 1 + 2

You would know that x is equal to 3.

In general, it’s the same thing with programming.  In Programming, we have variables that can hold information for us.   All we have to do is give the variable a name, and then set it equal to something.  This is known as “assigning” the variable a piece of information/data.

Again, as an example here is some Python code where I assign the number 33 to the variable Age.

```
Age = 33

```

Yes, that is a program.  It doesn’t really do anything useful, but in Python, this is a perfectly valid program.  It only does one thing, it sets the variable Age equal to the value 33.

We can store all kinds of information inside of a variable.  We can store text (string), integers, decimals, lists of data, and more.  All we need is a variable with a valid name, and the “=” sign.

## Variable Naming

So what is a valid name for a variable?  Technically a valid name is anything you want it to be with some specific limitations.

1. Variable names must begin with either a _(underscore) or a letter.  They cannot begin with numbers.
2. Variable names, after the first character, can be any letter number or underscore.  You cannot include spaces or punctuation.
3. Names are case-sensitive so Age and age are treated as two different variables.

Now, while any name is technically a valid variable name it’s important that you realize there are conventions that most programmers adhere to when creating names.  These conventions are not required by Python, but they do make the code easier to read and to understand.

1. Make your name descriptive.  In math you constantly see single letter names like “x”, “y”, “z.”  and these are fine for simple equations but code quickly gets very dense it quickly becomes hard to remember what “x” stood for in a long bit of code.  So you want to make sure you’re always using names that tell the coder/reader what the purpose of that variable is.For example: student_Age vs age.  Or  really_bad_puns  vs bad
2. Your variables must be easy to read, many programming languages have adopted what’s known as “CamelCase” for their variable names.  This means capitalizing each word.  Others use underscores to represent spaces.
3. Never use the characters ‘l’ (lowercase letter el), ‘O’ (uppercase letter oh), or ‘I’ (uppercase letter eye) as single character variable names.  This feeds back into point number 2.  Those letters are difficult to distinguish between each other, zeros, and ones depending on the font.  It’ll add unnecessary confusion to both you and the person reading your code.
4. If a variable will hold data that never changes (called a Constant) write the name in all CAPS.  For example.  If you wanted to have a variable for PI.  Since PI doesn’t change you can capitalize it to let yourself and your reader know that it’s an unchanging value.
`PI = 3.14159`

There are others, but I think this will suffice for now.

## Creating Variables

Alright, so we know how to name our variables.  Now how do we create them?  How does Python know when we are creating a brand new variable?

Variables are created the first time you try to assign some data to them.  You assign data to a variable using the assignment operator “=”.  So let’s say I had a variable “my_Age” and I set it equal to 33.  Since I’ve never used this variable before, and because I’m assigning it the number 33, Python will create this variable for me and give it that number.

`my_Age = 33`

This is important because if you attempt to use a variable in a calculation, or as a parameter to some other piece of code and you haven’t created it yet.  Python will throw an error.

Take a look at this code as an example

```
days_Alive = my_Age * 365

my_Age = 33

```

As you can see I’m attempting to calculate how many days I’ve been alive by multiplying my age in years by 365.  And then assign the result of that calculation to the variable days_Alive.

However, since I’m only defining my_Age on line 2 Python has no idea what “my_Age” is or what it’s supposed to contain.  And so it’ll throw an error.

NameError: name ‘my_age’ is not defined

The appropriate way to do this would be to define my_Age first.

```my_Age = 33
days_Alive = my_Age * 365
```

Microsoft VS Code editor is one of the latest code editors available to programmers.  It’s open source and cross platform.  Microsoft intended it to be used by everyone for almost any project.  It’s layout is similar to Atom or Sublime text editors.

To install VS Code go to: https://code.visualstudio.com

The page will recommend the most appropriate installer for you, download it and install.

What we’ll do is associate the PSPScript file extension with the python programming language so that VSCode knows to use Python syntax highlighting when it opens a script from us.  Very similar to what we did with Notepad++.

You can watch the process here: https://drive.google.com/file/d/1eBBv_6flUEV_Bk9xp-_tWEKFVwq01iq9/view?usp=sharing

To get started open up VS Code

Next go to File -> Preferences -> Settings.

This will open up a text document called User Settings.  It’s written in a format known as “JSON” or Javascript Object Notation.  It’s not important just a fun little tid-bit.

User settings are split into two sides, Default Settings and User Settings.  Default Settings are the settings that VSCode uses by default and User Settings override any Default Settings.

To get started scroll down until you find the text “file.associations”: {}

Hover your mouse of it and you’ll see a pencil icon appear to the left.  Click ont his icon and select “Copy to settings.”  It’ll place a duplicate of this setting into the User Settings side.  And if you have any user settings in there already will add the approrpriate comma to separate the two.  As you’ll see in the next screenshot

Next add the following text between the two curly braces.

“*.pspscript”: “python”

The “*” is a wildcard character that means “accept anything that comes before this.”  Then we have “.pspscript” as the file extension.  So any file that has a “.pspscript” extension is covered by this rule.  We separate the key from the value with a colon.  Then we pass in the name of the language we want associated with this file. In this case, python.

And that’s all there is to it.  The default settings already set the tab size to 4 spaces, and auto-replace tabs with spaces.  If you’d like to change this default behavior you can copy those values over to the user settings side as well and change them to meet your needs.

Finally setup PSP to open VS Code

Open PSP and go to File -> Preferences -> File Locations

In the list on the left select “Python Source Editor.”  Here you’ll only a textbox with a browse button.  Click on browse, and navigate to where VS Code is saved.  This is usually in C:\Program Files\Microsoft VS Code\Code.exe .

Now, when you hit the “Edit Script” button, instead of PSP opening regular Notepad, it’ll open it in VS Code.

Python scripts are just simple text files that can be edited in almost any text editor such as Notepad, Notepad++, Emacs, vim, nano, atom, sublime, etc.

So as long as you have an editor that can open a text file and save out a text file with the appropriate file extension you can edit or create scripts for PaintShop Pro.

However, certain editors have special tools and features that can make programming easier.  Features such as auto-indentation, syntax coloring (highlighting important words and color coding different aspects of the code for easy reading), definitions, auto-complete, etc.  And PSP can accommodate many of these editors.  The next two posts will focus on two of them: Notepad++ and Visual Studio Code Editor.

Probably the most established of the two is notepad++, it’s been around since 2003 and along with its own rich language and feature set also allows for the addition of plugins to augment its own features.  I won’t discuss plugins today, simply how to get Notepad++ ready for PSPScript editing.

You can watch the process here: https://drive.google.com/file/d/1T9m5I7gEQ5sPUKEAm6GQ73HKjjNTcG6u

Next open Notepad++ and go to “Settings -> Style Configurator”

This dialog is where we’ll tell Notepad++ how to handle PSPScript files.

In the “Language” box on the left scroll down and select “Python”

On the right under “Style” you’ll see various types of “syntax” or grammar that make up a Python script.  For each one they have a color, font family, and font style you can change.  So if you find you don’t like how Notepad++ colors everything you can change it here.  What we’re most interested in is at the bottom where you see “Default ext. :” and “User ext. :”

Under “User ext. :” add “pspscript,” this tells Notepad++ to treat any pspscript file like it was programmed in the Python programming language.  With the changes made hit “Save & Close”.  Next, we want to make sure that all indents are treated the same.  For me, the easiest way to do this is to auto-convert all tabs into spaces.

Go to “Settings -> Preferences”

In the list on the left select “Language”, here you can either set the default for the whole program or make a special override for an individual language.  You can also hide languages from the langue menu that you will never use.  In the image above you can see I have the tab size set to 4 spaces, and I have “Replace by space” selected.  This converts all tabs into 4 spaces.  This ensures that all indenting in your script has a consistent appearance and type of indentation (spaces vs tabs).

Next, we have to tell PSP to use Notepad++

Open PSP and go to File -> Preferences -> File Locations

In the list on the left select “Python Source Editor.”  Here you’ll only a textbox with a browse button.  Click on browse, and navigate to where notepad++ is saved.  This is usually in C:\Program Files (x86)\Notepad++\notepad++.exe  on a 64-bit machine and 32-bit install.  Or C:\Program Files\Notepad++\notepad++.exe on a 32-bit machine, or on a 64-bit machine with 64-bit install.

Now, when you hit the “Edit Script” button, instead of PSP opening regular Notepad, it’ll open it in Notepad++.

I’ve been going back and forth on where to start when it comes to Python and PSP Scripting.  Because this series isn’t going to be a general programming series I technically won’t be going about it the same way a normal programming tutorial would.  I’m going to attempt to teach you the basics of Python with a direct emphasis on Scripting in PSP.  And I figured the best place to start is to talk about Python and what version of Python PSP uses.

I want to start with this small disclaimer: YOU DON’T NEED TO INSTALL PYTHON ON YOUR COMPUTER!

PSP comes with its own Python interpreter built in.  So you don’t need to install python to start scripting and using python.  And these tutorials will focus only on PSP and Python inside PSP.  So at no point will you see me using standard Python.  Everything we do here can be done directly in PSP.

That being said, I do find it useful for me to have Python installed separately so that I can test small commands and methods before adding them into my PSP script.  If you would like to as well, great.  If not, that’s also good.

So right now if you were to go to Python.org you’d see on their webpage two different downloads for Python.  Version 3.6  and Version 2.7.

The reason for this is that technically Version 3 and Version 2 are different languages.  There are some very small basic changes and some very big important changes between the two.  They are both Python.  But, what’s really important, is that PaintShop Pro uses Python 2.

Python was first introduced to PSP back in Version 8 when it was still owned by Jasc.   Back then Python was version 2.2.  Over the past 4 or five versions of PSP we’ve been using Python 2.7.  Which means that for any advanced Python programming, your script will either behave or fail to function in older versions of PSP like PSP8, and you’ll want to be aware of that.

We’ll get into differences in languages, libraries, and the PSP API in general over the course of these tutorials.  Just be aware that if you’re using PSP X8-2018 you’re guaranteed to be using Python 2.7.  So, if you’re going to install Python on your computer, it makes things a lot easier for compatibility to also download python 2.7.

I don’t know if/when newer versions of PSP will change to Python 3.6, but for now we’re on 2.7

At this point, I think I’ve gone over everything I can personally think of for recording and debugging scripts from inside of PSP itself.  If anything else comes up, is added to PSP, or if any questions come up that I can answer I’ll add them to the PSP Scripting 101 tutorials but for now, we’re heading over to our intermediate courses which will focus on how to get started programming scripts manually.

One of the best things about scripting inside PSP is the fact that all scripts are in fact written in Python.  As a language Python is exceedingly powerful on its own, and it only gets better when you begin to use the various libraries available to it.

What you can expect from this next series: Basic Python scripting, the basic Script template, setting up an external editor for scripts(Notepad++, sublime, visual studio, etc), getting started with Gary Barton’s pause Script template for multi-step scripts.

One of the first things I always recommend before someone dives into scripting inside PSP is to get some basic familiarity with the Python programming language.  You don’t have to be an expert or know the ins and outs of the language, just have a basic enough understanding that you’ll be able to recognize what you’re looking at, and be comfortable with Python’s unique use of white space (spaces, tabs, newlines, etc.)

I will, as part of this series, go into a few of the most basic portions of Python myself.  However, I’m not a python expert and so I may miss some important key details.  To get you started here are a few basic resources of learning Python

Next, we’ll focus on resources that are very specific to PSP.

The first of these resources is what’s known as the “Scripting for Script Authors” guide.  This PDF, provided by Corel, covers huge amounts of the underlying logic and purpose of scripting inside PSP.  They cover built-in variables, how to navigate between documents and layers in the UI.  Almost everything a budding young scripter could hope for to help you understand what you’re looking at and how to accomplish some of the most basic tasks inside PSP.  For anyone just getting started, this guide is a must.  It also provides sample scripts to help you become familiar with the code structure.  Some slight updates were made for X6 and X8 but they are mostly all the same.

Secondly, there is the Script API.  The Script API (Application Programming Interface) is a complete list of all of the functions you’re able to call inside PSP from your script.  It includes all of the parameters, some details on what they do, minimum and maximum values, and references to the available constants.  Each version of PSP has a slightly different API, some commands are dropped, renamed, added, but a good majority of all functions are the same across APIs.

Here are a few of the ones that have been released, find the version that is closest to your version of PSP, but try not to use one that is newer than your version of PSP.

Then there is the Corel User to User webforum.  While not the only resource of PSP users with scripting experience, it is where I most hang out and therefore the only one that I can personally recommend.  They have an entire subforum dedicated to scripting.  You can go here to ask questions, get help, or share your own works with the community.

Finally, some of the best resources are just looking at other people’s scripts.  Completed scripts show you not just what can be done, but how they did what they did.  Many of my own scripts are just a hodge-podge of things I’ve seen in other scripts.  Below you’ll find links to various websites with scripts you can download.  Some are free, others are available for purchase.  All are highly recommended

Pixelnook (Gary Barton’s Scripts – Free) – The site has since closed up shop but all of the scripts can be found here:

NOTE: Gary Barton’s Pause Script is a “must have” to create scripts with multiple steps where you want to pause at intervals to do something that would otherwise be difficult or impossible to do from within the script. This might include, for example, aesthetic cropping, image alignment, text attribute selection, etc.

Joske’s Graphic Resources [Free Scripts and more]
http://members.home.nl/j.a.c.backer/gif-index.html

Cassel’s Digital Scrapbooking [Free & Paid scripts, sometimes a free offer or promotion]
http://creationcassel.com/store

Sheilsoft [Paid scripts]
http://www.sheilsoft.com/psp.htm

I would like to start off with, this is not a tutorial on how to fully utilize the History Palette but rather it’s a general overview of how the History Palette can be used to assist you in creating scripts and all of its script specific features.

The History Palette (View -> Palettes -> History) is a palette that lets you see all of the edits you’ve done to an image, quickly undo and redo multiple commands in a single click, and can be used to perform functions on other images as well as saving out scripts.

What’s truly great about the History Palette for scripters are all of the functions available to us as scripters.  The first such functions are the “Save to Script” and “Save to Quickscript” functions.  Both can be accessed by right-clicking in the history palette an choosing them from the context menu.

## Save to Script

So let’s say that you’ve been editing your image and you just created a routine that you think would be excellent as a script.  You could go through the hassle of recreating every step you need, or you could simply use the history palette and the “Save To Script” function.  Save to script will take all of the currently highlighted commands and let you save them out to a script just as if you had been recording the script yourself the whole time.  It’s a great time saver and it lets you make scripts with little to no hassle.

One of the nice things about this is you can pick and choose which items you want to record.  Simply hold the CTRL key down while selecting the items (Make sure you’re clicking on the names and not the eyeball) so you can avoid any unnecessary steps in your script.  On occasion, there may be steps that were undone originally that you still want to have in the final script.  These are called “inactive” commands.  When you use the save to script option you’ll see at the bottom of the save dialog an option to “Save only Active Commands” when this is checked the inactive command will not be saved to the script even if it is one of the selected commands.  So if you have any inactive commands selected for your script you’re gonna want to be careful to uncheck this option before saving.

Once saved, you can run it just like any other script.

## Quickscripts

Now, the other option was “Quickscript.”  Quickscripts are temporary scripts that are meant to be used for quick simple repetitive tasks.  Things you want to be able to do with the press of a button without creating a permanent script.  At the top of the history palette, you’ll see two buttons for quick scripts, Play and Save.  You save a quick script in exactly the same way you save a regular script.  Once the script has been saved you run it by clicking on the “Run quickscript” button.  This button can be run on any open image inside PSP and it’ll run the last saved quickscript.

If you save another quickscript it’ll overwrite the old one making these scripts impermanent.  Quick Scripts are also run in restricted mode.  This means they won’t be able to save or close images.

## Apply to Other Documents

The History palette can also apply any highlighted commands to all other opened images quickly without having to save a script.  Simply highlight the commands you want to duplicate across all other opened images, right-click an select “Apply to other open documents.”  This will automatically apply the command to every open document in PSP.

## Copy to Clipboard

This one is mostly for programmers.  Although PSP does provide an API list of commands it’s sometimes frustrating to try and recreate all of the necessary parameters from this document.  If you want just a quick template of a command to paste into your script you can use the “Copy To clipboard” option inside the History Palette.

Simply run the command you want to grab, then right-click on it an select “Copy to Clipboard”  It’ll place the script text for that command in the clipboard for you to add and tweak in your own script.  No need to track down every detail, just let PSP do most of the heavy lifting for you.

## Conclusion

The History Palette has a number of features that scripters can use to make great scrips quickly and effectively.  From selective saving of commands to scripts to copying detailed data for manual script creation it’s a handy tool.  But its features go beyond just scripting, and I highly recommend exploring and learning about all of its features as it’s a very powerful tool that you may find it useful for everyday editing.

PSP has two modes for executing scripts: Restricted and Trusted.  You’ve probably seen this come up a few times by now, especially if you’ve downloaded third-party scripts or tried to save your own script that closes or opens files inside PSP.  If you place the script into the wrong folder, scripts-restricted instead of scripts-trusted, PSP will throw an error saying you aren’t allowed to do that with a restricted script.

So what is a restricted script and why is it necessary?

PSP uses a very powerful scripting language called Python to write and execute the scripts you use.  Python can do anything from accessing the internet to making changes on your computer.  This can bring great flexibility to your script, it can also do great damage if the script is poorly written or purposely malicious.  To combat this PSP has the restricted folder.  Any scripts placed into this folder have a very limited set of permissions available to them.  Most of the things restricted scripts can do are limited to calling basic functions inside of PSP and doing basic math.

Restricted scripts also cannot: Save files using save or saveas, close open documents, send files via email, or close PSP, cannot access any of the file format optimizers, or even call the batch processing commands.

If your script needs to be able to open and close images you’ll want to make sure to save it to the Scripts-Trusted folder.  Also if you’re downloading third-party scripts that ask you to place the script into your trusted folder, make sure you trust the script explicitly before doing so.

So how are scripts determined to be restricted?  There are several ways that a script can be run in restricted mode

1. If the script is placed in the scripts-restricted folder (default)
2. If a script is run that isn’t in either the restricted or trusted folder using the Run Script command
3. If a file is in both the restricted and trusted folders it’ll be found be found in the restricted folder first and treated as a restricted script
4. Presets, materials, swatches, Print Templates are all run as restricted

There is only one parameter inside the script called “ConvertToRaster” when this is set to 1 it’ll convert the curves adjustment layer into a regular raster layer. By default it’s set to 0, this keeps it a regular adjustment layer.

Thanks to the excellent work and information provided by Teammouse for his own GradientMap scripts ( http://forum.corel.com/EN/viewtopic.php?f=104&t=63266 ) I was able to update my Gradientmap script to use a curves adjustment layer instead of the previous method of using image palettes. The script is almost identical to my previous one with a few simplifications and some extra functions to handle the new way the data is handled.

The end result is faster, with smoother transitions between colors. It also works on multi-layered images whereas the previous one would flatten the image

I’m creating a new post for it because I don’t want to completely delete my old one. Consider the old one a legacy script.

History:

v 1.1 – Added the option to update a current Curves Adjustment Layer instead of making a new one.   Simply select a current Curves Adjustment Layer and run the script, it’ll ask if you want to update the layer, if yes it’ll change the settings.  If no, it’ll make a new layer.
v 1.0 – Initial script upload