Hi all,
I have few script, and I want it should be auto run every after 15 minute. Can I do it if yes how it possible. If any one has shell script for it then please provide me.
Thanks
Rajeev
Hi all,
I have few script, and I want it should be auto run every after 15 minute. Can I do it if yes how it possible. If any one has shell script for it then please provide me.
Thanks
Rajeev
The easiest way to do that is with an ‘on idle’ script.
on run
-- do stuff - this runs when the application is started to set things up.
-- It is not necessary to have an 'on run' handler. The on idle
-- handler runs right after this anyway. If you want this to
-- run all the time, list it in startup items.
end run
-- Runs the first time immediately following the 'run' handler
-- if there is one. (There doesn't have to be)
on idle
-- In this section, you do your repeated operations. These can include running another script
return xx -- do this every xx seconds (or whatever).
end idle
on quit
-- do stuff - assumes you want to clean things up or save
-- preferences or variables before the program quits.
continue quit
-- if there's an on quit handler, continue quit
-- must be the last statement or the script will
-- not stop - you've grabbed the indication that
-- it should quit.
end quit
The script is saved as a ‘stay-open’ application and once started, will run on the return interval (not counting the time it actually takes to run).
Hi Rajeev:
If you have time to do some reading, learning how to use launchd may be another solution. It is only available if you are running OS X 10.4.x, and although it requires no shell scripting, it does require you to write up an XML .plist file and load it correctly into the system. The best article out there is launchd in depth, and I wrote one on using launchd to automatically access a flash drive using AppleScript.
This .plist should do the trick for you, once you put the correct path to your script in the second string line under the ProgramArguments key:
"<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://
[url=http://www.apple.com/DTDs/PropertyList-1.0.dtd>]www.apple.com/DTDs/PropertyList-1.0.dtd">[/url]
<plist version="1.0">
<dict>
<key>Disabled</key>
<true/>
<key>Label</key>
<string>Run AppleScript every 15 Minutes</string>
<key>LowPriorityIO</key>
<true/>
<key>Program</key>
<string>/usr/bin/osascript</string>
<key>ProgramArguments</key>
<array>
<string>osascript</string>
<string>/Users/YOURUSERNAME/FOLDER(S)TOSCRIPT/YOURSCRIPT.scpt</string>
</array>
<key>ServiceDescription</key>
<string>Runs Applescript every 15 minutes</string>
<key>StartInterval</key>
<integer>900</integer>
</dict>
</plist>"
There are a couple of other details to keep in mind. You need to have a folder in your user Library entitled LaunchAgents, and the .plist file goes there. You can name it anything you want. Once the path to your script is correct, and the .plist file is the LaunchAgents folder, you need to go to the Terminal and execute this command:
launchctl load -w /Users/YOURUSERNAME/Library/LaunchAgents/YOURPLISTFILENAME.plist
That will load your agent, and change the Disabled key in your .plist to false. Once that is done, your script will be called every 15 minutes as long as the machine is not asleep or turned off. Additionally, when you turn your machine back on, it will be automatically loaded again, without any further action by you.
Good luck; I am happy to assist you more on this if necessary.
I don’t know about something firing-off every 15 minutes, but I automate my overnight scripts using Cronnix to make Cron entries. Like the launchd suggestion, once you set up a Cron entry you never have to worry about it again, even across restarts.
(But I’m not sure how annoying I’d find it seeing the dock bounce around every 15 minutes as an AppleScript goes on then off. I’m sure the other suggestions avoid this issue for your case, but I figured I’d pass this on just in case, or for folks needing other ideas.)
–Kevin
If you don’t want a script app’s icon to show in the dock and the script doesn’t have any gui**, then use James Setnman’s Backgrounder. Its a droplet for converting to background or revealing background apps.
EDIT: **Doesn’t have any GUI means doesn’t have ‘choose file’, ‘choose folder’, ‘Save’, ‘display dialog’, ‘display alert’ or ‘choose from list’ instructions.