Go Back   The macosxhints Forums > OS X Help Requests > AppleScript



Reply
 
Thread Tools Rate Thread Display Modes
Old 12-29-2012, 04:44 AM   #1
paragon
Major Leaguer
 
Join Date: Oct 2002
Posts: 467
weeks of pregnancy

a very long time ago I found here a script that makes a new calendar in ical with whole day events from monday to friday and call it week number, it crates 52 such events in this new calendar.
I am trying to adjust it to give me count of my wife's pregnancy weeks.
mind you, I am shooting arrows in the dark as I have no idea what means what here.
the important things for me are that the first event (week) will start on july 31 2012 and end 7 days later and then the second will start, there will be 42 weeks in this calendar
I thought it was working nicely but as the next week is, from some reason back to 1 after 22 and I can't find the reason...
please your help.

here is the script after my playing with it...

set numberOfWeeks to 42
set daysText to "TueWedThuFriSatSunMon"
set aDate to (current date)
set day of aDate to 31
set month of aDate to July
set year of aDate to 2012
set aDay to weekday of aDate
set weekNo to 1
--Day of week as num. starting with 0
set aDayText to (characters 1 thru 3 of (aDay as text)) as text
set dayOff to ((offset of aDayText in daysText) - 1) / 3 as integer

if dayOff is less than 5 then
set StartDate to aDate - dayOff * days
else
set StartDate to aDate + (7 - dayOff) * days
end if

tell application "iCal"
set newCal to make new calendar at end of calendars with properties {title:"Pregnancy Week No.'"}
set myCal to (count of every calendar)
end tell

repeat with myCount from 1 to numberOfWeeks
if (month of StartDate is December) and (day of StartDate is greater than 28) then set weekNo to 1
if (month of StartDate is January) and (day of StartDate is less than 5) then set weekNo to 1
set weekText to "Week No. " & weekNo
tell application "iCal"
tell calendar myCal
make new event at end of events with properties {start date:StartDate, end date:StartDate + (6 * days), allday event:true, summary:weekText}
end tell
end tell
set weekNo to weekNo + 1
set StartDate to StartDate + 7 * days
end repeat
Attached Thumbnails
Click image for larger version

Name:	Screen Shot 2012-12-29 at 12.39.08.jpg
Views:	25
Size:	57.3 KB
ID:	4613   Click image for larger version

Name:	Screen Shot 2012-12-29 at 12.39.18.jpg
Views:	23
Size:	53.7 KB
ID:	4614  
__________________
there is nothing better than a... oh well, that aint that good...
paragon is offline   Reply With Quote
Old 12-29-2012, 06:47 PM   #2
NovaScotian
Hall of Famer
 
Join Date: Oct 2002
Location: Halifax, Canada
Posts: 4,945
Wouldn't it be easier to do something like this:

set StartDate to date "Tuesday, July 31, 2012 12:00:00 AM"
repeat with theWeek from 1 to 42
set aTuesday to StartDate + theWeek * weeks
addToCal(aTuesday, theWeek)
end repeat

to addToCal(aDay, aNum)
-- do your cal stuff here using the Tuesday date and the week number that have been passed.
end addToCal
__________________
17" MBP, OS X 10.8.3; 27" iMac, OS X 10.8.3

Last edited by NovaScotian; 12-29-2012 at 06:50 PM.
NovaScotian is offline   Reply With Quote
Old 12-30-2012, 12:00 AM   #3
paragon
Major Leaguer
 
Join Date: Oct 2002
Posts: 467
As i said, i know nothing about any of this, so i can't tell if it is better. but it does look simpler.
what should i copy paste?
thanx
__________________
there is nothing better than a... oh well, that aint that good...
paragon is offline   Reply With Quote
Old 12-30-2012, 12:05 AM   #4
anthlover
Hall of Famer
 
Join Date: Apr 2003
Posts: 2,658
Its a feature you can make a repeating event, no fancy magic, you can make daily weekly every two weeks, etc. You can even make multiple ones all tracking different things on different schedules.

