 |
 |
questions about writing Applescripts
|
 |
|
 |
|
Junior Member
Join Date: Apr 2003
Status:
Offline
|
|
I had an idea for a script but I cant figure out how to write it properly.
(I'm an artist not a coder) does anyone know where the best tutorial is for writing them?
I wanted a way to open "iCal" at 6am every morning before i get in the studio.
If I shut the comp. down every night, I would just put the app in the start-up folder, but I leave my comp. on all the time so I thought a script would work for me.
Am I wrong?
-S-
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status:
Offline
|
|
This script will lauch iCal:
Code:
tell application "iCal" to run
If you want it to run automatically, create a cron job (see zillions of posts in these forums and elsewhere on the net to create cron jobs).
The cron job could run an existing script, but for a one liner, you can include the entire line in the cron job as:
Code:
osascript -e 'tell application "iCal" to run'
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status:
Offline
|
|
Alternately, if you have iCal 1.5 installed, you can schedule iCal to open itself.
Schedule an event, set its alarm to "Open File", and "iCal" is the default choice. Quit iCal, and you'll find it relaunched when the alarm time comes.
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Apr 2003
Status:
Offline
|
|
from Brass:
This script will lauch iCal:
code:
tell application "iCal" to run
close- but how do i tell iCal to open at a specific time? ( i.e.-6:00am)
from Rickster:
Schedule an event, set its alarm to "Open File",
does this mean that i would have to setup "events" for every day??
-S-
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status:
Offline
|
|
close- but how do i tell iCal to open at a specific time? ( i.e.-6:00am)
AppleScript isn't a task scheduler, really. The closest you could do is write a script which is saved as a "stay open" application and has an idle handler and examines the current date regularly. Here's one way you could do it (it's untested and may not work, but it should be enough to get you the idea):
Code:
on idle
set currentDate to (current date)
if (time of currentDate) div 60 = 360 then
-- 6:00 am = 360 minutes past midnight
-- use integer divide to get minutes instead of testing seconds,
-- since AppleScript can't give us accuracy to the second
beep 10 -- raise a ruckus
return 86400 -- 24 hours until the idle handler gets called again
else
-- it's not 6 am, so we'll need the idle handler called sooner than 24 hours from now
set dateString to "6 am"
set alarmDate to date dateString -- coercing "6 am" to a date gives us 6 am today
if (time of currentDate) div 60 > 360 then
-- it's after 6 am today, we need an alarm at 6 am tomorrow
set alarmDate to alarmDate + 86400
end if
return alarmDate - currentDate
-- difference in seconds between alarmDate and now, we'll get called at alarmDate
end if
end idle
does this mean that i would have to setup "events" for every day??
Yes. I do something similar to have iCal run an AppleScript which serves as my "alarm clock" every morning -- I've set up an event which repeats every weekday, and put it in its own calendar (which I uncheck so the "wake up" events aren't cluttering up the calendar view).
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status:
Offline
|
|
Originally posted by Rickster:
AppleScript isn't a task scheduler, really. The closest you could do is write a script which is saved as a "stay open" application and has an idle handler and examines the current date regularly. Here's one way you could do it (it's untested and may not work, but it should be enough to get you the idea):
(code removed)
Yes. I do something similar to have iCal run an AppleScript which serves as my "alarm clock" every morning -- I've set up an event which repeats every weekday, and put it in its own calendar (which I uncheck so the "wake up" events aren't cluttering up the calendar view).
Ouch! Why would you go to all the trouble of setting up and AppleScript to run idle events forever when you could use cron (as I suggested in my first post)?
One simeple cron entry for 6am every day would do it:
Code:
0 6 * * * osascript -e 'tell application "iCal" to run'
However, setting an iCal event for 6am every day to open itself may be even easier, as you suggested. The only problem, is that it will show up as an event in your diary every day.
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Apr 2003
Status:
Offline
|
|
Brass-
you've gained my full attention on this -
how do i implement this "cron job"?
where can i learn more about them?
and..
am i wrong for always wanting to move to Australia?
it just always sounded like a really cool place to live.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status:
Offline
|
|
Ouch! Why would you go to all the trouble of setting up and AppleScript to run idle events forever when you could use cron (as I suggested in my first post)?
To illustrate just how crazy an idea it is. 
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|