Hilfe mein altes Applescript läuft nicht mehr

Daniel65

Golden Delicious
Registriert
13.06.18
Beiträge
8
Hallo zusammen

Ich hoffe es kann mir jemand helfen. Ich benutze seit Jahren ein einfaches Script um aus Filemaker heraus ein e-Mail zu schreiben.
Seit ich meine Macs (aus OS 10.13 und neuer) nun upgraded habe, funktioniert es nicht mehr. Ich habe das Script zum Versuch aus Filemaker kopiert und im Skript Editor versucht es zu laufen zu bringen. Es klappt einfach nicht.
Wenn ich den Befehl "visible:false" lösche, öffnet es zwar eine neue Mail, aber der Empfänger wird nicht eingesetzt und im content wird der Text nicht eingesetzt.
Was mache ich falsch oder was wurde wieder einmal mit dem Upgrade geändert?

Hier noch das einfache Script, welches vor dem Upgrade jahrelang funktionierte:
tell application "Mail"
activate
set theNewMessage to make new outgoing message with properties {subject:"Test", content:"", visible:false, sender:"[email protected]"}
tell theNewMessage
make new to recipient at end of to recipients with properties {address:"[email protected]"}
tell content
activate
tell application "System Events"
keystroke "v" using {command down}
end tell
end tell
end tell
end
tell

Vielen Dank im voraus
 

hubionmac

Tydemans Early Worcester
Registriert
25.06.04
Beiträge
393
Hm, also bei mir unter 10.13.4 öffnet er brav ein neues Email-Fenster und setzt auch den Empfänger und fügt den Text ein.
Testest Du direkt aus Filemaker oder aus dem Script-Editor von System?
 

Daniel65

