I am hoping for JavaScript to perform three distinct actions depending on the names of the files that are currently open in Photoshop

Currently, I am in the process of developing a JavaScript script for Photoshop. The main objective of this script is to prompt the user to choose a folder containing multiple files. Subsequently, the script will open each file within the folder and perform specific actions based on the filenames.

Although I have managed to successfully open all the files and apply a single action to them, I am encountering difficulties when it comes to executing different actions for different files.

The structure of the folders would typically include:

(1-18 selected or files with less than 3 characters in their names)

1.psd
2.psd ...
18.psd

(files with "-" in their names)

GHHJKK-1.psd GHHJKK-2.psd ... GHHJKK-5.psd

(files containing the string "zoom" in their names)

zoom_side.psd

zoom_sole.psd

Here is a brief overview of what I have accomplished so far:

#target photoshop

var inputFolder = Folder.selectDialog("Select a folder of documents to process");

function open360() {
    var filesOpened = 0;
    var fileList = inputFolder.getFiles();
    for ( var i = 0; i < fileList.length; i++ ) {
        open( fileList[i] );
        filesOpened++;
    }
}

open360();

var doc = app.activeDocument;

 function shoeSFW() {

/*if (doc.filename.length < 3 ) {
app.doAction("Zoom Side and Sole 360 SFW", "New SFW Actions");

}
*/
for(i = app.documents.length; i > 0; i--){

if(app.documents.length != 0){ 

doc = app.doAction("360 Shoes SFW", "New SFW Actions");
}
}

}
shoeSFW(); 

I would greatly appreciate any assistance with modifying the script to achieve the desired functionality for different types of files. Thank you in advance!

Answer №1

Here is a possible solution to the problem:

for (var i = 0; i < fileList.length; i++) {
        open(fileList[i]);
        filesOpened++;
        if (fileList[i].name.indexOf("zoom") != -1) { //checks for "zoom"
            app.doAction("foo", "bar"); //perform first set of actions
        } else if (fileList[i].name.indexOf("-") != -1) { //checks for "-"
            //perform second set of actions
        } else { //for all other cases
            //perform third set of actions
        }
}

If simply checking for "zoom" and "-" is not sufficient, you can opt for using regular expressions instead.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using NextJS: Customizing page names for cleaner URLs

Currently working on a project in NextJS, I've come across an interesting observation. The file name within my pages folder seems to directly correspond to the path displayed in the URL bar. My question is, can I possibly create a structure like this ...

Incorporating Numerous Location Pointers in Angular-google-maps

I've been struggling to show multiple map markers in my Angular project. I have a service called retsAPI that queries a local MLS database for home listings, and I'm attempting to display these items on a Google map. Below is my controller code. ...

When Infinite Scroll is integrated into another file with HTML tags stacked on top, it will not load additional posts when scrolling down

I have implemented an Infinite Scroll feature that dynamically loads more data from a database as users scroll to the bottom of the page. However, I encountered an issue when trying to include this functionality in another .PHP file. If I insert any HTML ...

Can Angular's built-in internationalization features be used to translate bindings?

Challenge The task at hand involves integrating translations into an Angular 6 application to support static text in multiple languages. The objective is to have the ability to choose a language during the build process without requiring dynamic translati ...

**Finding the Index of a Table Row in Vue-Tables-2**

Recently, I came across some vue code that utilizes vue-tables-2. The table in question is quite simple and looks like this... <v-client-table :data="myRows" :columns="columns" :options="options"> <div slot=" ...

The rendering of HTML DOM is being obstructed on iPhone devices running iOS 13

Currently, I'm developing a web-based URL stream music player using JavaScript. The player functions smoothly on Android devices, but I'm encountering an issue with DOM rendering being blocked on iPhone devices. Despite rearranging the JavaScript ...

Exploring the world of jQuery sliders and dynamically updating div container content

Alright, here's what I have come up with so far: First, take a look at this website to see the idea I am trying to explain: What I am aiming for is this concept: A visitor goes to the provided website and wants to know what type of sandwich they can ...

Creating and adding nested div elements with the power of JavaScript

My goal is to utilize JavaScript for updating the CSS layout as the webpage loads. Below is the code I have been working on: var container = 0; // Total UI Container var containerTitle = 0; // Title Container var article = 0; var articleTitle = 0; var ...

Plugin for saving inline edits in CKEditor 4

After creating a plugin for ajax save, I found the documentation confusing when it comes to implementation. How can I make the button responsive and able to save content using AJAX with PHP? Currently, I am unable to retrieve the content. Directory: /plug ...

After ajax, trigger change event

Can anyone assist me in combining multiple functions within the same form using AJAX? The purpose of the form is to prenote a new "meeting" and it consists of an input for the date and a select dropdown for choosing the operator. FORM CODE: <div id=&qu ...

Reorganizing Elements within an Array using JavaScript

Imagine I have the characters: H, M, L I want to create sorted arrays like this: var array1 = [ "H", "M", "L", "L", "M", "H" ]; My goal is to avoid having more than one unique character in the first three and last three characters when using the shuffl ...

Automatically reconstructing local packages when changes occur

After installing a local package using npm local paths, I am looking for a way to automatically rebuild or re-install the package whenever I make changes to the file. Can anyone help me with this? I have searched online extensively but haven't come a ...

Exploring ngModel components with a specified class

In my HTML code, I've assigned many elements with ngModel defined as ng-model = "object.[something]". For example: <div class="form-group row" ng-model="object.askUser"> I use this method to keep my purpose clear for these elements. My questi ...

Creating vibrant row displays in Vue.js: A guide to styling each row uniquely

I am not a front-end developer, so Vue and JS are new concepts for me. Currently, I am working on an application for managing sales. One of the components in my project involves displaying invoices in a list format. To make the rows visually appealing, I ...

Having trouble aligning a div in the middle of a slick-slider item using flex styling

I've created a slick slider component in Vue, and I'm facing an issue with centering a circular div inside each of the slider items. Despite trying to align and justify center along with adding margin:auto for horizontal centering, I can't s ...

A guide on importing images into a CSS file with Reactjs

Currently, I am utilizing Reactjs (Nextjs) and have placed my images folder within the "public" directory. In my "style.css" file, I adjusted the path for the image, but unfortunately it is not displaying. Can you please help me identify where I may have ...

Adjust the visual presentation based on the chosen option at the top of a column JQchart

Can anyone offer assistance with creating three radio button fields that will display yearly, monthly, or weekly data on a column chart? I have searched through numerous examples in JQchart but haven't found one for this specific scenario. Are there o ...

Challenges arise with the height settings of ui-grid

Currently, I am facing an issue with using height: auto on an angularJS ui-grid. The problem arises from an inline style that specifies a fixed height on the div to which the ui-grid attribute is added. Additionally, the function getViewPortStyle() dynamic ...

Executing JQuery and Ajax calls within a loop

Can I dynamically change the variable in ("xxxxx").html(data) inside a for loop? I've been struggling to figure this out. My goal is to populate an HTML table with JSONP data from multiple ajax calls within a loop, where the URL changes each time. Wh ...

Transition between different segments

Currently working on a sapui5 fiori app, I find myself utilizing multiple fragments based on the mode (read, create, edit). However, I am stuck on how to smoothly navigate from one fragment to another, and more importantly, how to seamlessly return to th ...