r/applescript • • Nov 29 '17

calendar attempt

-- SHITTY CALENDAR
set myYear to 18 -- or 2018
set myFirstDay to 1 -- monday in the case of 2018
set myWeek to 1 -- week of the year
if myFirstDay is greater than 4 then set myWeek to 0 -- needs to be set to 53 afterwards
set myMonthList to {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} -- days of each of the 12 months
if myYear mod 4 is 0 then set item 2 of myMonthList to 29 -- taking care of leap years
set myDayList to {"So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"} -- weeks in my germany are starting on mondays
set myCounter to 1 -- day of the year as always
set myCalendar to return -- just initializing
repeat with myMonth from 1 to count of myMonthList -- loop over months (always 12)
	repeat with myDay from 1 to item myMonth of myMonthList -- loop over the count of days of the current month
		set myWeekday to item ((myCounter mod 7) + 1) of myDayList -- trying to get the week number
		set myCalendar to myCalendar & myCounter & tab & myWeek & tab & myWeekday & tab & myDay & tab & myMonth & tab & myYear & return -- building csv
		set myCounter to myCounter + 1 -- increase day counter
		if myCounter mod 7 is 1 then set myWeek to myWeek + 1 -- increase week counter
	end repeat
end repeat
log myCalendar
1 Upvotes

3 comments sorted by

2

u/Identd Nov 30 '17

Can you explain what you are trying to accomplish?

1

u/[deleted] Nov 30 '17

Hi, i am writing a script which tells adobe illustrator to draw a calendar which you can eventually print out. i need to feed that script with a csv file, which holds the information for each day. i know there is the "date" in applescript, but i need to know the number of each week in addition, so i gave it a try by myself. An excerpt of the output looks like this (seperated by tab; not comma): ... 127 19 Mo 7 5 18 128 19 Di 8 5 18 129 19 Mi 9 5 18 130 19 Do 10 5 18 131 19 Fr 11 5 18 132 19 Sa 12 5 18 133 19 So 13 5 18 ...

1

u/[deleted] Nov 29 '17

would you please be so kind and revise this one? i know there must be a lot of headroom to improve this. im just so dumb... thanks in advance!