Script labels and findchangebylist.jsx

I am looking for any examples of a script that finds a certain script label on a textframe and then runs findchangebylist.jsx on that textframe.

Hi,
What you need is
1. to simplify function
main()
2. and to modify:
myFindChangeByList(myObject)
myDisplayDialog()
Ad 1.
function main(){
    var myObject;
    //Make certain that user interaction (display of dialogs, etc.) is turned on.
    app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
    if(app.documents.length > 0) myDisplayDialog();
    else alert("No documents are open. Please open a document and try again.");
Ad 2
function myFindChangeByList(myObject){
    var myScriptFileName, myFindChangeFile, myFindChangeFileName, myScriptFile, myResult;
    var myFindChangeArray, myFindPreferences, myChangePreferences, myFindLimit, myStory;
    var myStartCharacter, myEndCharacter;
    var myFindChangeFile = myFindFile("/FindChangeSupport/FindChangeList.txt")
    if(myFindChangeFile != null){
        myFindChangeFile = File(myFindChangeFile);
        var myResult = myFindChangeFile.open("r", undefined, undefined);
        if(myResult == true){
            //Loop through the find/change operations.
            do{
                myLine = myFindChangeFile.readln();
                //Ignore comment lines and blank lines.
                if((myLine.substring(0,4)=="text")||(myLine.substring(0,4)=="grep")||(myLine.substring(0,5)=="glyph")){
                    myFindChangeArray = myLine.split("\t");
                    //The first field in the line is the findType string.
                    myFindType = myFindChangeArray[0];
                    //The second field in the line is the FindPreferences string.
                    myFindPreferences = myFindChangeArray[1];
                    //The second field in the line is the ChangePreferences string.
                    myChangePreferences = myFindChangeArray[2];
                    //The fourth field is the range--used only by text find/change.
                    myFindChangeOptions = myFindChangeArray[3];
                    switch(myFindType){
                        case "text":
                            if (myObject instanceof Array)
                                for (var k = myObject.length - 1; k >=0; k--)
                                myFindText(myObject[k], myFindPreferences, myChangePreferences, myFindChangeOptions);
                            else myFindText(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions);
                            break;
                        case "grep":
                            if (myObject instanceof Array)
                                for (var k = myObject.length - 1; k >=0; k--)
                                myFindGrep(myObject[k], myFindPreferences, myChangePreferences, myFindChangeOptions);
                            else myFindGrep(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions);
                            break;
                        case "glyph":
                            if (myObject instanceof Array)
                                for (var k = myObject.length - 1; k >=0; k--)
                                myFindGlyph(myObject[k], myFindPreferences, myChangePreferences, myFindChangeOptions);
                            else myFindGlyph(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions);
                            break;
            } while(myFindChangeFile.eof == false);
            myFindChangeFile.close();
function myDisplayDialog(){
    var myObject, mFramesLabels, mFrames = [];
    var myDialog = app.dialogs.add({name:"FindChangeByList"});
    with(myDialog.dialogColumns.add()){
        with(dialogRows.add()){
            with(dialogColumns.add()){
                staticTexts.add({staticLabel:"Search Range:"});
            var myRangeButtons = radiobuttonGroups.add();
            with(myRangeButtons){
                radiobuttonControls.add({staticLabel:"Document", checkedState:true});
                radiobuttonControls.add({staticLabel:"Selected Story"});
                radiobuttonControls.add({staticLabel:"Labeled Frames"});
                if(app.selection[0] && app.selection[0].hasOwnProperty ("baselineShift") && app.selection[0].contents != ""){
                    radiobuttonControls.add({staticLabel:"Selection", checkedState:true});
    var myLabel = textEditboxes.add({staticLabel:"Label:", minWidth: 185});
    var myResult = myDialog.show();
    if(myResult == true){
        switch(myRangeButtons.selectedButton){
            case 0:
                myObject = app.documents.item(0);
                break;
            case 1:
                myObject = app.selection[0].parentStory;
                break;
            case 2:
                mFramesLabels = app.documents.item(0).textFrames.everyItem().label;
                for (var k = 0; k < mFramesLabels.length; k++)
                    if(mFramesLabels[k].length && mFramesLabels[k] == myLabel.editContents)
                    mFrames.push(app.documents.item(0).textFrames[k]);
                myObject = mFrames;
                break;
            case 3:
                myObject = app.selection[0];
                break;
        myDialog.destroy();
        myFindChangeByList(myObject);
    else{
        myDialog.destroy();
Make a copy with mentioned function replaced with.
Enjoy
Jarek

Similar Messages

  • View all script labels and find an object by its script label

    Hello,
    I have an InDesign document in which many objects get a script label. I know how to view and edit the script label of an object, but is it possible to:
    1 - See a list of all the script labels of the document (as can be done with the styles for example)?
    2 - Search an object in the document by its script label?

    If you are using OSX this AppleScript displays a list of document labels:
    global labels
    set labels to []
    tell application "Adobe InDesign CS6"
        set x to every page item of active document
        repeat with i in x
            if class of i is group then
                my checkGroup(i)
            else
                my getLabel(i)
            end if
        end repeat
        display dialog labels as string
    end tell
    on checkGroup(g)
        tell application "Adobe InDesign CS6"
            set gi to all page items of g
            repeat with a in gi
                if class of a is group then
                    my checkGroup(a)
                else
                    my getLabel(a)
                end if
            end repeat
        end tell
    end checkGroup
    on getLabel(pageitem)
        tell application "Adobe InDesign CS6"
            if label of pageitem is not "" and label of pageitem is not in labels then
                set labels to labels & label of pageitem
            end if
        end tell
    end getLabel

  • Script Label feature exhibits unexpected behavior. Is it a bug?

    If I create a table, select a cell on any row, apply a Script Label (using Window -> Utilities -> Script Label), and then insert a new row above or below it, the new row will have the same script label in the same column. I can't imagine this being by design so it sounds like a bug.
    Has anyone else encountered this? If so, have you implemented any workarounds? I'm thinking I might have to write a post-insertion process to detect when a row is created and remove all the script labels for that row, but that seems like a lot of work. I'd have to check all the rows in the table, because if I insert multiple rows in one operation, they all inherit the original row's script labels.
    I'm using the CC2014 SDK, but I wouldn't be surprised if this occurs on all versions.
    Thanks for any feedback.
    Bob

    I can reproduce it as well. Feels like a bug...
    Locking the variable for read in code has the same effect:
    public void Main()
    // Lock variable for read
    Dts.VariableDispenser.LockForRead("User::myStringVariable");
    // Create a variables 'container' to store variables
    Variables vars = null;
    // Add variable from the VariableDispenser to the variables 'container'
    Dts.VariableDispenser.GetVariables(ref vars);
    // Now try giving it a new name
    vars["User::myStringVariable"].Value = "new value";
    // Release the locks
    vars.Unlock();
    Dts.TaskResult = (int)ScriptResults.Success;
    For reference:
    https://connect.microsoft.com/SQLServer/Feedback/Details/991697
    Please mark the post as answered if it answers your question | My SSIS Blog:
    http://microsoft-ssis.blogspot.com |
    Twitter

  • Duplicate script label warning into preflight panel - possible?

    Hello!
    Duplicate script labels are creating problems for us.They occur when our graphic designers copy a picture box and forget to change the script label, resulting in two identical images - if the indesign document is closed - and reopened.
    Is there any way to either provide a warning for duplicate script labels, and/or a insert duplicate script label-warning in the preflight panel?

    Hi Hans,
    Thanks for that suggestion.Simple and affective.
    Cheers!
    Date: Fri, 22 Mar 2013 01:07:21 -0700
    From: [email protected]
    To: [email protected]
    Subject: Indesign script for locating metadata in images
        Re: Indesign script for locating metadata in images
        created by -hans- in InDesign Scripting - View the full discussion
    Why scripting¿ http://forums.adobe.com/servlet/JiveServlet/downloadImage/2-5169242-310155/450-213/Copyrig ht.png
         Please note that the Adobe Forums do not accept email attachments. If you want to embed a screen image in your message please visit the thread in the forum to embed the image at http://forums.adobe.com/message/5169242#5169242
         Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/5169242#5169242
         To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/5169242#5169242. In the Actions box on the right, click the Stop Email Notifications link.
         Start a new discussion in InDesign Scripting by email or at Adobe Community
      For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

  • CS3 Script Label not found

    Hi all,
    Very much a newbie with InDesign Scripting, but I've managed to build a script that does exactly what I want - almost.
    It opens a document, looks for a Script Label, and when it's found, it does something with the item's contents. The only problem is that some of the documents don't have a Script Label, and should therefore be ignored. I've taken this code from one of the supplied examples:
    var myPageItems = myPage.pageItems.item("myScriptLabel");
    var myString = myPageItems.contents;
    If there are no items called "myScriptLabel", the second line will generate an error. How do I test whether the myPageItems actually contains any pageItems? I've tried all the obvious things I can think of, but have had no success. I'm sure the answer has to be a simple one.
    Thanks,
    Bruce

    Hi Bruce,
    Hm. I thought that this would return an array, but it doesn't--it returns a single page item, even if a.) there are no objects with that label, b.) there is one object with that label, and c.) there are multiple objects with that label. If all you want to do is set some property of all of the returned page items, this is a good thing. But if you want to do something else, it makes it more difficult. Here's a basic script that shows how to deal with it. It's probably quicker than looping through every page item.
    var myDocument = app.documents.add();
    var myRectangle = myDocument.pages.item(0).rectangles.add({label:"myLabel"});
    var myRectangle = myDocument.pages.item(0).rectangles.add({label:"myLabel"});
    var myObjectList = myDocument.pages.item(0).pageItems.item("myLabel");
    try{
    //If the object is not valid, the following line will throw an error.
    switch(myObjectList.id.constructor.name){
      case("Number"):
       //Do something with the object.
       alert("Object ID is: " + myObjectList.id);
       break;
      case("Array"):
       //Do something with each object (you can use objectByID to get a
       //reference to each object).
       for(var myCounter = 0; myCounter < myObjectList.id.length; myCounter++){
        alert("Object ID is: " + myObjectList.id[myCounter]);
       break;
    catch(myError){alert("eh")}
    Thanks,
    Ole

  • Script label: Set and get it?

    Hi
    How can I set and get the script label of a frame in my plugin?
    Thanks for the help.
    Best regards
    Hans

    Hi,<br /><br />the IScript-Interface has a GetTag() and SetTag() method. While GetTag() is fine, you'll get Asserts when using SetTag() - thus I changed that to  processing kSetScriptingTagCmdBoss.<br /><br />Example (script-label on a splineitem, stripped of nil-pointer-checks):<br /><br />InterfacePtr<IScript> script(itemRef, UseDefaultIID());               <br />PMString label = script->GetTag();<br />ScriptList scriptList.push_back(script);<br />InterfacePtr<IScriptManager>scriptMgr(Utils<IScriptUtils>()->QueryScriptManager(kScript TagMgrBoss));<br />InterfacePtr<ICommand> cmd( CmdUtils::CreateCommand(kSetScriptingTagCmdBoss));<br />InterfacePtr<IScriptTagCmdData> scriptTagData(cmd, UseDefaultIID());<br />scriptTagData->SetScriptList(scriptList, scriptMgr->GetRequestContext(), label);<br />cmd->SetItemList(UIDList(itemRef));<br />ErrorCode err = CmdUtils::ProcessCommand(cmd);<br /><br />Regards,<br /><br />Bernt

  • When I try to run a FindChangeByList.jsx in InDesignCS4, it will not let me select a txt file

    Hi all,
    I have a 100 page document that uses two javascript FindChange queries to cleanup an imported XML file. I've been using the same cleanup files for years and they have worked just fine. (I still only open it in CS4 because I've had some issues when trying to use this XML/Find-Change combo in CS5 and 6.) The only difference is my computer has been upgraded, the apps reinstalled, and I am now running 10.9.5
    I can import the XML just fine into my template, but when I double click on FindChangeByList.jsx, select Document, hit OK, nothing happens. I do not get a second dialog box asking me to choose my txt cleanup file.
    I only run this job once a year, so it's possible I am doing something wrong. I've place copies of my txt files in as many scripts folders as I can find on my computer, but they are greyed out in the FIndChange Support folder within InDesign.
    Please help, this is the only way to fix this XML!

    Hi,
    2 things:
    1. Assuming your script is original - it is not asking for a TXT file till it is found in expected location. You can choose between 2 solutions:
         to remove FindChangeList.txt from FindChangeSupport folder ==> script will ask for another file
         to override this file by your query ==> script will not ask but execute your query
    2. You can see greyed TXT files in Script Panel since this panel shows executable files (script's formats)
    Jarek

  • FindChangebyList.jsx Recently Stopped Working

    Hi,
    I use the FindChangebyList.jsx (standard script that comes with InDesign) very often. It has recently been throwing an error that I cannot troubleshoot . Anyone have any ideas on what’s going on? Running InDesign CS5.0 ver 7.0.4, Windows 7. It looks like something to do with preferences, maybe a clear user preferences is in order?

    Hi Larry,
    I made sure the upper left dropdown has InDesign selected and ran it again. I have now received an error that I was not getting before, see below. Should I trash my user settings?

  • Script Label insert into FileName

    Any help would be greatly appreciated!
    This is a portion of "PageExporterUtility5.0.js" that I'm tailoring to use at our workplace. Finding a simple description of how to use the "Script Label" is stumping me. How would you modify the following to work? My InDesign document has a Text Frame that I'd like to utilize the text contents in the filename. The text frame has been identified with a "Script Label" called "DOC_SIZE". An example of the text contents would be "18X24" (which is not the actual page size, just a rough description is needed).
    Current Base Name:
    816069-OHI-none-none.indd
    Export Name:
    816069_18X24_"Output Directory".eps
    w/ the Output Directory, I'd like to use the Folder Name, not the full path.
    These are the revalent sections of the script identifying the "outFile" Name.
    VAR SETUP
    for(currentDoc = 0; currentDoc < peuINFO.numDocsToExport; currentDoc++) {
        var tempENTRY = getNewTempENTRY();
        tempENTRY.theDoc = app.documents[currentDoc]
        tempENTRY.singlePage = (tempENTRY.theDoc.documentPreferences.pagesPerDocument==1)?true:false;
        tempENTRY.getOut = true;
        var baseName = (tempENTRY.theDoc.name.split(".ind"))[0];   
        var baseName = baseName.replace(/-OHI-none-none/g, "")
    MIDDLE
        else{
                currentINFO.outfileName = currentINFO.baseName;
                exportPage(currentINFO, PageRange.allPages);
    EXPORT PORTION
        case 2:
                app.epsExportPreferences.pageRange = pgRange;
                    currentINFO.theDoc.exportFile(ExportFormat.epsType, (new File(outFile + ".eps")), false);

    If the problem is getting the text contents of your labeled box, try something like this:
    var docsizeBoxes = new Array;
    for (var i = 0; i < app.activeWindow.activePage.textFrames.length; i++) {
        if (app.activeWindow.activePage.textFrames[i].label == "DOC_SIZE") {
            docsizeBoxes.push(app.activeWindow.activePage.textFrames[i]);
            break; }
    var docsizeString = app.activeWindow.activePage.textFrames[i].contents;
    You should now be able to use docsizeString in parsing out the name of the output file.  This assumes that there will be one and only one text frame labeled "DOC_SIZE" on the active page. So you might need some error checking.
    If it were me, though, I'd just get the actual pageWidth and pageHeight from documentPreferences and use them. In my place, we don't have too many doc sizes to choose from.

  • Script Labels Not Working In CC

    Any time I attempt to edit a script label in InDesign CC, the change is not applied.  Clicking off the element results in anything typed being erased. This was a persistent problem for us in CS5 (hitting tab after entering the content made it stick), but was completely resolved in CS6, but is back rearing its ugly head in CC.

    Have you tried searching the forum? There have been several questions regarding this.
    Searching has changed between CS2 and CS4.
    Try putting the script in folder: Applications/Adobe InDesign/Scripts/Scripts Panel/Version 4.0 Scripts

  • [CS3 JS] Getting a page item by its script label

    I have a text frame on a master page with its script label set. In my script, I am trying to get a reference to the text frame with this:
    var doc = app.activeDocument;
    var spread = doc.masterSpreads[0];
    var tabFrame = spread.allPageItems.item("TabLeft");
    I get the error "spread.allPageItems.item is not a function"
    Any help will be appreciated. Thanks.
    Rick

    Hi Rick,
    spread.allPageItems returns a flattened array of all of the page items in the spread, at any level of the hierarchy (i.e., inside groups and other page items). Is that what you want? Sadly, allPageItems does not benefit from the special case where we use the label as a name, so you'll have to iterate if that's what you want.
    As Peter says (thanks, Peter!), spread.pageItems.item("label") gives you all of the page items whose label matches the string, but it does so in sort of a weird way--you'll always get a page item object. If no page items match, you get an invalid page item; if one matched, you get a single page item, and if multiple page items matched, you get a page item object that actually contains multiple page items. It can take a little testing to figure out exactly what it is that was returned.
    Thanks,
    Ole

  • Batch-find-and-replace.jsx

    Hi there, I wrote a batch-processing script for find change queries and thought I share it with you. You can get it over here 
    You can process GREP, TEXT, GLYPH and OBJECT searches. 
    Purpouse
    While creating books in InDesign with several documents we always come across some find change queries that need to be used again, and again, and again. To make this process easier you can just grab their names and put them into a list. The script will than try to process all your queries in one click. 
    prerequisites
    make sure you have a toml file.
    make sure the toml file is next to the script.
    make sure the toml file has the right formatting (see below in section TOML)
    if you want the script to autoexecute (without toml file selection), make sure the .toml file has the right name: "batch-find-and-replace.toml"
    make sure your fcqueries work right
    Usage
    Place the script and the toml file into your Scripts Panel Folder 
    define some find and change queries and save them via the InDesign dialogue.
    get the xml file names and add them to the "batch-find-and-replace.toml" file in the right spot. text search goes into text.files = [], grep search goes into grep.files = [] and so on. Make shure to remove the .xml from the filename. You can find these files on:
    Mac OS Users[username]\Library\Preferences\Adobe InDesign[Version][Language]\Find-Change Queries[query type] 
    Windows XP Documents and Settings[username]\Application Data\Adobe\InDesign[Version][Language]\Find-Change Queries[query type] 
    Windows Vista and Windows 7 Users[username]\AppData\Roaming\Adobe\InDesign[Version][Language]\Find-Change Queries[query type] 
    the .toml file should be located next to the script file and have the  appropriate name (batch-find-and-replace.toml). If so the script wont ask for the toml file and process the data right away. If not the script will ask you to select the .toml file.
    Thats it. Watch the magick happen.
    TOML
    Tom's Obvious, Minimal Language is a simple markup language that makes settings human readable. It is still in development and may change a lot. But still. It is a pretty easy language and can be learned by anyone.
    The basic toml filer looks like this: 
    # these are the basic settings
    # the MUST be there
    do_text = true
    do_grep = true
    do_glyph = true
    do_object = false
    # now the file names
    # they have to be in one line
    # the toml specs say you can break lines in arrays
    # but the toml.js does not allow that at the moment
    [text]
    files = ["my_first_text_find_and_change","another one"]
    [grep]
    files = ["somegrepsearch", "find tabs", "something else"]
    [glyph]
    files = []
    [objects]
    files = []
    MUST HAVE Settings
    With the do_text, do_object, do_grep and do_glyph you can define if the script should do the corresponding find and replace. Set them to true or false.
    CAN HAVE Settings
    In the [text],[grep],[glyph] and [objects] areas you can define the filenames that should be processed. Make sure the filenames are written right. If there is a file mentioned that does not exist the script will throw an error. It will try to process all the .xml files it can find.
    !IMPORTANT! you MUST remove the .xml from the filename in the list as shown above.
    The Script is here --> https://raw.github.com/...find-and-replace.jsx
    The basic .toml file here --> https://raw.github.com/...ind-and-replace.toml
    The Readme here --> https://github.com/...lob/master/README.md
    And the whole package here --> https://github.com/...e/archive/master.zip

    Great script, it worked perfectly with grep, text, glyph, not only worked with OBJECTS, because I do the same operation and does not work. Can you give me a hand? Thank you.
    In arquivo.toml is thus:
    # These are the basic settings
    # The MUST be there
    do_text = true
    do_grep = false
    do_glyph = false
    do_object = true
    do_all_docs = false
    # Now the file names
    # They have to be in one line
    # TomL the specs say you can break lines in arrays
    # But does not allow the toml.js que momento
    [text]
    files = ["_OVER_BLACK_TXT", "_OVER_CORPROF_TXT"]
    [grep]
    files = []
    [glyph]
    files = []
    [object]
    files = ["_OVER_BLACK_FILL", "_OVER_BLACK_STRK"]
    This is the image of the Scripts Panel folder:

  • How to enable the script label of a text frames in indesign using applescript

    hi all,
    am using Indesign CS2 with applescript..
    Using script I have to open a template in indesign and flow the word document into it...
    I can able to flow the word document into the template using "Place" command..but script labels of the text frames gets disabled...
    I need the script labels to be enabled...
    can anybody help me
    thanks in advance

    Script labels can't be disabled, so I'm not sure what your problem is -- perhaps seeing some code could help. Could it be that you're referencing a page item by label, but it is not responding because the item is part of a group?
    Shane Stanley <[email protected]>
    AppleScript Pro Sessions <http://scriptingmatters.com/aspro>

  • [AS] Script Label Items in a Group

    Hi all,
    I have a group of shapes that, when grouped together in Indesign, form an object.  This grouped object is script labeled "special".  I am trying to script label each of the individual parts of this grouped object "special" so that if users ever mistakenly ungroup the object, I can still manipulate all items with the "special" label...which is effectively my original grouped object.
    The catch is that I need to do this labeling with a script because I have thousands and thousands of files I'm working with.  I'd love it if something like this worked (but it doesn't):
    tell application "Adobe InDesign CS3"
    set theObject to page item "special" of document 1
    set theShapes to every page item of all page items of theObject
    set label of theShapes to "special"
    end tell
    The problem I keep running into is that it seems when an object is grouped, all the objects inside that group become, for all practical purposes, invisible.  The line "set theshapes to every page item of all page items of theObject" returns an empty list "{ }" as though there ARE no items making up the group.
    So then I thought I'd take a more tactile approach.  Select it, ungroup it, label it, group it back:
    tell application "Adobe InDesign CS3"
    set theObject to page item "special" of document 1
    select theObject
    ungroup selection
    set label of selection to "special"
    group selection
    end tell
    The problem with this approach is that after ungrouping the object with a script, there is no longer a selection as there is when doing the same by hand, so trying to set the label of a selection that does not exist produces an error.  Grrrrr.
    Friends, I know this can be done, but I need a little outside perspective on this to help me figure this one out.  As always, thanks in advance for your help!

    OK. Got it working but I'm not sure why. I went back to the bigger script of which the below is a part. And it works fine. I just don't understand why.
    tell application "Adobe InDesign CS4"
         activate
         set myDocument to active document
         set myPage to page pageNum of myDocument
         set active page of layout window 1 to myPage
         if not (exists library "Logowear_Lib.indl") then
              set theFile to open tagsLib
         end if
         set assetPlacer to item 1 of (place asset asset "3_12:13" of library "Logowear_Lib.indl" on myDocument)
         move assetPlacer to myPage
         move assetPlacer to myCoordinates
         set color_code_counter to 5
         set color_box_counter to 1
         tell myDocument
              repeat color_counter times
                   set theColorCode to item color_code_counter of Style_List
                   set oldLabelName to ("CW" & color_box_counter)
                   set newLabelName to my makeImageName(theSap, theColorCode)
                   set label of (object reference of every item of all page items of page pageNum of myDocument whose label = oldLabelName) to newLabelName
                   set color_code_counter to (color_code_counter + 2)
                   set color_box_counter to (color_box_counter + 1)
              end repeat
         end tell
    end tell

  • Automator: Apply Color Label and Copy to Folder

    I'm trying my hand at Automator, and I need help with one of my workflows (⇪). Basically, it's a service (accessible via right-click) that will apply a color label on an image file, and then copy that image file to a corresponding folder with the same color label. My current version works fine, except for the fact that I had to create seven versions to accommodate all seven colors.
    Is there any way to turn the color into a variable? I want the workflow to prompt me for a color, and then use that choice to run a search for the appropriate folder. I'd rather not hard code the color choice into separate services that all do the same thing.
    Also, the service currently assumes that it will run fast enough before I can deselect the target file. I'm sure it's possible that the folder search could lag out while I select another file, and the service will ultimately copy the newly selected item, rather than the initial target. Is there a way to ensure the service acts on whatever was selected when it was first triggered?
    I don't know AppleScript beyond copying-and-pasting other people's codes, so that limits my automation quite a bit. I don't know how to prompt for a label index choice and then feed the result into a find function. I also don't know how to record the file path of the selected item, and then feed that into the copy function at the end to ensure it doesn't copy the wrong file.

    Typically a list of items is passed to a workflow, so you will usually (depending on what you are doing with the items) need to step through the items in that list. If there is only one destination folder with the target label, you can just search for it, otherwise you will need to specify the destination in some other way.
    The following Service workflow example assumes that there is only one destination folder that has a given label color. It gets the label index of one of the input items and finds a folder with the same index at a specified base location (to limit the search range).
    1) Input items are automatically passed to an application or service, otherwise another action to get FInder Items can be used
    2) *Label Finder Items* (show the action when the workflow runs)
    3) *Run AppleScript* (paste the following script)
    <pre style="
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 10px;
    font-weight: normal;
    margin: 0px;
    padding: 5px;
    border: 1px solid #000000;
    width: 720px; height: 340px;
    color: #000000;
    background-color: #DAFFB6;
    overflow: auto;"
    title="this text can be pasted into an Automator 'Run AppleScript' action">
    on run {input, parameters} -- copy to a labelled folder
    This action is designed to follow a "Label Finder Items" action.  It will get the
    first folder of the base folder that has the same label and copy the input items
    to that folder.
    input: a list of Finder items received from a "Label Finder Items" action
    output: a list of Finder items to be passed on to a following action
    set output to {}
    set skippedItems to {} -- this will be a list of skipped items (errors)
    set baseFolder to (((path to pictures folder) as text) & "Shelley:Mary:") as alias -- a place to start looking for the destination folder
    tell application "Finder"
    set theLabel to label index of (the first item of the input) -- just pick one, they should all be the same
    get folders of (entire contents of baseFolder) whose label index is theLabel -- include subfolders
    -- get folders of  baseFolder whose label index is theLabel -- no subfolders
    if the result is not {} then
    set theDestination to the first item of the result
    else -- no folder
    error number -128 -- cancel
    end if
    end tell
    repeat with anItem in the input -- step through each item in the input
    try
    tell application "Finder" to duplicate anItem to theDestination
    set the end of the output to (the result as alias)
    on error number errorNumber -- name already exists, etc
    set errorNumber to "  (" & (errorNumber as text) & ")"
    -- any additional error handling code here
    set the end of skippedItems to (anItem as text) & errorNumber
    end try
    end repeat
    showSkippedAlert for skippedItems
    return the output -- pass the result(s) to the next action
    end run
    to showSkippedAlert for skippedItems
    show an alert dialog for any items skipped, with the option to cancel the rest of the workflow
    parameters - skippedItems [list]: the items skipped
    returns nothing
    if skippedItems is not {} then
    set {alertText, theCount} to {"Error with AppleScript action", count skippedItems}
    if theCount is greater than 1 then
    set theMessage to (theCount as text) & space & " items were skipped:"
    else
    set theMessage to "1 item was skipped:"
    end if
    set {tempTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, return}
    set {skippedItems, AppleScript's text item delimiters} to {skippedItems as text, tempTID}
    if button returned of (display alert alertText message (theMessage & return & skippedItems) alternate button "Cancel" default button "OK") is "Cancel" then error number -128
    end if
    return
    end showSkippedAlert
    </pre>

Maybe you are looking for