32 Replies Latest reply on Nov 14, 2012 12:30 PM by espenmoe

    Can my mac run a script every 15 minute?

    espenmoe Level 1

      I have osx 10.7 and indesign CS5, and I use a script I run several times a day.  Would it be possible to have my mac start this script automatically - maybe every 15 minute?

        • 1. Re: Can my mac run a script every 15 minute?
          Kevin Parrott Level 2

          hi

          yes it's possible, and there a varied ways to do it, heres a few ideas.

           

          you could use CRON, which is daemon process running in the back ground all the time

          or you could use a simple on idle applescript something like the below.

           

           

          (* -- UNCOMMENT TO USE

          on run

          ------------------------------------------------------------------------

          -- INITIALIZATION OF APPS ,MOUNT SERVERS ETC HERE

          ------------------------------------------------------------------------

          end run

          *)

           

          on idle

              ------------------------------------------

              -- YOUR SCRIPT HERE

              ------------------------------------------

              return 900 -- 15 MINUTES

          end idle

           

          (*

          Save as a stay open application, script will run every 15 minutes

          *)

          • 2. Re: Can my mac run a script every 15 minute?
            Larry G. Schneider Adobe Community Professional & MVP

            Depends on what the script does. You really don't want it firing off when you are working in an app and the script targets that app.

            • 3. Re: Can my mac run a script every 15 minute?
              espenmoe Level 1

              Larry: I'm using a dedicatet Mac.

              • 4. Re: Can my mac run a script every 15 minute?
                espenmoe Level 1

                Kevin: How do I define my script?  I'm a novice on apple script, so this is as far  as I got:  on run      application "Adobe InDesign CS5"  end run  on idle            return 9 -- 15 MINUTES end idl  I manage to start the app :-D  The name of my script is myscript

                • 5. Re: Can my mac run a script every 15 minute?
                  Muppet Mark Level 5

                  You can also add them to iCal events to fire them off or you could use Adobe's Bridge schedule tasks… What is the script… AppleScript or ESTK?

                  • 6. Re: Can my mac run a script every 15 minute?
                    espenmoe Level 1

                    Maybe i was not clear, but I'm talking about running an Indesign-script every 15 minute, not just an Apple script.

                     

                    So question: What is the syntax for running Indesign script from an Apple script?

                    • 7. Re: Can my mac run a script every 15 minute?
                      -hans- Level 4

                      Hi,

                       

                      Kevin showed you the syntax to use AppleScript, sthg. like:

                       

                      --open in Scripteditor, save as Programm with option stay open!
                      
                      on idle
                          tell application "Adobe InDesign CS5"
                              --usage: do script pathToyourScript scriptinglanguage
                              do script "Mac Red-Grafik 3:Users:claessen:Desktop:FunnyScript.jsx" language javascript --applescript language
                          end tell
                          return 900
                      end idle
                      

                       

                       

                      Shareware for doing sheduled tasks: hazel

                       

                      OSX BuiltIn LaunchD

                       

                      Hope it'll help

                       

                      Hans-Gerd Claßen

                      • 8. Re: Can my mac run a script every 15 minute?
                        espenmoe Level 1

                        With my adress to my script, I get this error:

                         

                        Expected end of line, but found "script"

                         

                        on idle

                            tell application "Adobe InDesign CS5"

                                --usage: do script pathToyourScript scriptinglanguage

                                do script "Macintosh HD:Applications:Adobe InDesign CS5:Scripts:Scripts Panel:plasserinnhold.jsx" language javascript --applescript language

                            end tell

                            return 900

                        end idle

                        • 9. Re: Can my mac run a script every 15 minute?
                          -hans- Level 4

                          Hi,

                           

                          you  shouldn't get Errors while compiling, but may be when running the *.jsx ...

                           

                          Let's try from the start again:

                           

                          property pathToScript : ""
                          
                          on idle
                              if pathToScript is "" then set pathToScript to (choose file with prompt "Please choose the Javascriptfile") as text
                              tell application "Adobe InDesign CS5.5"
                                  do script pathToScript language javascript
                              end tell
                              return 900
                          end idle
                          

                          Please paste the above code  to a new window of AppleScript-Editor.app. Then save as APP with option STAY OPEN (IMPORTANT!!!) to any place on your harddisk.

                          double click the newly created app. You should be requested for the *.jsx-file once. Please choose it. Done! The targetScript should be launched every 900 seconds from now on.

                           

                          Hans-Gerd Claßen

                           

                          If running into errors: Please try to explain exactly ...

                          1 person found this helpful
                          • 10. Re: Can my mac run a script every 15 minute?
                            Kevin Parrott Level 2

                            the code works fine for me here under CS5.5 & CS6, maybe double check that you have saved it as a stay open application.

                             

                            on idle

                                tell application "Adobe InDesign CS6" --works fine in CS5.5 & CS6

                                    do script "Macintosh HD:Applications:Adobe InDesign CS6:Scripts:Scripts Panel:Samples:JavaScript:CropMarks.jsx" language javascript

                                end tell

                                return 5 --changed for testing

                            end idle

                            • 11. Re: Can my mac run a script every 15 minute?
                              Kevin Parrott Level 2

                              thtas a good idea Hans

                              • 12. Re: Can my mac run a script every 15 minute?
                                espenmoe Level 1

                                Now it is running - thx a LOT!

                                 

                                Message was edited by: espenmoe

                                • 13. Re: Can my mac run a script every 15 minute?
                                  espenmoe Level 1

                                  One last question: How to make the script click the "OK"-button at the end?

                                  Skjermbilde 2012-11-12 kl. 21.46.25.png

                                  • 14. Re: Can my mac run a script every 15 minute?
                                    Kevin Parrott Level 2

                                    my pick is that the jsx file has a dialog set to be thrown when the process has finished running, so id open the jsx file look near the bottom of the code and comment out or remove the area appropriate to the dialog, it may look like this

                                     

                                    alert("Done");

                                    1 person found this helpful
                                    • 15. Re: Can my mac run a script every 15 minute?
                                      espenmoe Level 1

                                      Found it, and killed it
                                      //    alert("Done");
                                      But this can not be clicked out by my little apple-script?

                                      • 16. Re: Can my mac run a script every 15 minute?
                                        -hans- Level 4

                                        Hi,

                                         

                                        you may tell system events to do this, but as it's possible to edit the source it's bit inconvinient.

                                         

                                        Guess this should work and could be added before invoking your targetscript:

                                        tell application "System Events"
                                            tell process "Adobe InDesign CS5.5"
                                                if accessibility description of window 1 is "alert" then
                                                    try
                                                        click button "OK" of window 1
                                                    end try
                                                end if
                                            end tell
                                        end tell
                                        

                                         

                                        Hans-Gerd Claßen

                                        1 person found this helpful
                                        • 17. Re: Can my mac run a script every 15 minute?
                                          espenmoe Level 1

                                          Hans: adding it at the begining now!

                                           

                                          Skjermbilde 2012-11-12 kl. 23.12.56.png

                                          ("Time out for Apple event" "Edit")

                                           

                                          But I just discovered the Apple-script is timing out after a short while. Can I set the timeout for Applescript?

                                           

                                          Or is it just my indesign-script hitting a bumper and stalling?

                                           

                                          Or is the problem that Indesign is still running the script when Apple script is trying to start the indesignscript?

                                          • 18. Re: Can my mac run a script every 15 minute?
                                            Kevin Parrott Level 2

                                            thought that might happen, maybe add to the end of the jsx script a piece of code to kill the dialog after say 5 seconds, I dont no how to do that, but i think it will work.

                                            • 19. Re: Can my mac run a script every 15 minute?
                                              Muppet Mark Level 5

                                              JavaScript windows have no giving up after… n seconds

                                              • 20. Re: Can my mac run a script every 15 minute?
                                                CarlosCanto Adobe Community Professional & MVP

                                                espenmoe wrote:

                                                 

                                                One last question: How to make the script click the "OK"-button at the end?

                                                 

                                                as an alternative, instead of using alert('done'), you could build your own dialog, show it, and dismiss it after x seconds.

                                                • 21. Re: Can my mac run a script every 15 minute?
                                                  -hans- Level 4

                                                  Hello Kevin,

                                                   

                                                  you may imitate the AS Alert-giving up in JS:

                                                   

                                                  try{
                                                      //...
                                                      }catch (e){displayDialog(e)}
                                                  
                                                  
                                                  
                                                  
                                                  function displayDialog(message){  
                                                  var infoWindow = new Window("palette");   
                                                  infoWindow.add("statictext", undefined, "Houston, we've got a problem:  " + message);   
                                                  infoWindow.show();   
                                                  $.sleep(2000);   
                                                  infoWindow.close();   
                                                  }
                                                  

                                                   

                                                   

                                                  Hans-Gerd Claßen

                                                  • 22. Re: Can my mac run a script every 15 minute?
                                                    -hans- Level 4

                                                    Hi espenmoe,

                                                     

                                                    gave it a custom-timeout, added the systemeventspart, and throwing errors when occur but giving up to not stopp the process ...

                                                     

                                                     

                                                    property pathToScript : ""
                                                    
                                                    on idle
                                                        if pathToScript is "" then set pathToScript to (choose file with prompt "Please choose the Javascriptfile") as text
                                                        my clickAlertButton()
                                                        with timeout of 850 seconds
                                                            try
                                                                tell application "Adobe InDesign CS5.5" --<<<<<<<YOUR APP!!!
                                                                    do script pathToScript language javascript
                                                                end tell
                                                            on error e
                                                                activate
                                                                display dialog e giving up after 3
                                                            end try
                                                        end timeout
                                                        return 30
                                                    end idle
                                                    
                                                    on clickAlertButton()
                                                        tell application "System Events"
                                                            set namesOfCurrProcesses to name of every process
                                                            
                                                            if namesOfCurrProcesses contains "Adobe InDesign CS5.5" then --<<<<<<<YOUR APP!!!
                                                                try
                                                                    tell process "Adobe InDesign CS5.5" --<<<<<<<YOUR APP!!!
                                                                        if accessibility description of window 1 is "alert" then
                                                                            click button "OK" of window 1
                                                                        end if
                                                                    end tell
                                                                on error e
                                                                    activate
                                                                    display dialog e giving up after 3
                                                                end try
                                                            end if
                                                        end tell
                                                    end clickAlertButton
                                                    

                                                    Give it a try

                                                     

                                                    Hans-Gerd Claßen

                                                    • 23. Re: Can my mac run a script every 15 minute?
                                                      espenmoe Level 1

                                                      Gives me an error:

                                                      Skjermbilde 2012-11-13 kl. 09.08.13.png

                                                      • 24. Re: Can my mac run a script every 15 minute?
                                                        -hans- Level 4

                                                        Hi,

                                                         

                                                        the ID-Part did not change, so it should work if worked before ... Shure that the target is a (the) Javascriptfile? (May be resafe the script and choose the file again ...)

                                                         

                                                        It worked on my machine this morning and as I#M on a PC for the rest of the day ... I can only check it this evening. But again: seems as if  'pathToScript' doesn't target a *.jsx-file.

                                                         

                                                        Hans-Gerd Claßen

                                                        • 25. Re: Can my mac run a script every 15 minute?
                                                          espenmoe Level 1

                                                          OK - testing now!  Jus to let me check that I got this: The timeout for for the apple script-erro, not the indesign-popup?

                                                          • 26. Re: Can my mac run a script every 15 minute?
                                                            espenmoe Level 1

                                                            Hans!

                                                            I have been testing this script for many times, and every time it fails to close the indesign-document! The original script you wrote (the small one that did not kill Apple-script-popup) did manage to close indesign-documents.

                                                             

                                                            Any idea why?

                                                             

                                                            I have changed my Indesign script so it does not end the job with a jolly popup message, so that problem is solved.

                                                             

                                                            The only problem left is the timeout message from Applescript.

                                                            Skjermbilde time out.png


                                                             

                                                             

                                                             

                                                            property pathToScript : ""

                                                             

                                                            on idle

                                                                      if pathToScript is "" then set pathToScript to (choose file with prompt "Please choose the Javascriptfile") as text

                                                                      my clickAlertButton()

                                                                      with timeout of 60 seconds

                                                                                try

                                                                                          tell application "Adobe InDesign CS5" --<<<<<<<YOUR APP!!!

                                                              do script pathToScript language javascript

                                                                                          end tell

                                                                                on error e

                                                              activate

                                                              display dialog e giving up after 3

                                                                                end try

                                                                      end timeout

                                                                      return 30

                                                            end idle

                                                             

                                                            on clickAlertButton()

                                                                      tell application "System Events"

                                                                                set namesOfCurrProcesses to name of every process

                                                             

                                                                                if namesOfCurrProcesses contains "Adobe InDesign CS5.5" then --<<<<<<<YOUR APP!!!

                                                                                          try

                                                                                                    tell process "Adobe InDesign CS5" --<<<<<<<YOUR APP!!!

                                                                                                              if accessibility description of window 1 is "alert" then

                                                                                                                        click button "OK" of window 1

                                                                                                              end if

                                                                                                    end tell

                                                                                          on error e

                                                              activate

                                                              display dialog e giving up after 3

                                                                                          end try

                                                                                end if

                                                                      end tell

                                                            end clickAlertButton

                                                            • 27. Re: Can my mac run a script every 15 minute?
                                                              -hans- Level 4

                                                              Dear espenmoe ;-),

                                                               

                                                              well, AS timeout is 120 seconds as standard. If your script takes longer so set it up (for example 1 hour, better more then less).

                                                               

                                                              property pathToScript : ""
                                                              
                                                              on idle
                                                                  if pathToScript is "" then set pathToScript to (choose file with prompt "Please choose the Javascriptfile") as text
                                                                  
                                                                  try
                                                                      --set timeout up to 1 hour
                                                                      with timeout of 3600 seconds
                                                                          tell application "Adobe InDesign CS5.5" --<<<<<<<YOUR APP!!!
                                                                              do script pathToScript language javascript
                                                                          end tell
                                                                      end timeout
                                                                  on error e
                                                                      activate
                                                                      display dialog e giving up after 3
                                                                  end try
                                                                  --run script every 15 minutes after finishing the current turn
                                                                  return 900
                                                              end idle
                                                              

                                                               

                                                              The script you posted above should never have clicked any button cause there still 5.5 as target:

                                                                                  if namesOfCurrProcesses contains "Adobe InDesign CS5.5" then --<<<<<<<YOUR APP!!!

                                                               

                                                              To say anything about the problems using system events it would be necessary to post the executed script, as it works on my machine without any problem.

                                                               

                                                              Good luck

                                                               

                                                              Hans


                                                              1 person found this helpful
                                                              • 29. Re: Can my mac run a script every 15 minute?
                                                                espenmoe Level 1

                                                                -hans- wrote:

                                                                 

                                                                 

                                                                The script you posted above should never have clicked any button cause there still 5.5 as target:

                                                                                    if namesOfCurrProcesses contains "Adobe InDesign CS5.5" then --<<<<<<<YOUR APP!!!

                                                                 

                                                                To say anything about the problems using system events it would be necessary to post the executed script, as it works on my machine without any problem.

                                                                 

                                                                Good luck

                                                                 

                                                                Hans


                                                                And that is probably the reason!

                                                                • 30. Re: Can my mac run a script every 15 minute?
                                                                  espenmoe Level 1

                                                                  I have been testing this, and so far it looks liek we ahve a winner! I altered it to look like below:

                                                                   

                                                                  It will not time out until 150 seconds

                                                                  It wil run every 300 second

                                                                  Applescript pop up lasts for 5 secons

                                                                   


                                                                   

                                                                  property pathToScript : ""

                                                                   

                                                                  on idle

                                                                            if pathToScript is "" then set pathToScript to (choose file with prompt "Please choose the Javascriptfile") as text

                                                                            my clickAlertButton()

                                                                            with timeout of 150 seconds

                                                                                      try

                                                                                                tell application "Adobe InDesign CS5" --<<<<<<<YOUR APP!!!

                                                                                                          «event K2  dosc» pathToScript given «class doLg»:«constant ScLgJSLg»

                                                                                                end tell

                                                                                      on error e

                                                                    activate

                                                                    display dialog e giving up after 3

                                                                                      end try

                                                                            end timeout

                                                                            return 300

                                                                  end idle

                                                                   

                                                                  on clickAlertButton()

                                                                            tell application "System Events"

                                                                                      set namesOfCurrProcesses to name of every process

                                                                   

                                                                                      if namesOfCurrProcesses contains "Adobe InDesign CS5" then --<<<<<<<YOUR APP!!!

                                                                                                try

                                                                                                          tell process "Adobe InDesign CS5" --<<<<<<<YOUR APP!!!

                                                                                                                    if accessibility description of window 1 is "alert" then

                                                                                                                              click button "OK" of window 1

                                                                                                                    end if

                                                                                                          end tell

                                                                                                on error e

                                                                    activate

                                                                    display dialog e giving up after 5

                                                                                                end try

                                                                                      end if

                                                                            end tell

                                                                  end clickAlertButton

                                                                  • 31. Re: Can my mac run a script every 15 minute?
                                                                    -hans- Level 4

                                                                    Good morning,

                                                                     

                                                                    allready sunrise in norway? Have to say that I can not understand / read one of the errormessages you've posted! Cryptical language ;-)

                                                                     

                                                                    Just a few points to clarify:

                                                                     

                                                                    1. set time out to specific time means that this is just  the maximum time given to a process' duration. If finished earlier everything will go on from this moment and will not wait until timeout duration is over!

                                                                    2. If the second errormessage appears it means that system events failed on clicking the button of alert window. UI-Scripting is not very robust and should be avoided if possible.

                                                                    3. Be aware that the 'clickAlertButton'-function is just a workaround. Could be used if there no possibility to modify the executed script

                                                                    3.b. If you want a Javascript alert and you want it to close after a specific time then try to use the handler I posted in response to Kevin. Just run it with 'displayDialog('anyStringYouLike')'

                                                                     

                                                                     

                                                                    Have a good day

                                                                     

                                                                    Hans-Gerd Claßen

                                                                    • 32. Re: Can my mac run a script every 15 minute?
                                                                      espenmoe Level 1

                                                                      Thx a lot!

                                                                       

                                                                      At this time of year in Oslo, we hardly have daylight ;-)