Growl-Alarm für Adressbuch-Geburtstage

Dienstag, 20 April 2010
0.0/5 Bewertung (0 Stimmen)
Beschreibung

Da ich viele Kontakte in meinem Adressbuch habe, hielt ich es für eine gute Idee, mich mit Growl über die Geburtstage informieren zu lassen. Also habe ich (With a Little Help from my Friends) ein AppleScript geschrieben, dass diese Arbeit für mich erledigt.
Zunächst muss allerdings Growl installiert werden, wenn das nicht ohnehin schon passiert ist. Ausserdem müssen Sie den Terminal-Befehl growlnotify installieren, den Sie im Ordner ”Extras” des Growl-Images finden. Anschließend kopieren Sie das folgende Script in den ScriptEditor:


delay 0.5
set isRunning to 0
set timer to the time of the (current date)
repeat while isRunning = 0
tell application ”System Events”
set isRunning to ¬
((application processes whose (name is equal to ”GrowlHelperApp”)) count)

end tell

if isRunning ≥ 1 then
--try
MyScript()
-- end try
else if (the (time of the (current date)) - timer) > 2 then
set isRunning to -1
quit
end if
delay 1
end repeat
on MyScript()
set birthdayPeople to {}
set birthdayDates to {}
set birthdayMonths to {}
set birthdayAge to {}
set birthdayPeopleToday to {}
set birthdayDatesToday to {}
set birthdayMonthsToday to {}
set birthdayAgeToday to {}
set message to ””
set messageToday to ””
set endOfYear to false
-- Get the current date & next week

set today to current date
set todayDate to day of today

set nextWeek to today + (60 * 60 * 24 * 7)
if (hours of today) is greater than 11 then
set today to today - (60 * 60 * 24)
end if
if (year of nextWeek) is greater than (year of today) then
set endOfYear to true
end if
-- Loop through everyone in the Address Book
tell application ”Address Book”
set peopleArray to the name of every person
repeat with i from 1 to count of peopleArray
set thisPerson to person i
set thisBirthday to birth date of thisPerson

-- Check if they”ve got a birthday entered on their card
if thisBirthday is not equal to (missing value) then
set whichMonth to (month of thisBirthday) as number
if ((endOfYear is true) and (whichMonth = 1)) then
set peopleAge to ((year of today as number) - (year of thisBirthday as number) + 1) as string
set year of thisBirthday to (year of today) + 1
else
set peopleAge to ((year of today as number) - (year of thisBirthday as number)) as string
set year of thisBirthday to year of today -- otherwise it uses their birth year
end if
-- See if it”s in the next week
if (thisBirthday is greater than today) and (thisBirthday is less than nextWeek) then
set thisBirthday_day to day of thisBirthday
set thisBirthday_month to month of thisBirthday as number
-- Add them to our list
if (todayDate) is equal to thisBirthday_day then
set birthdayPeopleToday to birthdayPeopleToday & name of thisPerson
set birthdayDatesToday to birthdayDatesToday & thisBirthday_day
set birthdayMonthsToday to birthdayMonthsToday & thisBirthday_month
set birthdayAgeToday to birthdayAgeToday & peopleAge
else
set birthdayPeople to birthdayPeople & name of thisPerson
set birthdayDates to birthdayDates & thisBirthday_day
set birthdayMonths to birthdayMonths & thisBirthday_month
set birthdayAge to birthdayAge & peopleAge
end if
end if
end if

end repeat
end tell
if ((count of birthdayPeople) is greater than 0) then
repeat with i from 1 to count of birthdayPeople
set message to message & item i of birthdayPeople & ” (” & item i of birthdayAge & ”) am ” & item i of birthdayDates & ”.” & item i of birthdayMonths & ”.” & year of today & return
end repeat
--display dialog message
--modify the next line to reflect the location of your image, or remove the
--image reference. Also change the text as you wish.
do shell script ”usr/local/bin/growlnotify --image /Users/Nomis101/Applications/cake.gif -t ”Birthdays this week:” -m ”” & message & ”””
end if
if ((count of birthdayPeopleToday) is greater than 0) then
repeat with i from 1 to count of birthdayPeopleToday
set messageToday to messageToday & item i of birthdayPeopleToday & ” (” & item i of birthdayAgeToday & ”)” & return
end repeat
do shell script ”usr/local/bin/growlnotify -a ”Problem Reporter” -t ”Birthdays TODAY:” -m ”” & messageToday & ”””
--display dialog messageToday
end if
tell application ”Address Book”
quit
end tell
quit
end MyScript

In dem Script selber müssen Sie noch in der Zeile, die mit do shell script ”usr/local/bin/growlnotify... anfängt, den Pfad an Ihre eigene Umgebung anpassen. Beachtenb Sie weiterhin, dass im Script ein Verweis auf ein Bild ist, das erscheint, wenn der Alarm anspringt. Entweder passen Sie den Pfad ebenfalls an. oder kommentieren die entsprechende Zeile aus.
Speichern Sie das Script als Programm an einen beliebeigen Ort. Anschliessend gehen Sie in die ”System-Einstellungen -> Benutzer” und tragen das Script (Programm) als Startobjekt ein.
Ein Problem hatte ich mit dem Script: es war als Startobjekt zu schnell. Soll heissen, es konnte nicht richtig arbeiten, solange Growl nicht vollständig geladen war. Am Anfang des Scripts habe ich einen Verweis an ”GrowlHelperApp” eingefügt, die bewirkt, dass das Scipt solange pausiert, bis Growl vollständig geladen ist.
Das Script läuft wunderbar unter 10.5. Unter 10.6 habe ich leider das Problem, dass bei jedem Ausführen des Scripts das Adressbuch für kurze Zeit angezeigt wird.Bisher habe ich noch keine Möglichkeit gefunden, das Script im Hintergrund ablaufen zu lassen. Davon mal abgesehen, läuft das Script auch unter 10.6.
Erstellt von [url=http://www.macosxhints.com/users.php?mode=profile&uid=1067492]Nomis101[/url]

Spezifikationen

Hits

1602

© by macjaner.ch | Powered by GoeGG-ArT.ch