You can also send reminders, multiple for each event. Alerts, Emails, etc.
anthlover is offline   Reply With Quote
Old 12-30-2012, 12:09 AM   #5
paragon
Major Leaguer
 
Join Date: Oct 2002
Posts: 467
you all seem so nice but miss my main problem I am a complete newbeeeee
I have almost no understanding of what you are taking about, you will have to be a little more specific. Thanx
__________________
there is nothing better than a... oh well, that aint that good...
paragon is offline   Reply With Quote
Old 12-30-2012, 12:39 AM   #6
anthlover
Hall of Famer
 
Join Date: Apr 2003
Posts: 2,658
Do not think this meets your needs but post it none the less, leave the scripting to my colleagues...

1) Go the Calendar and click your cursor on the day you want something to start.
2) Type a Description of that event
3) Now double click on the event you created and choose Edit
4) Leave or Not: All Day Button as appropriate (I usually leave it checked)
5) Below the From and To: date range, it Says REPEAT: None
6) Change The Repeat None pop up to: Every what ever you want, day, week, month, Custom, etc
7) Below that are options for Alerts, e.g. Pop Up
8) Once you create one alert you can create more alerts e.g. Email, etc.

Last edited by anthlover; 12-30-2012 at 12:44 AM.
anthlover is offline   Reply With Quote
Old 12-30-2012, 10:07 AM   #7
NovaScotian
Hall of Famer
 
Join Date: Oct 2002
Location: Halifax, Canada
Posts: 4,945
Definitely the best way to go -- use Calendar without any scripting at all. What's missing then is the week number, which could be done by adding a script to the event that sets the summary of the event, but I confess I've never done that, not sure how to go about it.
__________________
17" MBP, OS X 10.8.3; 27" iMac, OS X 10.8.3
NovaScotian is offline   Reply With Quote
Old 12-30-2012, 11:02 AM   #8
benwiggy
League Commissioner
 
Join Date: Aug 2006
Posts: 5,039
Oh, and there are some very good iPhone apps related to pregnancy. My favourites are the Contraction Timers -- press start and stop, get table of frequency and duration to show the midwife.

"You should be having another one ...... now."
benwiggy is offline   Reply With Quote
Old 12-30-2012, 11:10 AM   #9
NovaScotian
Hall of Famer
 
Join Date: Oct 2002
Location: Halifax, Canada
Posts: 4,945
I just discovered that sandboxing in Mountain Lion makes it impossible to run a script from an event. Ah well....
__________________
17" MBP, OS X 10.8.3; 27" iMac, OS X 10.8.3
NovaScotian is offline   Reply With Quote
Old 12-30-2012, 12:46 PM   #10
anthlover
Hall of Famer
 
Join Date: Apr 2003
Posts: 2,658
The use case I was suggesting was more for scheduling a recurring even/meeting reminder for taking meds or medication injections on a complicated schedule, etc.

I realize the OP was looking for a week number count. I can imagine why but not sure what will be done with the info. The OB/GYN usually keeps track of most of important cal events for the parents. Also not too hard to count by Months the weeks that have gone by from Aprox date of conception.

Below are some tools outside of Ical that keep track of the weeks of pregnancy, trimester, etc. The first couple are web based so they work on anything, iphone too.

Here are web based Pregnancy Calculator
http://pregnancy.about.com/cs/pregna...blpregcalc.htm

and http://calcnexus.com/pregnancy-calculator.php

Iphone pregnancy apps
http://ipod.about.com/od/bestiphonea...Ipod-Touch.htm

Last edited by anthlover; 12-30-2012 at 12:55 PM.
anthlover is offline   Reply With Quote
Old 01-01-2013, 02:10 PM   #11
paragon
Major Leaguer
 
Join Date: Oct 2002
Posts: 467
thanx all but you aren't answering my Qs
i want to fix the script so it will work.
thanx for all the nice workarounds, though.
__________________
there is nothing better than a... oh well, that aint that good...
paragon is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting 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

Forum Jump



All times are GMT -5. The time now is 09:38 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.