PrimalScript: New Code Copy Feature

This article provides an overview of a new feature introduced in PrimalScript build 8.1.177 that allows you to create, compare, and manage copies of your code.


When we get a request to extract source code from a packaged executable, it is inevitably for one of two distinct reasons:

  • The source code was lost because there was no backup.
  • The production code was mangled beyond repair by ‘someone’, and no backup of a working version exists.

The backup issue is just as serious as what we address here, and we cover that subject in another article.

New Icon

PrimalScript has a new icon on the status bar, as shown below:

image

This little icon makes it easy to create, manage, and compare copies of your code.

If you use a version control system like Git or if you store your code on GitHub, you likely create a branch of your code to avoid working on the production version.

Working in an air-gaped network keeps you off GitHub; more often than not, users do not create Git repositories for a single script file that resides on a network share. However, this exact scenario can create the most havoc. For example, you (or “someone”) are working on the production version of your Enterprise Active Directory Management script while everyone else is running the same script you are modifying. I cannot stress enough that you absolutely should not do that.

Create a New Copy

Right-click on the status bar icon to bring up the menu and select ‘Add new copy…’:

image

You will be prompted for a name (prefilled with your user name). You can name it anything you like; just avoid characters that are not allowed in file names ( \ / ? : * < > | ” ). Then, PrimalScript will close the original file and open the new copy.

The name you assigned will appear in square brackets. A number may follow the name if you create multiple copies with the same base name; for example, Webrequest[Alex 1].ps1, Webrequest[Alex 2].ps1, etc. We use square brackets instead of round ones to avoid colliding with naming conventions that cloud drives like DropBox or OneDrive use.

image

If you right-click on the status bar icon while a copy is active, other functions become available:

image

These are pretty straightforward, but you should try them once anyway.

Close and Remove

The ‘Close and Remove’ function will prompt you before deleting the file you have open. If you choose to delete the file and later regret it, you can find the deleted copy in the Windows Recycle Bin.

Manage Copies

The ‘Manage Copies’ dialog lets you see what copies of that file you have and offers some direct functions to Open, Compare, and Remove copies:

image

Once again, the ‘Remove’ function moves a file to the Windows Recycle Bin rather than deleting a file permanently.

I want to point out that this new functionality avoids letting you create a copy of a copy; it might get too complicated if you are three levels away from the original when there is just a file naming convention to determine what is a copy of which file.

Compare

The ‘Compare to original…’ function opens the original file and your selected copy, allowing you to merge changes in ScriptMerge. It is important to remember that while you make changes to the copy you created, someone else may modify the original file. ScriptMerge will show you that and enable you to move these changes to your working copy. Please note that files saved in ScriptMerge that are also open in PrimalScript will automatically and without prompt reload in PrimalScript.

image

We hope this new feature helps you better manage the process of updating your production scripts. It is well worth it if this prevents one mishap or mangling of a critical file.

Related

Feedback

As always, please feel free to leave feedback or feature requests in the comments below. If the comments are closed, you can always post in our SAPIEN Support Forum.