Secure your scripts

Upload Photoshop Scripts, download Photoshop Scripts, Discussion and Support of Photoshop Scripts

Moderators: Tom, Kukurykus

Mikeal.Sim

Secure your scripts

Post by Mikeal.Sim »

I've been working on securing my code for a release. I notice that every once in a while something pops up on the forum regarding this but no one has a great complete option. I'm posting several bits of code I have either found on this forum or developed myself to at least try and consolidate some of this info.


Unstoppable code:
This code can not be stopped by the user (ESC Key, or cancelled) without running your clean up code. You can catch other errors with this as well. I have other security code below that I will also include this in for added protection.

more info: bb/viewtopic.php?t=1695&highlight=prevent+esc

Code: Select alltry{
[
//code that shouldn't be stopped

}catch(e){
if (e.number == 8007) {
//on cancel, code here
}
else{
//other error code here, "throw e" will display the error, remove to hide.
;throw e;
};
};

No History:
Prevent script from populating the history... sort of.
Instead of a bunch of tell-tail steps showing up in history you can group a bunch of actions into one big step in the history.
Problem: cannot use semicolons, instead use commas


Code: Select allapp.activeDocument.suspendHistory("New history Name", "CODE HERE"),


these last two can easily be combined for extra protection.
Code: Select alltry{
[
app.activeDocument.suspendHistory("running script", "Code Here!, history protected");

//more code here, if you want. history not protected here

}catch(e){
if (e.number == 8007) {
//on cancel, code here
  }
else{
//other error code here, "throw e" will display the error, remove to hide.
;throw e;
};
};



Hide Menus
this code also includes some of the protections listed above already. it could be simpler or better written, but I'm not a programmer.

it first copies the current layer into a new document
saves the workspace under the name of a random number, if it cant it closes the new document
then resets the pallets which has the same wonderful effect as opening the default workspace w/o prompts. It then closes every open palette leaving an empty screen. No layers menu, no history visible. Can still see the document though.

then runs your code, if it fails, closes the doc first, then displays the error

To show all the menus that were hidden it simply loads the saved workspace, then deletes the workspace so no traces are left. If the user tries to cancel the load workspace (there is a prompt) it gives them advice to accept.
from my testing no matter the menu palette configuration this will work great.


hiding the menus is also action-able, which I'll also include.
Mikeal.Sim

Secure your scripts

Post by Mikeal.Sim »

CS4 UPDATE:

Hide Menus:
My hide menus idea is now outdated. Adobe saw the need, and replaced this with a single command.


Code: Select alltogglePalettes()