Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > questions about writing Applescripts

questions about writing Applescripts
Thread Tools
Junior Member
Join Date: Apr 2003
Status: Offline
Reply With Quote
Oct 22, 2003, 07:27 PM
 
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
Reply With Quote
Oct 22, 2003, 07:47 PM
 
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
Reply With Quote
Oct 23, 2003, 04:08 AM
 
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.
Rick Roe
icons.cx | weblog
     
Junior Member
Join Date: Apr 2003
Status: Offline
Reply With Quote
Oct 23, 2003, 11:45 AM
 
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
Reply With Quote
Oct 23, 2003, 04:43 PM
 
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).
Rick Roe
icons.cx | weblog
     
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status: Offline
Reply With Quote
Oct 23, 2003, 06:46 PM
 
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
Reply With Quote
Oct 24, 2003, 08:59 AM
 
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
Reply With Quote
Oct 24, 2003, 06:14 PM
 
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.
Rick Roe
icons.cx | weblog
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 07:18 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2