Can my mac run a script every 15 minute?

I have osx 10.7 and indesign CS6, 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 10 minute?



Posted on Jul 9, 2015 4:07 AM

Reply
6 replies

Jul 10, 2015 7:41 AM in response to sreekarthik.k

sreekarthik.k wrote:


Thanks for your suggestions. I am new in apple scripting


But the below code is not working for me.




In Script Editor option-File-Save As and choose this at the bottom (make sure you've selected Application and that the 'Stay open after run handler' box is checked.


User uploaded file


Then in Finder you double-click the saved Application to run it, just as you would any other app. And like any other app, when running it will show up on the Dock. And you quit it like any other app.


SG

Jul 9, 2015 1:39 PM in response to sreekarthik.k

There are various ways of doing this, each with their own set of caveats.


One solution (suggested by Tony) is to use the OS scheduler to kick of the script on a preset schedule (e.g. every 10 minutes).

This is simple, but may be prone to errors - for example, what if the task is lengthy and takes more than 10 minutes to run? The OS doesn't care, and will schedule a second run of the script while the first is still in flight. This may or may not be a problem depending on the workflow, but it may require additional logic in the script to maintain sanity.


A second solution (suggested by Pierre) is to have the script handle the scheduling itself via an 'on idle()' handler. This has the advantage that it's only active while the script is running and you can disable the scheduler by quitting the app.


Again, though, some caveats are needed depending on the workflow.

The easiest way to run this within AppleScript is to return a value for when the script should next be run, e.g.:


on idle


doSomething()

return (10 * minutes) -- run again in 10 minutes

end idle


Now the script will do its thing, then hold for 10 minutes and run again. This might be OK - there's little or no risk of it running over itself, but it is subject to time drift - if the doSomething() handler takes, say, 30 seconds to run and you start at midday then the second run will be at 12:10:30 (10 minutes after the initial run completed), the second will be at 12:21:00... and the drift continues.


A solution to this is to dynamically calculate the next time the script should run and use that as the return value, something like:


on idle

set runInterval to (10 * minutes) -- run on this schedule


-- e.g. (10 * minutes) => 12:10:00, 12:20:00, 12:30:00, etc.


-- or (15 * minutes) => 12:15:00, 12:30:00, 12:45:00, etc.



doSomething()



-- get the current time

set c to time of (get current date)


-- work out how far into the current runInterval we are


-- and invert that to work out how long until the next one:

set nextRun to runInterval - (c mod runInterval)

end idle


So now your script will do whatever tasks you put in doSomething(), then work out when the next time run should be.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Can my mac run a script every 15 minute?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.