10 Replies Latest reply on Oct 29, 2009 6:04 PM by DAHolman

    applescript 10x slower in InDesign (CS3)

    McShaman Level 1

      I have been writing a script for a few days now and have got it working the way I wanted... However as soon as I started running it from the InDesign Scripts Panel I have found that part of it has become at least 10x slower. I have isolated the problem area which is as follows:

       

      set MainFolder to "The Love Hub:0_STUDIO JOBS X:1_IN PROGRESS:" as alias
      set searchString to "RG_2472"

       

      tell application "Finder"
          set folderItemList to items of MainFolder as alias list
          repeat with currentFolderItem in folderItemList
              try
                  find text searchString in ((displayed name of currentFolderItem) as string)
                  set targetFolder to currentFolderItem as alias
                  exit repeat
              end try
          end repeat
      end tell

       

      display dialog targetFolder as text

       

      I also have Satimages Smile Companion extension for Regular Expression functionality. The MainFolder consists of about 60 folders. When I run this script directly from Script Editor it runs in about a second... When I run it from the Script Panel in InDesign it takes about 11 seconds. Can anybody explain why this may be? and what I could do to fix it?

        • 1. Re: applescript 10x slower in InDesign (CS3)
          DAHolman Level 1

          I've noticed (also in CS3) that as soon as your commands leave InD it slows way down, compared to running out of InD. obviously, the biggest slow down is if the script takes InD out of the foreground, causing a panel redraw when you come back. that's unovoidable as far as I'm aware.


          the best work-around I've found is to run your script from OS X's script menu and/or a third party quick key app. of course, I usually just live with the slow-down in practice.

          • 2. Re: applescript 10x slower in InDesign (CS3)
            SuperMacGuy Level 2

            When possible try to keep the Finder out of doing a lot of refreshing of file lists or getting file data. I've seen a 10x speed reduction from using 10.4 to 10.5 on getting lists or any file/folder lists from the Finder.

             

            But my suggestion is, can you remove the "displayed name of" part from the command? I've  not seen that (part of Smile?) but if it's making the Finder re-get the name of the folder, then it's probably the culprit. Current folder item is an alias at this point right.. maybe just coerce it to string instead of displayed name.

            This is just a guess.

            • 3. Re: applescript 10x slower in InDesign (CS3)
              sstanleyau Level 4

              What version of the OS are you running?

              • 4. Re: applescript 10x slower in InDesign (CS3)
                Muppet Mark-QAl63s Level 4

                In Finder you have the option to use 'entire contents' this will trawl all the sub-level items from your chosen folder location. This can be pretty slow dependent on how much it has to go through. You also have the ability to filter in AppleScript with the word 'whose' Something like this:

                 

                set This_Folder to (choose folder with prompt "Select your top level folder…" without invisibles)

                --

                tell application "Finder"

                set My_Folder to every folder of entire contents of This_Folder whose displayed name = "RG_2472"

                end tell

                 

                No OSXA required.

                 

                Better still is the option to call a shell and use spotlight to find your files/folders this is lightning fast and no finder required.

                 

                The above AppleScript can still take a few seconds if I select my desktop (which is loaded with junk) using a shell for the same is almost instant

                • 5. Re: applescript 10x slower in InDesign (CS3)
                  McShaman Level 1

                  Thanks for the suggestion SuperMacGuy... Just tried it... Converted the list of aliases into a list of strings before going into the loop... Still lags up when the "Find Text" command has to go over each entry in the list... So its does not seem to be the Finder... I'm guessing that it is the use of the Regexp plugin that is having trouble with InDesign.

                   

                  Currently I am doing your first initial suggestion... running the script from the Script Menu supplied by Apple. That works...

                  • 6. Re: applescript 10x slower in InDesign (CS3)
                    sstanleyau Level 4

                    > I'm guessing that it is the use of the Regexp plugin that is having trouble with InDesign.

                     

                    Sort of. It's probably because you're telling InDesign to tell another app to use a scripting addition -- move the calls to Satimage out of the Finder block.

                    • 7. Re: applescript 10x slower in InDesign (CS3)
                      McShaman Level 1

                      Hey Mark,

                       

                      I am using 10.5.8

                       

                      Unfrotunatly there are 2 problems with your solutions in my senario... The pattern "RG_2472" is not the exact name of the folder... it is found at the beggining of the folder name (eg. RG_2472_My_Folder_Project).

                       

                      The second option using spotlight is an issue... The file is found on an external server where spotlight does not seem to be able to index correctly... this is a whole other issue that we have not been able to fix yet.

                       

                      thanks for your suggestions

                      • 8. Re: applescript 10x slower in InDesign (CS3)
                        McShaman Level 1

                        $*%K Yeah

                         

                        Thanks for that Shane... That fixed it!

                        • 9. Re: applescript 10x slower in InDesign (CS3)
                          Muppet Mark-QAl63s Level 4

                          AppleScript's 'whose' filtering can also deal with contains, starts with, ends with as well as = (is equal to), ≥ (greater than or equal to) and so on…

                          • 10. Re: applescript 10x slower in InDesign (CS3)
                            DAHolman Level 1
                            AppleScript's 'whose' filtering can also deal with contains

                             

                            that's what came to mind for me also. you could isolate the items with 'contains'. are you trying to rename the folder, or just assign it to a variable?