Creating an installer script

Discussion of Photoshop Scripting, Photoshop Actions and Photoshop Automation in General

Moderators: Tom, Kukurykus

ddbell

Creating an installer script

Post by ddbell »

I am trying to create a basic installer script. I think I've been able to piece something together that will work except I'm not sure how to copy the files from one location to another.

Basically, I need to copy all of the contents from a folder called chroma_key which is in the same folder as the install script into the scripts directory.

Are there and sample codes for copying files and folders from one location to another? I've searched this forum and not found any but I'm sure there is something out there that I'm not finding.

Thanks

Code: Select all#target photoshop

// define the path of the jsx install file
detect_install_file_directory();
installer_dir = new File(detect_install_file_directory()).parent;
//---------------------------------------------

//copy contents from the install folder into the scripts folder
try {
scriptspath = app.path + "/" + localize("Presets/Scripts");
newfolder = Folder(scriptspath +"/"+ "chroma_key") ;
if(!newfolder.exists) newfolder.create();
folder_to_copy_from = installer_dir + "/" + "chroma_key";
copy_contents ();
alert ("The script was installed");   
}
catch (e) {
alert ("There was an error installing the script");   
}

//functions
function copy_contents () {code???????????????}

function detect_install_file_directory() {
   var where;
   try {
      var FORCEERROR = FORCERRROR;
   }
   catch( err ) {
      where = File(err.fileName);
   }
   return where;
}

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

Mike Hale

Creating an installer script

Post by Mike Hale »

Not tested, but something like this should be close.

Code: Select allfunction copy_contents ( sourceFolder, destFolder ) {
   var files = sourceFolder.getFiles();
   for( var f=0;f< files.length;f++){
      var file = files[f];
      if( file instanceof File && !file.hidden ){
         var newPath = new File( destFolder+'/'+decodeURI(file.name) );
         var copied = file.copy( newPath );
         if(!copied) alert('file '+decodeURI(file.name) +' not copied');
      }
   }
}
Paul MR

Creating an installer script

Post by Paul MR »

Just a few comments....
Code: Select all#target photoshop

// define the path of the jsx install file
detect_install_file_directory();  //This is not doing anything!!
installer_dir = new File(detect_install_file_directory()).parent;  //This should be  installer_dir = new Folder(detect_install_file_directory()).parent;
//---------------------------------------------

//copy contents from the install folder into the scripts folder
try {
scriptspath = app.path + "/" + localize("Presets/Scripts"); //localize("$$$/ScriptingSupport/InstalledScripts=Presets/Scripts"));
newfolder = Folder(scriptspath +"/"+ "chroma_key") ;
if(!newfolder.exists) newfolder.create(); // If you have to create this folder there are no files to copy!
folder_to_copy_from = installer_dir + "/" + "chroma_key"; //You have this defined as newfolder
copy_contents (); //BIG problems if on VISTA or  Windows 7 you do not have permission to do this!!!! Need to run as administrator!
alert ("The script was installed");   
}
catch (e) {
alert ("There was an error installing the script");   
}

//functions
function copy_contents () {code???????????????}

function detect_install_file_directory() {
   var where;
   try {
      var FORCEERROR = FORCERRROR;
   }
   catch( err ) {
      where = File(err.fileName);
   }
   return where;
}
Mike Hale

Creating an installer script

Post by Mike Hale »

Thanks Paul, I didn't really pay attention to the other parts of the code. And I forgot that it might need to be run as administrator.
ddbell

Creating an installer script

Post by ddbell »

Paul MR wrote:Just a few comments....


Thanks for you feed back. A couple of questions here.......

--------------------------------------------------

Comment - //BIG problems if on VISTA or  Windows 7 you do not have permission to do this!!!!

Question - Are there any issues for a Mac? I'm using an install .exe file for Windows. This script will only be for Mac.

-------------------------------------------------

Qeustion - what is the difference between these 2 expressions? I've been using localize("Presets/Scripts") to define the scripts directory and haven't been having any problems on either Mac or PC. Should I not be doing it this way? What is the need for the latter?

localize("Presets/Scripts")
localize("$$$/ScriptingSupport/InstalledScripts=Presets/Scripts")

-------------------------------------------------
comments-
if(!newfolder.exists) newfolder.create(); // If you have to create this folder there are no files to copy!
folder_to_copy_from = installer_dir + "/" + "chroma_key"; //You have this defined as newfolder

Question-
Why are newfolder and folder_to_copy_from the same thing?

newfolder - This should be a new folder to created inside the Photoshop scripts directory. If it doesn't exist it is being created.

folder_to_copy_from - This should be a folder from the location of the installer file.

The installer .jsx will be contained in a .zip folder when its distributed. That folder has a sub folder called chroma_key.

What I am trying to do is copy all of the content from the already existing folder called chroma_key into a new folder called chroma_key which is created by the script in the Photoshop scripts folder.

I ran this script with these 2 alerts and it alert 2 different locations which appear to be correct (and different).

alert (newfolder);
alert (folder_to_copy_from);
ddbell

Creating an installer script

Post by ddbell »

Thanks Mike and Paul for your input on this.

After much trial and error (because I'm lousy at javascript), here is a final working product for a Mac install script. I realize that this won't work on Windows Vista / 7. But it works on Mac which is what I need.

I've found that for installing scripts on Windows 7/Vista, a free program called Install Jammer works great. Its really easy to use and creates .exe files. It can auto detect the Photoshop scripts directory as well. The user doesn't need to run anything as administrator to do an install. Here is some info on using this for a Windows Photoshop scripts installer if anyone is interested. http://www.installjammer.com/forums/vie ... shop#p7385 ... shop#p7385


Here is the code for an install script that works on Mac.
Code: Select all#target photoshop

// define the path of the jsx install file
installer_dir = whereAmI();
//---------------------------------------------

//copy contents from the install folder into the scripts folder
try {
scriptspath = app.path + "/" + localize("Presets/Scripts");
newfolder = Folder(scriptspath +"/"+ "chroma_key");
if(!newfolder.exists) newfolder.create();
copy_from = new Folder(installer_dir + "/" + "chroma_key");
copy_contents (copy_from, newfolder);
alert ("The script was installed");   
}
catch (e) {
alert ("There was an error installing the script");   
}

//functions

function whereAmI() {
   var where;
   try {
      var forcedError = FORCEDRRROR;
   }
   catch( e ) {
      where = File(e.fileName).parent;
   }
   return where;
}

function copy_contents ( sourceFolder, destFolder ) {
   var files = sourceFolder.getFiles();
   for( var f=0;f< files.length;f++){
      var file = files[f];
      if( file instanceof File && !file.hidden ){
         var newPath = new File( destFolder+'/'+decodeURI(file.name) );
         var copied = file.copy( newPath );
         if(!copied) alert('file '+decodeURI(file.name) +' not copied');
      }
   }
}