Script commands on several files in the folder

Hello

I am very new to JavaScript and I combinded a few codes that I found here to build a swatch color replacement tool. It works very well! The only issue I'm having is that it only works on a single file in the selected folder. I would like that it works on all files in the folder. Am I missing a loop function? Any help much appreciated. Thank you.

Main code [the script starts here]

Uncomment to delete the Illustrator warning dialog boxes

app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;

var destFolder sourceFolder, files, type sourceDoc file, targetFile, pdfSaveOpts;

Select the source folder.

sourceFolder = Folder.selectDialog ("select the folder with the Illustrator");

If a valid file is selected

If (sourceFolder! = null)

{

files = new Array();

fileType = prompt ("select the type of Illustrator files you want to process.") For example: * .ai ',' ');

Download all the files that match the pattern

files = sourceFolder.getFiles (file type);

If (files.length > 0)

{

Get the destination to save files

destFolder = Folder.selectDialog ('Select the folder where you want to save the files.', ' ~');

destFolder = sourceFolder;

for (i = 0; i < files.length; i ++)

{

sourceDoc = app.open (files [i]); Returns the document object

App.Paste)

App.Cut)

var docRef = sourceDoc;

with (docRef) {}

var replaceColor1 = swatches.getByName('YELLOW_Final').color;

for (var i = 0; i < pathItems.length; i ++) {}

with (pathItems [i]) {}

If (filled == true & & instanceof SpotColor fillColor) {}

If (fillColor.spot.name == 'Yellow TEMP') fillColor = replaceColor1;

}

If (stroked == true & & strokeColor instanceof SpotColor) {}

If (strokeColor.spot.name == 'Yellow TEMP') strokeColor = replaceColor1;

}

}

}

for (var j = 0; j < stories.length; j ++) {}

with (stories [j]) {}

for (var k = 0; k < characters.length; k ++) {}

with (characters [k] .characterAttributes) {}

If (instanceof SpotColor fillColor) {}

If (fillColor.spot.name == 'Yellow TEMP') fillColor = replaceColor1;

}

If (instanceof SpotColor strokeColor) {}

If (strokeColor.spot.name == 'Yellow TEMP') strokeColor = replaceColor1;

}

}

}

}

}

}

sourceDoc.save ();

sourceDoc.close ();

}

}

}

on the other

{

Alert ("no file found");

}

ZINGERERs wrote:

-J' I combinded some codes I found here

You should always reference it these discussions/messages/links, so that we can see the code of original work before tinkering it upward with the changes. I think that its the following thread:

Muppet Mark Code: http://forums.adobe.com/message/2570586

ZINGERERs wrote:

The only issue I'm having is that it only works on a single file in the selected folder. I would like that it works on all files in the folder.

It works in my test (I did a few test files) and used code marks in some batch code I use. Give it a try, works very well in my tests.

app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
var filesFolder = Folder.selectDialog('Select the folder where the (.ai) files are located.', '~');
if (filesFolder != null) {
    var filesArray = new Array();
    filesArray = filesFolder.getFiles("*.ai");
    if (filesArray.length > 0) {
        var saveToFolder = filesFolder;
        var curDoc;
        for (var f = 0, l = filesArray.length; f < l; f++) {
            curDoc = app.open(filesArray[f]);
            // ------------------------------
            // Muppet Mark Code:
            // Thread: http://forums.adobe.com/message/2570586
            with(curDoc) {
                var replaceColor = swatches.getByName('YELLOW Final').color;
                for (var i = 0; i < pathItems.length; i++) {
                    with(pathItems[i]) {
                        if (filled == true && fillColor instanceof SpotColor) {
                            if (fillColor.spot.name == 'Yellow TEMP') fillColor = replaceColor;
                        }
                        if (stroked == true && strokeColor instanceof SpotColor) {
                            if (strokeColor.spot.name == 'Yellow TEMP') strokeColor = replaceColor;
                        }
                    }
                }
                for (var j = 0; j < stories.length; j++) {
                    with(stories[j]) {
                        for (var k = 0; k < characters.length; k++) {
                            with(characters[k].characterAttributes) {
                                if (fillColor instanceof SpotColor) {
                                    if (fillColor.spot.name == 'Yellow TEMP') fillColor = replaceColor;
                                }
                                if (strokeColor instanceof SpotColor) {
                                    if (strokeColor.spot.name == 'Yellow TEMP') strokeColor = replaceColor;
                                }
                            }
                        }
                    }
                }
            }
            // ------------------------------
            curDoc.save();
            curDoc.close();
            curDoc = null;
        }
    } else {
        alert('No Illustrator (.ai) files found');
    }
}

