N
nilsaushd
Mitglied
Thread Starter
- Dabei seit
- 10.10.2016
- Beiträge
- 7
- Reaktionspunkte
- 0
Hallo zusammen
Ich habe dieses schöne Skript entdeckt, mit dem man von seinen Kontakten aus eine pages-Vorlage mit dem entsprechendem Adressfeld öffnen kann.
Praktisch eine Serienbrieffunktion durch die Hintertür.
Dummerweise übernimmt es aber nur den Vor- und Nachnamen und die Adresse.
Für meinen Zweck bräuchte ich noch Firma und Notizen.
Ich kenne mich leider überhaupt nicht mit AppleSkript aus und meine Versuche haben nur Fehlermeldungen erzeugt.
Weiß jemand, wie das Skript verändert werden müsste, damit es auch diese Informationen einfügt?
Vielen Dank, Gruß Nils
Hier das Skript
Ich habe dieses schöne Skript entdeckt, mit dem man von seinen Kontakten aus eine pages-Vorlage mit dem entsprechendem Adressfeld öffnen kann.
Praktisch eine Serienbrieffunktion durch die Hintertür.
Dummerweise übernimmt es aber nur den Vor- und Nachnamen und die Adresse.
Für meinen Zweck bräuchte ich noch Firma und Notizen.
Ich kenne mich leider überhaupt nicht mit AppleSkript aus und meine Versuche haben nur Fehlermeldungen erzeugt.
Weiß jemand, wie das Skript verändert werden müsste, damit es auch diese Informationen einfügt?
Vielen Dank, Gruß Nils
Hier das Skript
Code:
-- Properties festlegen
property recipientFirstNamePlaceholder : "RECIPIENTFIRSTNAME"
property recipientLastNamePlaceholder : "RECIPIENTLASTNAME"
property recipientFullAddressPlaceholder : "RECIPIENTFULLADDRESS"
-- Plugin definieren
using terms from application "Contacts"
on action property
return "address"
end action property
on should enable action for thePerson with theEntry
if theEntry = missing value then
return false
else
return true
end if
end should enable action
on action title for thePerson with theEntry
return "Brief mit Pages schreiben"
end action title
on perform action for thePerson with theEntry
--Schleife für Kontakte
tell application "Contacts"
-- Auswahl für Auslesen vorbereiten
set thisPerson to selection
set thisPerson to item 1 of thisPerson
-- Kontaktdaten in Variablen auslesen
tell thisPerson
set recipientFirstName to first name
set recipientLastName to last name
set recipientFullAddress to the formatted address of the first address of thisPerson
end tell
end tell
-- Ende der Schleife für Kontakte
-- Schleife für Pages
tell the application "Pages"
activate
-- Liste der Pages-Vorlagen aufrufen und eine wählen
set userTemplateNames to the name of every template whose id of it begins with "User/"
if userTemplateNames is {} then error number 10001
set the chosenTemplateName to ¬
(choose from list userTemplateNames with prompt ¬
"Bitte eine Vorlage wählen:" default items (item 1 of userTemplateNames))
if chosenTemplateName is false then error number -128
set chosenTemplateName to chosenTemplateName as string
-- Neues Dokument aus der Auswahl öffnen
set thisDocument to ¬
make new document with properties ¬
{document template:template chosenTemplateName}
tell body text of thisDocument
set recipientFullAddressPlaceholderCount to ¬
the count of (every word where it is recipientFullAddressPlaceholder)
end tell
tell thisDocument
-- Platzhaltertext mit Empfängerdaten ersetzen
set placeholderWordReplacementStringPairings to {{recipientFirstNamePlaceholder, recipientFirstName}, {recipientLastNamePlaceholder, recipientLastName}, {recipientFullAddressPlaceholder, recipientFullAddress}}
tell body text
with timeout of 600 seconds -- Bis zu 10 minuten gestatten, falls sehr lange Dokumente nach Platzhaltertexten durchsucht werden müssen
repeat with i from 1 to the count of placeholderWordReplacementStringPairings
copy item i of placeholderWordReplacementStringPairings to ¬
{placeholderWord, replacementString}
my replaceWordWithStringInBodyText(placeholderWord, replacementString)
end repeat
end timeout
end tell
end tell
end tell
end perform action
end using terms from
on replaceWordWithStringInBodyText(searchWord, replacementString)
tell application "Pages"
activate
tell the front document
tell body text
-- Schleife mit Ersetzungen
repeat with i from the (count of paragraphs) to 1 by -1
tell paragraph i
repeat
try
if exists searchWord then
set (last word where it is searchWord) to replacementString
else
exit repeat
end if
on error errorMessage
exit repeat
end try
end repeat
end tell
end repeat
end tell
end tell
return true
end tell
end replaceWordWithStringInBodyText
Zuletzt bearbeitet: