2009-10-07

Find the Scripts Panel Folder

Part of a Script to Install Scripts

I've been thinking for some time of a foolproof method of installing scripts at remote sites. Almost all of the script writing I do is done for sites that I never get to visit. The sites contract me to do the automation and I send the scripts and the invoice. Generally the installation process isn't a problem, but some sites have never looked inside the Adobe InDesign or Adobe InCopy application folder to see where the scripts get installed. And some sites don't have any managed approach to installing scripts other than walking around to each machine (it is actually hard for me to imagine that, but it is true). So to make things easier, I've wanted a script that would either self install or an installer script would do the installation.
This generic function is the start of that process. If your script contained something like:

#target indesign
var scriptsPanelFolder = findScriptsPanelFolder() ;

Then that 'scriptsPanelFolder' variable would contain a Folder object for the Adobe InDesign CS3 or CS4 Scripts Panel folder. Remember this isn't 'true' JavaScript where working with folders isn't allowed, this is ExtendScript where working folders is encouraged.

From that location, it would be easy to go up one more parent and test for the 'Startup Scripts' if you needed to install something there.

By the way, add a line like this:

scriptsPanelFolder.execute()

And that scripts panel folder will open. And that .execute() method works in Windows or Mac OS. It is both an ExtendScript File and Folder object method.


//
function findScriptsPanelFolder () {
//-------------------------------------------------------------------------
//-- F I N D S C R I P T S P A N E L F O L D E R
//-------------------------------------------------------------------------
//-- Generic: Yes, for both Mac OS and Windows
//-- any version of ExtendScript, but only for
//-- the CS3 and CS4 versions of Adobe InCopy or Adobe InDesign
//-------------------------------------------------------------------------
//-- Purpose: to locate the Scripts Panel for Adobe InCopy or Adobe
//-- InDesign when a script is launched from an unknown location
//-- (like the downloads folder). The reason is that if you want
//-- to use a script to install a script, this is a necessary part
//-- of the process. This function requires the user of a
//-- #target incopy
//-- or
//-- #target indesign
//-- line in the script file calling this function. Without that
//-- there will be nothing to signal the script where to start
//-- looking.
//-------------------------------------------------------------------------
//-- Returns: A Folder object for the Scripts Panel folder
//-------------------------------------------------------------------------
//-- Calls: Itself, the function is recursive.
//-------------------------------------------------------------------------
//-- Sample Use:
//~ var scriptsPanelFolder = findScriptsPanelFolder() ;
//-------------------------------------------------------------------------
//-- Written by Jon S. Winters starting on 2009.07.18
//-- eps@electronicpublishingsupport.com
//-------------------------------------------------------------------------

//-- If the function was not passed any arguments, then start at what
//-- ExtendScript calls the 'startup' folder. This will be several
//-- layers deep within the Adobe Application.
//-- However, if the function was passed an argument there will be one
//-- and we want to use it as the starting point. This allows the
//-- funciton to call itself recursively. See the last line of the
//-- function to see the recursive call.
//-- Note: Wanted to use the alternative form of the If statement,
//-- but it wouldn't post on the blog, so the long form is here.
if ( arguments.length == 0 ) { var currentFolder = Folder.startup }
else { var currentFolder = Folder ( arguments[0] ) }


//-- Calculate the path for the 'Scripts Panel' folder from the curentFolder.
//-- Then check to see if that folder exists. If it exists, return to the caller.
var possible = Folder ( unescape ( currentFolder + '/Scripts Panel' )) ;
if ( possible.exists ) return possible ;
//-- implied else;
//-- If here, look one layer up from the current folder. Do this by
//-- calling the function recursively.
return findScriptsPanelFolder ( currentFolder.parent )
}
//

No comments:

Post a Comment