START > APPLESCRIPT > Gebrauchsfertige Scripts > iCal - Kalenderwochen eintragen

iCal - Kalenderwochen eintragen

Ein Script von Armin Briegel, um einen Kalender mit den Kalenderwochen in iCal zu generieren. Die ganze Story findet ihr hier.  (Vielen Dank nochmals an Armin Briegel für die freundliche Genehmigung zur Veröffentlichung an dieser Stelle.)

Den Handler «solo» gibt's hier nochmal in der Rubrik «Praktische Handler».

-- :::::::::::::::::::::::::::::::::  hohabadu.de  :::::::::::::::::::::::::::::::::

--        ( Mit freundlicher Genehmigung des Autoren Armin Briegel )
--         [ Quelle: http://rsvp.atsites.de/stories/storyReader$285 ]

on run
   set theYear to year of (current date)
   display dialog "Bitte das Jahr in dem die Kalenderwochen angezeigt werden sollen, eingeben:" default answer theYear
   set theYear to (text returned of result) as number
   set theCalName to "Kalenderwochen"
   display dialog "Bitte Namen des Kalenders in dem die Kalenderwochen angezeigt werden sollen, eingeben:" default answer theCalName
   set theCalName to (text returned of result)
   
   set theDate to date "1.1.2001"
   set year of theDate to theYear
   
   tell application "iCal"
      set x to count of (every calendar where title is theCalName)
      if x = 0 then make new calendar with properties {title:theCalName}
      set theCalendar to first calendar where title is theCalName
   end tell
   
   -- first day of first week
   set d to theDate - ((weekdayForDate(theDate) + 5) mod 7) * days
   
   repeat until year of d > theYear
      tell application "iCal"
         set kw to my kalenderwoche(d)
         set kwstring to "KW " & kw as string
         make new event at the end of events of theCalendar with properties {start date:d, summary:kwstring, allday event:true}
      end tell
      set d to d + 7 * days
   end repeat
end run


on kalenderwoche(d)
   copy d to basedate
   set day of basedate to 4
   set month of basedate to January
   set firstdayoffirstweek to basedate - ((weekdayForDate(basedate) + 5) mod 7) * days
   set calendarweek to ((d - firstdayoffirstweek) div weeks) + 1
   if calendarweek = 53 then
      set year of basedate to (year of basedate) + 1
      set firstdayoffirstweek to basedate - ((weekdayForDate(basedate) + 5) mod 7) * days
      if firstdayoffirstweek < d then
         set calendarweek to 1
      end if
   else if calendarweek = 1 then
      if firstdayoffirstweek > d then
         set calendarweek to 53
      end if
   end if
   return calendarweek as integer
end kalenderwoche

on weekdayForDate(d)
   set wd to weekday of d
   if wd is Sunday then
      return 1
   else if wd is Monday then
      return 2
   else if wd is Tuesday then
      return 3
   else if wd is Wednesday then
      return 4
   else if wd is Thursday then
      return 5
   else if wd is Friday then
      return 6
   else if wd is Saturday then
      return 7
   end if
   
   return -1
end weekdayForDate


 Im Scripteditor öffnen



Powered By CMSimple Design By NMuD Top