10 Replies Latest reply on Sep 5, 2014 10:18 PM by CarlosCanto

    Edit/Edit Colors/ Convert to CMYK via applecript

    handellwork

      Cant seem to figure this one out.

      In Adobe CC, I am trying to convert every path item of the current document to CMYK using applecript or javascript.

      The equivalent to Edit/Edit Colors/ Convert to CMYK.

      Currently I am using an action but I try to stay away from actions as much as possible.

       

       

       

       

      Does anyone know how this could be done via applecript, javascript or whatever else?

        • 1. Re: Edit/Edit Colors/ Convert to CMYK via applecript
          CarlosCanto Adobe Community Professional & MVP

          unfortunately, not everything can be scripted in illustrator...you may not be able to retire your actions for the time being.

          • 2. Re: Edit/Edit Colors/ Convert to CMYK via applecript
            handellwork Level 1

            With great disappointment, that is exactly what I have discovered.

            So I noticed that the action file is text based .

            So what I have done as a long workaround is included the Action in the script.

            I then write the action text  to  a file, load the action, run the action & delete the action from  where it was saved.

            The only problem I am having is how to unload the action from the actions palette whereas they keep building up after each run.

             

            I tried these commands however they keep erroring.

             

            unload actionv : unloads an action into action palette

            unload action

            action file path text : Name of the set to be unloaded

            action file path text : Name of the action to be unloaded

             

             

            is there a javascript way?

            • 3. Re: Edit/Edit Colors/ Convert to CMYK via applecript
              CarlosCanto Adobe Community Professional & MVP

              Welcome to the wonderful world of Illustrator Scripting...The unload Action function unloads the action but it leaves the action set behind, so in my projects I have no choice but to leave the actions there. Now, to avoid loading multiple instances of the action, I wrap the action in a try...catch statement to Run the action first, if the action does not exist, it raises an error, then I load the action...javascript

              • 4. Re: Edit/Edit Colors/ Convert to CMYK via applecript
                handellwork Level 1

                Right, I tried this technique but I could not get the try statement to error.

                It just pretend runs the action and mocks me.

                 

                 

                SCRIPT:

                  set isit to false

                  try

                  do script actbname from ACTSET -- this makes everything CMYK 

                  set isit to true

                  end try

                 

                  if isit = false then

                  do javascript "app.loadAction (new File('" & the_file2 & "'));"

                  do javascript "app.doScript ('" & actbname & "', '" & ACTSET & "');"

                  end if

                 

                RESULT:

                do script "Action 1" from "Set 1"

                  --> current application


                • 5. Re: Edit/Edit Colors/ Convert to CMYK via applecript
                  handellwork Level 1

                  I was thinking i could have the action create an identifiable path item in the document & if it does not exist then run a subroutine that saves/load/run the action.

                  • 6. Re: Edit/Edit Colors/ Convert to CMYK via applecript
                    CarlosCanto Adobe Community Professional & MVP

                    That could work, is there are try...catch in appplescript?

                    • 7. Re: Edit/Edit Colors/ Convert to CMYK via applecript
                      handellwork Level 1

                      yes there is a try in applecript . I did a try catch in the javascript I can't get it to error. its like its running the action that doesn't even exists but its really not.

                      Im at a loss

                      • 8. Re: Re: Edit/Edit Colors/ Convert to CMYK via applecript
                        CarlosCanto Adobe Community Professional & MVP

                        sorry, I wast talking from memory, I checked and in fact it does not raise an error, but it brings up a dialog showing "the action is not available"

                         

                        here's a working sample

                         

                            try {
                                app.doScript ('actionName', 'setName'); // missing action doesn't trigger an error, but it brings up Illustrator warning about action not being available - Click on "Stop" to continue
                                                                                                           
                                //app.unloadAction ('setName', 'actionName'); // unloads action but it keeps the set folder, loading actions keep duplicating folder actions
                            }
                            catch (e) {
                                var f = new File('fullpath');
                                app.loadAction (f);
                                app.doScript ('actionName', 'setName');
                               
                            }
                        
                        • 9. Re: Re: Edit/Edit Colors/ Convert to CMYK via applecript
                          handellwork Level 1

                          Right, I tried this method already but it does not show the dialog box in Adobe Illustrator CC v18. only previous versions.

                          Our group all use different versions.  I may just switch to an installer script thats adds the action to Illustrators "Default_Actions.aia"  file since its text based.

                           

                           

                          Heres what I'm using now which  is working but I don't like all the hoops it has to jump.

                          The action simply writes a new doc to a dummy file on a server & the when script doesn't see then dummy file, it writes, loads the action & deletes the dummy file.

                          Then on the next run, the action will write the dummy file for the script to see & skip the loading of a duplicate action. 

                          And if I change the action, I simply change the name of the action file & dummy file.

                           

                           

                          property ACTSET : "Set 1"

                          property actbname : "Action 1" --- writes teh PTDF file, then run rest of action

                          property PTDF : POSIX file "/Volumes/artserver/1_ASI/spotcheck.ai" as string

                          property the_file : PTDF & ACTSET & ".aia" as string

                          property the_file2 : POSIX path of PTDF & ACTSET & ".aia" as string

                          property spotcheck : {}

                           

                           

                          tell application "Adobe Illustrator"

                            set spotcheck to ""

                            do javascript "app.doScript ('" & actbname & "', '" & ACTSET & "');"

                           

                            try

                            tell application "Finder" to set spotcheck to file PTDF as string

                            end try

                           

                            if spotcheck = {} then

                            my addaction() --- saves action text to temporary items for the load

                            do javascript "app.loadAction (new File('" & the_file2 & "'));"

                            do javascript "app.doScript ('" & actbname & "', '" & ACTSET & "');"

                            tell application "Finder" to move file the_file to trash

                            end if

                           

                            tell application "Finder" to move file PTDF to trash

                           

                          end tell



                           

                          • 10. Re: Edit/Edit Colors/ Convert to CMYK via applecript
                            CarlosCanto Adobe Community Professional & MVP

                            I hear you, I used to get frustrated by the lack of scripting features...then I learned what Illustrator can do and what it can not, I lower my expectations, now I get really happy when I can get anything to work as convoluted as it may be.