Let us know if it works for you, and if it was useful.

Tags: Illustrator

Similar Questions

  • I want to move virtual machines to a folder called Linux name, but we have several file of the same name in our Datacenter, please give me PowerCLI Script to move exactly

    I want to move virtual machines to a folder called Linux name, but we have several file of the same name in our Datacenter, please give me PowerCLI Script to move exactly.

    I tried to use for the function FolderByPath below, but don't know how to use it and have worked. Please help me in this.

    Function Get-FolderByPath {}

    < #.

    . Records of recovery SYNOPSIS by giving a path

    . DESCRIPTION the function will retrieve a record by its

    path. The path can contain any type of leave (folder or)

    Data Center).

    . Author NOTES: Luc relaxing

    . Path PARAMETER

    The path to the folder.

    This is a required parameter.

    . Path PARAMETER

    The path to the folder.

    This is a required parameter.

    . PARAMETER separator

    The character used to separate the leaves in the

    path. The default value is ' / '.

    . EXAMPLE OF

    PS > Get-FolderByPath-path ' Datacenter/Folder1/Folder2 ".

    . EXAMPLE OF

    PS > Get-FolderByPath-path "Folder1 > Folder2"-separator ' > '

    # >

    (param

    [CmdletBinding()]

    [parameter (Mandatory = $true)]

    [System.String []] ${Path}.

    [tank] ${delimiter} = ' / '.

    )

    {in process

    If (((Get-PowerCLIConfiguration).)) DefaultVIServerMode - eq "Multiple") {}

    $vcs = $defaultVIServers

    }

    else {}

    $vcs = $defaultVIServers [0]

    }

    {foreach ($vc to $vcs)

    {foreach ($strPath in $Path)

    $root = get-file-name of the server data $vc centers

    $strPath.Split ($Separator) | %{

    $root = get-inventory-name $_-location $root - server $vc - NoRecursion

    If ((Get-stocks-localisation $root-NoRecursion |)) Select--ExpandProperty name)-contains "vm") {}

    $root = get-inventory-name "vm" - location $root - server $vc - NoRecursion

    }

    }

    $root | where {$_-is [VMware.VimAutomation.ViCore.Impl.V1.Inventory.FolderImpl]}|% {}}

    Get-file-name $_. Name - location $root. Parent - Server $vc

    }

    }

    }

    }

    }

    You can try to retrieve the object file by steps as well.

    Something like this for example

    $folder = get-data center-name 'LTX01-G8 | Get-file-name "LTX-servers | Get-file-name "LTX servers 0000 - 0299. Get-file-name Linux

    I guess the first qualification in your path was the data center.

  • How to avoid the FDM-command being moved files from the OpenBatch folder

    Hello world

    I have a little problem with Batch Processing of the FDM - I need to stop the movement of files in the folder OpenBatch - when a batch is executed.

    The installer by using the Task Manager, a load a Batch Script and Script integration all works very well. However, the process must run every 3 hours, so I need the file "A_LedgerTransLocation_Actual_nov - 2013_RR.txt" to remain in the \Inbox\Batches\OpenBatch\ folder at any time.

    How to avoid the file is moved?


    Best regards
    Frederik




    PS: I noticed on the OTN Forum is it may be possible to script a solution such as:

    FSO1 = CreateObject ("Scripting.FileSystemObject") set
    Set File1 = FSO1. GetFile ("FDM Directory\FDM Application\Inbox\Batches\Openbatch\A_LedgerTransLocation_Actual_nov-2013_RR.txt")
    The BATCHENG value. PcolFiles = BATCHENG.fFileCollectionCreate (CStr (strDelimiter), File1)

    However this is not possible, as the controllers of the company need to edit the. TXT file themselves. They will not be able to edit the script too.

    I don't think you can prevent the FDM, move the file. I'm assuming that the file change in each period to use the last period of POV, so I think that option easiset to copy the file (based on a part of the name (location?) to a temporary location before began the FOM and write again later.)

  • Move the file in the folder of the same name in AppleScript

    I had a problem with the script below. Basically, on the execution of the script, I want to create folders based on the name of the file and move the files in the files of autocorrelation. However, at the minute, that I'll have to choose the folder in which the script should run.

    Folder to choose a folder

    say application 'Finder '.

    located fileList to the name of every file in Folder with name extension is "m4v".

    end say

    the value point text delimiters to ".".

    Repeat with dittos in list of files

    get each text element of dittos

    masterFile defined in the point 1 of the result

    say application 'Finder '.

    create a new folder to Folder with properties {name: masterFile}

    move (each file from the folder Folder whose name contains masterFile) will cause

    end say

    end Repeat

    Ideally, I would like it to run automatically, but the folder is on an external hard drive. (\Volumes\Lacie\Movies). and I had problems to use the POSIX and 'alias' to properly re-create the path of the file desired.

    Any help would be greatly appreciated. Thank you!

    Hello

    You can try something like the AppleScript script which is a simple shell script wrapper.

    set d to (choose folder)'s POSIX path
    do shell script "/bin/bash -s <<'EOF' - " & d's quoted form & " 2>&1
    cd \"$1\" || exit
    shopt -s nullglob
    for f in *.m4v
    do
        m=${f%.*}
        [[ -d $m ]] || mkdir -p \"$m\" || continue
        mq=$(sed 's/[^[:alnum:]]/\\\\&/g' <<< \"$m\")   # quote meta characters for regex
        find -E . -depth 1 -type f -iregex '.*/'\"$mq\"'.[[:alnum:]]+$' -print0 | xargs -0 -J% mv % \"$m\"
    done
    EOF"
    

    For example, given that you choose/path/to/directory in the folder - source

    Input state:

    /path/to/directory/abc.m4v
    /path/to/directory/abc.txt
    /path/to/directory/abcd.m4v
    /path/to/directory/abcd.txt
    

    Status of the output:

    /path/to/directory/abc/abc.m4v
    /path/to/directory/abc/abc.txt
    /path/to/directory/abcd/abcd.m4v
    /path/to/directory/abcd/abcd.txt
    

    Briefly tested under OS X 10.6.8 but no guarantee of any kind. Please make sure that you have a full backup of the original files and directories before you run this kind of script.

    Good luck

    H

  • Download the files from the folder on the external drive

    I have this script that opens the most recent file in a folder.

    However I have now moved to an external drive.

    I thought I would use this line

    last element of the value latestFile (sort (get the files in the folder "HotFolderA" of the "Dropbox folder" from the folder "CloudStorage" in the folder "Volumes" of the file ((path to the startup disk))) by creation date) as alias

    but that

    Result:

    error "' Finder has been an error: cannot get the file \"Volumes\ ' startup disk. " ' number-1728 of the folder "Volumes" of startup disk

    How can I do it keep this method?

    Matt

    tell application "Finder"
      set latestFile to last item of (sort (get files of folder "AA" of folder (path to desktop folder)) by creation date) as alias
    set fileName to latestFile's name
    
     open latestFile
    end tell
    

    You used the backslash \ (like Windows) instead of the slash /.

  • Give permission to the domain users to replace the file in the folder created by domain admin

    We have a domain controller in our network. also we have the domain users and domain administrator. We create a batch file that copies a file to the folder by using a script to the server policy when users open a session input/output. However if the admin area access system cant use overwrite file in the folder. We want to give permission to the domain users to replace the file in the folder created by the domain administrator.

    Hello

    The question you posted would be better suited in the TechNet Forums. I would recommend posting your query in the TechNet Forums.

    http://social.technet.Microsoft.com/forums/en/category/w7itpro, w8itpro, windowsvistaitpro, windowsxpitpro, windowsintune

    Hope the information is useful.

  • Return of the mistake of MUSE: why do we not have several files with the same name?

    Well - I thought I had all this worked and fixed, but I met the download error 'Why do we have several files with the same name' once again.  (I downloaded all the files several times today in order to 1) works the way it worked the last time and 2) get an OAM file that is not loading for some reason any load again and the download takes about an hour to transfer all the files manually.

    To recap:

    (1) an option "Upload only modified files" returns the 'Muse has encountered an error and closes.  Why do we have several files with the same name? "error just as before.

    (2) a full download will work but takes forever and is NOT a substitution for work changed files option.

    Please advise with possible solutions!

    -Dave

    Is it possible to have two .oam different files in different folders on your computer where the .oam files have the same name? I'm theorizing that there may be a bug in the treatment to ensure the folder created for a .oam placed on the server receives a unique name, particularly in the case of a partial update of the site on the server.

    Please send us the .muse file and all the files in .oam related to [email protected] along with a link to this topic for the context so we can attempt to reproduce this error and isolate the root cause. If files are larger than 20 MB, you'll need to use a service such as Adobe send & Track, Dropbox, creative cloud, WeTransfer, etc. file sharing. Thank you.

  • Help! Need a script to automatically open files with the same name but in another location.

    Good morning friends,

    So for my work, I need a script to open files with the same name but located in a different folder. But since I'm a total noob when it comes to programming, I can't understand how do. That's what I have in mind:

    -J' I manually open an image.

    -The script will look for a file with the same name in another folder that I've specified.

    -The script will then select the channel CMYK of the second file and copy and paste it into the first file.

    -The second file is then closed without saving the changes.

    I have problems with the part where the script searches for a file with the same name as the opened file. I would really appreciate help. Thanks in advance.

    If (app.documents.length > 0) {}

    myDocument var = app.activeDocument;

    var Nomdoc = myDocument.name;

    try {var basename = docName.match (/(.*)-.)} [ ^\.] +$/)[1]}

    catch (e) {var basename = thedoc.name};

    var path = / * path of folder to insert as a string here * / + ' / ' + base name + / * insert file extension, including the period as a string here * /;

    If (queue (path) .exists == true) {var otherDocument = app.open (File (path))};

    };

  • The Acrobat 9 batch - get PDF files of the folder names?

    Hello

    Can someone give me an example with the use of batch (when the value of a specific folder/files) for a list of the names of files in this folder? I was not able to find examples online. It does not seem be any batch built in sequences that automatically do so I guess it will have to be done with javascript?

    In the end, I need to automate a process (I was hoping to create a batch sequence to do this) which will allow me to invite a user to choose a record source to PDF files and then based on this selection, run a Javascript that I create, which will merge all of the PDF files in this folder into a new PDF apply some culture settings to each page, and then ask the user where to save the merged PDF file?

    Has anyone ever done something like this? I'd love to see an example of how this could be able to achieve.

    Thanks in advance.

    Have you tried to create a batch process to test (now called 'Actions')?  Actions in Acrobat 10 has the 'Merge all the files in the folder' option, and batching in previous versions has always included a commad culture page, but also an option to ask the user where to save the file.

    There are many examples and articles on this topic at http://www.acrobatusers.com

    Thom Parker
    The source for PDF Scripting Info
    pdfscripting.com

    The Acrobat JavaScript Reference, use it early and often

    Then more important JavaScript development tool in Acrobat
    The Console window (video tutorial)
    The Console Window (article)

  • Reading several files / locate the data source during execution

    Hi all

    I have a requirement of the company in which I need to read files to different folders. This system is not hosting the ODI agent. There are two folders, the folder A and folder b. Two records may have any number of files. My intention is to read the files in a folder and write the data to a table in a database that resides in another system. This forms a flow for me. For the B folder, I have a similar flow. All files (in the folder A and folder B) have the same structure. The requirement is to read A book during the week and the B folder on the weekend. The system that has the database also runs the ODI agent.

    Here are my questions:

    1. How can I read several files one by one in a folder? Because the read files must be archived, they need to be written in a different folder, file C (for example). How do you archive part? Please note that this machine does not run ODI agent (network share could be an option, but we try to avoid it.

    2. can I have only an interface to read files in folder A and folder B? Everything else remains the same (the processing logic/transformations etc.). Indeed, is there a way to dynamically switch between two files (using a variable, perhaps).

    I've not worked with files and so any help is greatly appreciated.

    Edited by: Sankash 7 May 2009 08:24

    Hi Sankash,

    Hopefully I can help you achieve this task.

    Please go through this link

    Re: import files in a table

    1. you can update the status of the process of the files in a journal/temp table.
    Based on the State of the (transformed) file in the table, you can check the files that has completed its process correctly.

    machine does not run ODI agent:-J' have it is implemented the same type of scenario, in which I am downlading all the files in a common location and treat it from there.

    2. one of the solutions is that: -.

    create two interface with the same structure, but the source table must point to the folder A and B
    Create a variable (week/check) and based on the value, you can call the interfaces.

    second option: -.

    If you're downlaoding the files in a common location, you can reach the spot through a single interface (down load files from folder A or B according to in week/weelend)

    3. If all the files have the same structure, you need only a data store and it should be a variable data store.

    If something is not not clear please me ping / mail to my id (good that now I don't get enough time to go through the forum discussions)

    Also if you need I can send you a diagram wokflow for this loop (read multiple files one by one in a folder)

    Kind regards
    Pascale of M

  • rearrange the files in the folder "iTunes media" is gray

    I have a good size iTunes media folder which WAS organized in subfolders - music, movies, etc.  I just noticed that my most recent files are not saved in these subfolders.  Instead, everything will be saved in iTunes Media.  When I consolidate files, everything said is it.  I want to rearrange the files in the folder "iTunes media" but this option is grayed out.  Any suggestions on how to get everything converted?  I am looking at about 80 artists a few singles and other full CD.

    iTunes is a database application. You must organize your music within the interface of iTunes and let iTunes organize real files. Otherwise, it's only a matter of time before the database is interrupted.

  • Re: HDR-AS100V-remove the 100AVN folder or the contents of the files in the folder after downloading?

    I was wondering what is the recommended way to free the memory after I downloaded my files do I delete the folder AVN? the files in the folder? or reformat the chip together again?

    Thanks in advance

    Good day Laszlo,.

    We recommend that you format the memory card on the Action cam to free up the storage space on the SD card, this would open up any excess files such as files metadata or exif of previous videos and photos allowing you to maximize the storage capacity of the SD card.

    If my post answered your question, please mark it as "accept as a Solution.

  • In the Finder, how can I search/list of the files in the folder of final characters in filenames, i.e. 'to end-with' alphabetical rather than by default "starting by" alphabetical?

    In the Finder, how can I search/list of the files in the folder of final characters in filenames, i.e. 'to end-with' alphabetical rather than by default "starting by" alphabetical?

    As far as I know, you can't.

  • I can't open the files in the folder "my pictures."

    For the last two weeks, I was unable to open the files in the folder "my pictures." For example, if I save the photo in my pictures, it will not open if I double click on it.
    Someone at - it ideas?
    Thanks in advance.

    Hello Tim

    Is there a message if you want to open it? You can copy data to another folder in my photos and open them?

    You have this problem just with images or even other files?
    Give us more information.

  • Manually remove the iOS App files in the folder "Mobile Applications" on a Mac.

    In my eagerness, trying to save valuable disk space, I deleted all the files (40 GB) in the mobile apps on my mac. This folder has accumulated over 900 files app over the years. I am currently using only 160 apps on my iPhone. I deleted all the files (and emptied the Recycle Bin). After having to remove it, I was unable to download, only the applications that I use currently on the phone (160 of them), in my iTunes again (from the app store in iTunes). This is because iTunes App store thinks that I have already downloaded these applications; where I have deleted just manually in the Mobile Applications folder.

    After reading on the web that it is a mistake, I got cold feet and began a restoration of my time Machine to all 900 app files back.

    I started the process of restoring time Machine is because the thinning app is NOT allowing me to transfer my iTunes on mac purchases. I first thought I can "put" just the 160 apps from my phone, Mobile Applications to iTunes folder. Now, I realize that I can do is not "transfer purchases". I am on iOS 9.2.1 (6s iPhone Plus) and OS X El Captain (10.11.3) (Macbook Air).

    Moreover, I have a PDF file with a list of all the files in the Mobile Applications (900 application files) folder. I did it using an application called Print window. So I did not have a detailed list of all the files (apps) that I never downloaded. This is so that I can download the Apps on my iPhone directly (from the cloud) in case I need an app on my phone, in the future

    Critical how's this for keep the files in the folder of Mobile Applications on my Mac? In which case I have to restore my iPhone, applications will only download from the Cloud? If the answer is Yes to this question, I can go ahead and delete all the files in the folder of Mobile Applications manually to recover a good amount of disk space?

    I hope I'm clear in my question and description.

    Thank you!

    You have more need to keep a local copy of the apps. Any application that you do not have at the time of a restoration is downloaded from the cloud provided that it is always available. You can view your list of 160 apps for everything you'd be really sad to lose and keep a copy of those. You don't necessarily need in the library. As long as you have the file .ipa somewhere you can add new in your library at a later date.

    TT2

Maybe you are looking for

  • Recovery on Equim A100-337

    Hello My wifes laptop has corrupted and I tried to reinstall with the product recovery disc. (Vista Premium) I booted from the DVD. However after seeing - loading windows and then, seeing the small chart with the yellow blocks to run through it, it w

  • linux installation

    Hi guys! I want to install linux (ubuntu) on my mac now, I want you help install me VMware? and you want to install using VMware or boot?

  • DEP maintains close my "my pictures" file before doing anything

    Now, whenever I try to open anything in my photos, data execution prevention area opens and closes the file. I tried the suggestions on this site, but it does not help. I tried to save pictues to another file, but it still happens. I can't do anythin

  • How to lock a folder OR file in windows without using the 3rd party software

    How to lock a folder OR file in windows without using any software of the 3 part,. Please help me if there is another way to lock.

  • Stop programs from running automatically at startup in Vista

    Hello I need to stop a bunch of programs to run automatically when my computer starts. I have about four programs that I need not run unless I open them myself. Their icons are listed in my lower right. A technician told me to stop running and it wou