Golden Delicious
Registriert
13.06.18
Beiträge
8
Ich haben 10.13.3 und habe es im Script Editor versucht, neachdem es in Filemaker nicht geklappt hat. Es öffnet sich das App Mail, jedoch keine neue Mail und danach erklingt der typische "Pong". Da wahrscheinlich das einsetzen durch cmd+v nicht klappt.
Script Editor 2.7 Version 2.10 (194).
Es klappt zum Beispile im Büro auf keinem Mac .... :(
 

sedna

Galloway Pepping
Registriert
22.10.08
Beiträge
1.358
Hallo,

mal davon ausgehend, dass wir im gleichen Hier und Jetzt leben...und mein macOS 10.13.5 sich so verhält, wie alle macOS 10.13.5, behaupte ich, dass das so nicht funktionieren kann und bin sogar ein klein wenig erstaunt, dass es jemals funktioniert hat... und noch mehr, dass es bei hubionmac funktioniert!

Füge in deinem Skript folgende Zeile vor tell content ein:
delay 2
und du siehst, warum....


Um den Inhalt der Zwischenablage als "content" der E-Mail einzufügen, ändere das Skript folgendermaßen:
Code:
tell application "Mail"
activate
set theNewMessage to make new outgoing message with properties {subject:"Test", content:the clipboard, visible:false, sender:"[email protected]"}
tell theNewMessage
make new to recipient at end of to recipients with properties {address:"[email protected]"}
end tell
end tell
.
Es gibt erstens wohl keinen unzuverlässigeren Weg in einem Skript, die Zwischenablage einzufügen, als mit cmd-v!
Ausserdem ist es zweitens doch irgendwie unsinnig, erst den Inhalt der E-Mail mit "" zu bestimmen um ihn sofort danach dann doch zu bestimmen!

Gruß
 

Daniel65

Golden Delicious
Registriert
13.06.18
Beiträge
8
Vielen Dank für den Tipp. Ich habe das Script wie unten im Editor laufen lassen. Mail öffnet sich und nur ganz kurz erscheint das neue Mail-Fenster (ca. 1 Sekunde) und schliesst sofort wieder.

tell application "Mail"
activate
set theNewMessage to make new outgoing message with properties {subject:"Test", content:the clipboard, visible:false, sender:"[email protected]"}
tell theNewMessage
make new to recipient at end of to recipients with properties {address:"[email protected]"}
end tell
end tell

Was mache ich falsch?
 

Daniel65

Golden Delicious
Registriert
13.06.18
Beiträge
8
Komisch ... wenn ich den Befehl "visible:false" weglasse, scheint es zu klappen. welchen Zweck erfüllt dieser Befehl "visible:false"?
 

Daniel65

Golden Delicious
Registriert
13.06.18
Beiträge
8
Es klappt wieder fast wie früher. Danke.
Die Schritte mit Copy & Paste habe ich früher extra integriert, da dadurch die Schrift Formatierung auch übernommen wurde. So habe ich im Feld Mailtexte (Formel) den Text formatiert (z.B. Wörter oder Abschnitte Fett). Und das wurde so übernommen.

Die Formatierung wird jetzt so aber nicht mehr übernommen - komisch.

Wir nehmen dann auch manuell die html Vorlage von Mail "Fotos - Postkarte". Dies kann man meines Wissens nicht mit Applescript automatisieren, oder?

lg
Daniel
 

Anhänge

  • Bildschirmfoto 2018-06-14 um 11.37.13.png
    Bildschirmfoto 2018-06-14 um 11.37.13.png
    119,4 KB · Aufrufe: 15

sedna

Galloway Pepping
Registriert
22.10.08
Beiträge
1.358
Oje... ja, die Formatierung geht flöten und es ist wirklich nicht einfach, die beizubehalten.

visible (boolean) : Controls whether the message window is shown on the screen.

Du bräuchtest tatsächlich ein GUI-Skript. Ist zwar doof, aber machbar.

Entweder in dieser Art ..
Code:
set postcardTemplate to POSIX file "/Library/Application Support/Apple/Mail/Stationery/Apple/Contents/Resources/Photos/Contents/Resources/Postcard.mailstationery" as alias

tell application "Mail"
    activate
    open postcardTemplate
 
    tell application "System Events"
        tell process "Mail"
            tell window 1
                repeat until focused of UI element 1 of scroll area 1
                    keystroke tab using shift down
                end repeat
                keystroke "a" using command down
                keystroke "v" using command down
             
                repeat until focused of text field 1
                    keystroke tab using shift down
                end repeat
                keystroke "[email protected]"
             
                repeat until focused of text field 3
                    keystroke tab
                end repeat
                keystroke "Test"
             
                repeat until focused of pop up button 1
                    keystroke tab
                end repeat
                keystroke space
                keystroke (string id 31)
                keystroke return
             
                repeat until focused of UI element 1 of scroll area 1
                    keystroke tab
                end repeat
                keystroke "a" using command down
                keystroke "TEST"
            end tell
        end tell
    end tell
end tell
- - - - -
- - - - - - - -
Oder so rum

Code:
tell application "Mail"
    activate
    set theNewMessage to make new outgoing message with properties {subject:"Test", content:"", sender:"[email protected]"}
    tell theNewMessage
        make new to recipient at end of to recipients with properties {address:"[email protected]"}
    end tell
end tell

tell application "System Events"
    tell process "Mail"
 
        repeat until focused of UI element 1 of scroll area 1 of window 1
            keystroke tab using shift down
        end repeat
        keystroke "v" using command down
     
        tell window 1
            click button 7 of toolbar 1
            delay 1
                set theTable to table 1 of scroll area 2
            set the category_list to the value of text field 1 of every row of theTable
         
            repeat with i from 1 to the count of the category_list
                set item i of the category_list to (item i of the category_list) as string
            end repeat
            if the category_list contains "Fotos" then
                repeat with i from 1 to the count of rows of theTable
                    set this_category to (the value of text field 1 of row i of theTable) as string
                    -- am besten "Postkarte" als Favorit sichern
                    if this_category is "Favoriten" then
                        select row i of theTable
                        exit repeat
                    end if
                end repeat
             
                set the template_list to radio group 1 of scroll area 3
                set the button_titles to the title of every button of template_list
                if the button_titles contains "Postkarte" then
                    click button "Postkarte" of template_list
                end if
            end if
         
        end tell
    end tell
end tell
Gegebenenfalls "Favoriten" durch "Fotos" ersetzen


Gruß
 
Zuletzt bearbeitet:

Daniel65

Golden Delicious
Registriert
13.06.18
Beiträge
8
Hallo
Erstmal vielen Dank. Die zweite Variante funktioniert beim zweiten Test sehr gut. Musste die Vorlage als Favorit abspeichern und bei den Einstellungen Sicherheit Script Editor freischalten.
Bei der ersten Variante gab es ein Problem, als ich es im Script Editor laufen liess. Das Script hing in einer Schleife mit Tab. Wenn ich das Programm wechselte, arbeitete auch dort das Script. Ich konnte nur noch den Mac Zwangs abschalten.
Aus diesem Grund werde ich mal die erste Variante versuch im Filemaker einzubauen.
Gruss
Daniel
 

Daniel65

Golden Delicious
Registriert
13.06.18
Beiträge
8
Hallo
Ich habe nun das Script im FM eingebaut und erhalte aber imm die Fehlermeldung: Zeilenende, etc. erwartet, aber "repeat" gefunden. und Fehlermeldung -2741. Im Editor läuft das Script jedoch einwandfrei.
Ist doch irgendwie seltsam, oder?

Im Filemaker habe ich es wie folgt eingebaut:

"tell application \"Mail\"
¶ activate
¶ set theNewMessage to make new outgoing message with properties {subject:\"" & $$Betreff & "\", content:\"\", sender:\"[email protected]\"}
¶ tell theNewMessage
¶ make new to recipient at end of to recipients with properties {address:\"" & $$MailAdr & "\"}
¶ end tell
¶ end tell

¶ tell application \"System Events\"
¶ tell process \“Mail\"

¶ repeat until focused of UI element 1 of scroll area 1 of window 1
¶ keystroke tab using shift down
¶ end repeat
¶ keystroke \“v\“ using command down

¶ tell window 1
¶ click button 7 of toolbar 1
¶ delay 1
¶ set theTable to table 1 of scroll area 2
¶ set the category_list to the value of text field 1 of every row of theTable

¶ repeat with i from 1 to the count of the category_list
¶ set item i of the category_list to (item i of the category_list) as string
¶ end repeat
¶ if the category_list contains \“Fotos\“ then
¶ set this_category to (the value of text field 1 of row i of theTable) as string
¶ if this_category is \“Favoriten\“ then
¶ select row i of theTable
¶ exit repeat
¶ end if
¶ end repeat

¶ set the template_list to radio group 1 of scroll area 3
¶ set the button_titles to the title of every button of template_list
¶ if the button_titles contains \“Postkarte\“ then
¶ click button \“Postkarte\“ of template_list
¶ end if
¶ end if

¶ end tell
¶ end tell
¶ end tell“
 

Anhänge

  • Bildschirmfoto 2018-06-16 um 18.53.06.png
    Bildschirmfoto 2018-06-16 um 18.53.06.png
    22,6 KB · Aufrufe: 9

sedna

Galloway Pepping
Registriert
22.10.08
Beiträge
1.358
Hallo,

Warum die erste Variante bei dir hängt, kann ich auf die Schnelle nicht beantworten.

Zu der zweiten Variante:
die Vorlage in „Favoriten“ gespeichert, sollte das Skript einfach etwas schneller laufen lassen....deshalb mein kurzer Hinweis.

Ich sehe übrigens gerade beim Lesen meines Skriptes, dass es etwas umständlich geschrieben ist. Weiter unten eine leicht modifizierte Variante.

Zu deiner Frage den Hinweis, dass es wirklich sehr zu empfehlen ist, Skripte hier in CODE tags gepackt zu posten!

Ich kenne FileMaker gar nicht! Keine Ahnung, wie da AppleScript ausgeführt werden. Die Fehlermeldung besagt einen Syntaxfehler ...
Du kannst ja mal folgendes versuchen - das Skript quasi auszulagern! Hier zwei Möglichkeiten. Dazu das untenstehende Skript im Skript-Editor einmal als Skript und einmal als Programm speichern.
Dann das Skript so ansprechen:
Code:
run script file (POSIX file "/Pfad/zu/deinem/Skript.scpt")


Die App so:
Code:
set MyApp to (POSIX file "/Pfad/zu/deiner/App.app" as string)
tell application MyApp to activate


Pfade ergänzen!
Die App braucht eine Berechtigung in den Systemeinstellungen Sicherheit-Bedienungshilfen




Gruß


- - - - - - - - - - - - - - - - - -


GUI Skript modifiziert:
Code:
tell application "Mail"
    activate
    set theNewMessage to make new outgoing message with properties {subject:"Test", content:"", sender:"[email protected]"}
    tell theNewMessage
        make new to recipient at end of to recipients with properties {address:"[email protected]"}
    end tell
end tell

tell application "System Events"
    tell process "Mail"    
        repeat until focused of UI element 1 of scroll area 1 of window 1
            keystroke tab using shift down
        end repeat
        keystroke "v" using command down
     
        tell window 1
            click button 7 of toolbar 1
            delay 1
            set theTable to table 1 of scroll area 2
            set the category_list to the value of text field 1 of every row of theTable
         
            repeat with i from 1 to the count of rows of theTable
                set this_category to (the value of text field 1 of row i of theTable) as string
                -- am besten "Postkarte" als Favorit sichern
                if this_category is "Favoriten" then
                    select row i of theTable
                    exit repeat
                end if
            end repeat
         
            set the template_list to radio group 1 of scroll area 3
            set the button_titles to the title of every button of template_list
            if the button_titles contains "Postkarte" then
                click button "Postkarte" of template_list
            end if
        end tell
    end tell
end tell
 
  • Like
Reaktionen: Wuchtbrumme

Daniel65

Golden Delicious
Registriert
13.06.18
Beiträge
8
Super, danke vielmals für Deine Hilfe. Habe es nun im Filemaker zum Laufen gebraucht. Bis jetzt läuft es sehr gut. Muss nun nur noch alle Stationen entsprechen vorbereiten.

- in Mail den Favoriten setzen
- in Einstellungen noch Script Editor und Filemaker freischalten um den Mac zu steuern.
et voila.....

Für die, die es im Zusammenhang mit Filemaker interessiert:
https://filemaker-magazin.de/forum/beitrag/180575

Ganz herzlichen Gruss und nochmals vielen Dank für die Hilfe
Daniel