• Apfeltalk ändert einen Teil seiner Allgemeinen Geschäftsbedingungen (AGB), das Löschen von Useraccounts betreffend.
    Näheres könnt Ihr hier nachlesen: AGB-Änderung
  • Viele hassen ihn, manche schwören auf ihn, wir aber möchten unbedingt sehen, welche Bilder Ihr vor Eurem geistigen Auge bzw. vor der Linse Eures iPhone oder iPad sehen könnt, wenn Ihr dieses Wort hört oder lest. Macht mit und beteiligt Euch an unserem Frühjahrsputz ---> Klick

[gelöst]try handling und adressbook probleme (Applescript)

rev.angeldust

Granny Smith
Registriert
29.04.09
Beiträge
14
Hallo an alle =)

Ich habe mich heute mal ein bisschen in Applescript versucht und bin wirklich überrascht, was man damit alles anstellen kann.
Aus spass habe ich mal ein Script geschrieben, dass einen Namen abfragt und dann mit dem Adressbook vergleicht, ob er den Namen kennt
soweit so gut, hier mal der code:
Code:
set temp to display dialog "Who are you?" default answer "" buttons {"OK"}
set johndoe to text returned of temp
set speech to ("Hello " & johndoe as string) & "!"
say speech using "Zarvox"
-- Adressbuch durchsuchen
set repeatition to true
set i to 1
repeat while repeatition is true
	try
		tell application "Address Book"
			set searchjohn to every person whose first name = johndoe
			set temp to properties of (item i of searchjohn)
			set lastname to last name of temp
		end tell
	on error
		set repeatition to false
		say "I don't seem to know you!" using "Zarvox"
	end try
	set speech to "are you " & johndoe & " " & lastname & "?"
	say speech using "Zarvox"
	display dialog "are you?" buttons {"yes", "no"} default button 2
	if the button returned of the result is "yes" then
		set repeatition to false
	else
		set repeatition to true
	end if
	set i to i + 1
end repeat

hier jetzt mal meine Fragen:
- obwohl im on error part die variable zur wiederholung auf false gesetzt wird, wiederholt er trotzdem. Das passiert nicht, wenn im if block des display dialog repeatition auf false gesetzt wird! woran kann das liegen?
- obwohl ich eigentlich adressbook sage, dass er every person suchen soll, dessen name = johndoe ist, hat er immer nur ein item (also die erste Person, dessen Name übereinstimmt) woran kann das liegen? er müsste doch eigentlich alle in der liste haben?

Vielen Dank für eure Hilfe!

Grüße

Angeldust

edit: okay, habs selber hinbekommen! ich weiss nicht genau was da passiert ist, jetzt funktionierts aber einwandfrei!
für alle die es jetzt noch analysieren wollen, hier der code:
Code:
set found to true
set temp to display dialog "Who are you?" default answer "" buttons {"OK"}
set johndoe to text returned of temp
set speech to ("Hello " & johndoe as string) & "!"
say speech using "Zarvox"
-- Adressbuch durchsuchen
set again to true
set i to 1
repeat while again is true
	try
		tell application "Address Book"
			set searchjohn to every person whose first name = johndoe
			set temp to properties of (item i of searchjohn)
			set lastname to last name of temp
		end tell
	on error
		set found to false
	end try
	if found is true then
		set speech to "are you " & johndoe & " " & lastname & "?"
		say speech using "Zarvox"
		display dialog "are you?" buttons {"yes", "no"} default button 2
		if the button returned of the result is "yes" then
			set again to false
		else
			set again to true
		end if
	else
		say "I don't seem to know you!" using "Zarvox"
		set again to false
	end if
	set i to i + 1
end repeat
 
Zuletzt bearbeitet: