Mit Applescript in iCal Einträge erstellen

action

Tydemans Early Worcester
Registriert
15.11.05
Beiträge
389
Da ich mich in Applescript nicht auskenne, frag ich mal. Ist es möglich mit Applescript einen Countdown zu erstellen. Sprich eine Script das vom enddatum (z.B. 01.01.2008) bis zum anfangsdatum(z.B. 01.07.2007) jeden tag eine Zahl in de Kalendar "xy" einen eintrag mit einer zahl erstellt. Sprich am 1.1 steht "Noch 0 Tag" am 31.12 steht "Noch 1 Tag" Versteht ihr was ich meine?? Weis jemand wie man das machen könnte
 

Sarah Nyn

Kaiser Wilhelm
Registriert
02.06.07
Beiträge
177
Ich denke, das ginge. So zum Beispiel macht man ein neues event:
tell application "iCal"
tell calendar 1
make new event at the beginning with properties {description:"event", start date:current date, end date:current date}
end tell
end tell

Weitere properties eines events sind im Funktionsverzeichnis.
Über Datumsformatierungen gibt es hier etwas:
http://www.fischer-bayern.de/applescript/html/datum.html
http://www.fischer-bayern.de/applescript/html/datum2.html

Für Dialogboxen um das Zieldatum und Startdatum einzugeben gibt es diaplay dialog.

Eine schleife geht so:
repeat with x from 1 to number_of_days
...
end repeat

Jemand der sich damit etwas mehr befasst hat, kann das sicher machen, ich müsste erst noch etwas ausprobieren.

Hier sind Beispiele zu iCal:
http://www.apple.com/applescript/ical/03.html
 

Sarah Nyn

Kaiser Wilhelm
Registriert
02.06.07
Beiträge
177
Ich hätte einen Anfang, der allerdings schon einen Fehler hat. Die Anzahl Tage ist beschränkt. Naja. Das script fragt nach Anfangs- und Enddatum und berechnet die Anzahl Tage, mehr nicht. Die Eingabe muss in Tag.Monat.Jahr erfolgen.

Code:
on run
	
	display dialog "Anfangsdatum" default answer ""
	set anfangsdatum to date (text returned of result)
	
	display dialog "Enddatum" default answer ""
	set enddatum to date (text returned of result)
	
	repeat with anzahl_tage from 1 to 99999
		if anfangsdatum + (anzahl_tage * 60 * 60 * 24) is enddatum then
			exit repeat
		end if
	end repeat
	
end run

Was noch fehlt ist eine Schleife, die die Events erstellt. Vielleich guck ich das Morgen noch an, falls nicht ein höheres Wesen sich berufen fühlt.

Edit: Mein 2^6ter Beitrag. Yeah!
 
Zuletzt bearbeitet:

Sarah Nyn

Kaiser Wilhelm
Registriert
02.06.07
Beiträge
177
So. Ist zwar nicht wirklich schön gemacht, sollte aber gehn. Es fragt zuerst nach der Kategorie und dann anch den Daten.


Code:
on run
    
    tell application "iCal"
        
        set cal_list to {}
        
        repeat with x from number of calendars to 1 by -1
            set the beginning of cal_list to name of calendar x
        end repeat
        
        set cal_list_string to ""
        repeat with x from 1 to number of calendars
            set cal_list_string to cal_list_string & (x as text) & " - " & item x of cal_list & return
        end repeat
        
    end tell
    
    display dialog cal_list_string default answer ""
    set cal_number to text returned of result as number
    
    display dialog "Anfangsdatum" default answer ""
    set anfangsdatum to date (text returned of result)
    
    display dialog "Enddatum" default answer ""
    set enddatum to date (text returned of result)
    
    repeat with anzahl_tage from 1 to 99999
        if anfangsdatum + (anzahl_tage * 3600 * 24) is enddatum then
            exit repeat
        end if
    end repeat
    
    tell application "iCal"
        
        tell calendar cal_number
            
            set x_date to anfangsdatum
            
            repeat with x from anzahl_tage to 0 by -1
                set x_date to x_date + (3600 * 24)
                set event_summary to "Noch " & x & " Tag"
                if x is not 1 then
                    set event_summary to event_summary & "e"
                end if
                make new event at the beginning with properties {summary:event_summary, start date:x_date, end date:x_date}
            end repeat
            
        end tell

    end tell
    
end run
Edit: Man könnte auch noch einbauen, dass es nach einem summary fragt ung der Countdown als Notiz hinzugefügt wird. Oder dass es ganztägige Einträge werden oder sonstwas.
 
Zuletzt bearbeitet:

action

Tydemans Early Worcester
Registriert
15.11.05
Beiträge
389
Danke für die Antwort, das war genau das was ich gesucht habe. Vielen dank.
 

Mediaman2000

Jonagold
Registriert
04.12.10
Beiträge
23
Abend, ich möchte hier was aufwärmen: wie muss man den gezeigten Code modifizieren um automatisiert eine "Erinnerung", die in iOS 5 unterstützten Aufgaben einzutragen?