Using Windows without show()

Photoshop Script Snippets - Note: Full Scripts go in the Photoshop Scripts Forum

Moderators: Tom, Kukurykus

Andrew

Using Windows without show()

Post by Andrew »

This is a technique I just worked out which is going to save me quite a bit of time. It's obvious so some of you will already have thought of it, but it's new to me and I wish I thought of it a few months ago.

Quite often I find with a complex script that I need it in three forms:

1. Full Process: Get settings, open dialog for user input, save new dialog settings for next time, run process.

2. Run without Dialog: Run process without dialog based on last settings and current File Browser of Bridge selections.

3. Just Get Settings: Just get new settings and save them, prior to doing 2.

I found I could waste quite a lot of time adapting the initial script (1) to purpose 2 and 3, especially the detail of loading and saving the settings and converting them to my working variables.

What I realised just now is that a windows properties exist whether you 'show' them or not. I can create a window and load values into the window object from a settings file, exactly as I would do in 1, but just not 'show()' the window.

This makes all three scripts extremely easy to create. Very little needs to be changed at all.

Here's an example:

Code: Select all// ----------------- Normal Get Settings & Run Mode ------------------------

// load dialog settings, open dialog, save settings

reNameDlg = createRNDialog(); // make window    from resource string   

// load last run settings if a settings file exists, otherwise initialise with defaults

if (settingsFile.exists) loadSettings(settingsFile, reNameDlg); // includes initialising
else if (!initialised){initialiseRNDlg(reNameDlg, myData);}

doRename = reNameDlg.show(); // show window

saveSettings (settingsFile, reNameDlg); // save this runs settings

// Run the main processor

if (doRename) renameFiles(reNameDlg);

// --------------------------------- Get Settings Mode   ---------------------------

// load dialog settings, open dialog, save settings

reNameDlg = createRNDialog(); // make window from resource string      

// load last run settings if a settings file exists, otherwise initialise with defaults

if (settingsFile.exists) loadSettings(settingsFile, reNameDlg); // includes initialising
else if (!initialised){initialiseRNDlg(reNameDlg, myData);}

reNameDlg.show(); // show window

saveSettings (settingsFile, reNameDlg); // save this runs settings


// -------------------------  Run with Existing Settings Mode   ------------------

// load dialog settings, open dialog, save settings

reNameDlg = createRNDialog(); // make window    from resource string   

// load last run settings if a settings file exists, otherwise issue warning

if (settingsFile.exists) loadSettings(settingsFile, reNameDlg); // includes initialising
else {alert('No Existing Settings Found'); return;}   

// Run the main processor

renameFiles(reNameDlg);


I don't know if that will make sense to anyone but anywhere there it is.

Andrew