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?
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?
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.
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
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.
You do this with launchd.
The easiest way is to use Lingon, $5 in the App Store: https://itunes.apple.com/us/app/lingon-3/id450201424?mt=12
Note: to run an Applescript, save as an App and use the open command in the Run box in Lingon:
open "/Users/Tony/Library/Scripts/myApplescript.app"
Thanks for your suggestions. I am new in apple scripting
But the below code is not working for me.
on idle
tell application "Adobe InDesign CS6"
--usage: do script pathToyourScript scriptinglanguage
do script "Mac Red-Grafik 3:Users:claessen:Desktop:Script.jsx" language javascript --applescript language
end tell
return 900
end idle
How are you running this?
idle() handlers only run as part of a stay-open application. If you are trying to run this within AppleScript Editor, you won't get the results you want.
Additionally, when you say it's not working, what do you mean? what happens? anything? nothing? it runs once, then stops?
You could save your script as an application and choose “Stay open after run handler“.
See “idle and quit Handlers for Stay-Open Applications” in the AppleScript Language Guide.
Can my mac run a script every 15 minute?