Urlaubstage in iCal zählen

Ist ein kleines Skript um Urlaubstage zu zählen. Das Skript zählt alle All-Day-Events die das Schlüsselwort Urlaub enthalten… gezählt werden aber  alle Tage ausser Samstag und Sonntag…

##©hubionmac.com 17.02.2013 -Urlaubstage zählen
set myweekdays to {Monday, Tuesday, Wednesday, Thursday, Friday}
set triggerString to "urlaub"
set urlaubscount to 0
tell application "iCal"
  set thecal to my returntheCal()
  tell thecal
    set e to every event
    repeat with i from 1 to count of e
      set te to item i of e
      if summary of te contains triggerString then
        set s to start date of te
        set enddate to end date of te
        repeat until s ≥ enddate
          
          set currentday to weekday of s
          if currentday is in myweekdays then
            set urlaubscount to urlaubscount + 1
            
          end if
          set s to s + 86400
        end repeat
      end if
    end repeat
  end tell
  activate
  display dialog "Habe " & urlaubscount & " Ulaubstage gezählt, exklusive Samstage und Sonntage"
end tell


on returntheCal()
  tell application "iCal"
    set writeableCals to every calendar whose writable is true
    set nonWriteableCals to every calendar whose writable is false
    set writeableCalNames to {}
    set writeableCalIDs to {}
    set nonwriteableCalNames to {}
    set nonwriteableCalIDs to {}
    repeat with i from 1 to count of writeableCals
      set writeableCalNames to writeableCalNames & {(i & ": " & name of item i of writeableCals as text)}
      set writeableCalIDs to writeableCalIDs & {uid of item i of writeableCals}
    end repeat
    repeat with i from 1 to count of nonWriteableCals
      set nonwriteableCalNames to nonwriteableCalNames & {("_" & i & ": " & name of item i of nonWriteableCals as text)}
      set nonwriteableCalIDs to nonwriteableCalIDs & {uid of item i of nonWriteableCals}
    end repeat
    set thecalname to (choose from list writeableCalNames & nonwriteableCalNames) as text
    if thecalname does not start with "_" then
      set theIndex to (word 1 of thecalname) as integer
      set thecalID to item theIndex of writeableCalIDs
    else
      set thecalname to (characters 2 through -1 of thecalname) as text
      set theIndex to (word 1 of thecalname) as integer
      set thecalID to item theIndex of nonwriteableCalIDs
    end if
    set thecal to calendar id thecalID of application "iCal"
  end tell
end returntheCal
									

Leave a Reply