FTP Links in Emails per Script downloaden

ich habe es ;-)

Code:
using terms from application "Mail"
    on perform mail action with messages theMessages for rule theRule
        repeat with eachMessage in theMessages
            tell application "Mail"
                set this_subject to subject of eachMessage
                set this_body to content of eachMessage
                #display dialog this_subject
                #display dialog this_body
                #say 1
                #set myURL to paragraph 5 of this_body # variante 1
                set myURL to do shell script "echo " & quoted form of this_body & " | grep -iom 1 'ftp:.*zip'" # variante 2
                #display dialog myURL
                do shell script "wget -p ~/Downloads " & myURL
                #say 2
            end tell
        end repeat
    end perform mail action with messages
end using terms from

Mit dieser grep-Option steht in myURL genau der FTP-Link drin. Aber ein Download findet noch nicht statt. Wenn ich die Zeile in die Zwischenablage kopiere und im Terminal einfüge rennt der Download sofort los. Was kann da noch falsch sein?
 
Eventuell wird der ~ nicht aufgelöst. Probier das mal testhalber mit dem gesamten Pfad.
 
nein, auch mit kompletten Pfad geht es nicht
 
Code:
using terms from application "Mail"
    on perform mail action with messages theMessages for rule theRule
        repeat with eachMessage in theMessages
            tell application "Mail"
                set this_subject to subject of eachMessage
                set this_body to content of eachMessage
                #display dialog this_subject
                #display dialog this_body
                #say 1
                #set myURL to paragraph 5 of this_body # variante 1
                set myURL to do shell script "echo " & quoted form of this_body & " | grep -iom 1 'ftp:.*zip'" # variante 2
                #display dialog myURL
                tell application "Safari" to open location myURL
                #do shell script "wget -p ~/Downloads " & myURL
                #say 2
            end tell
        end repeat
    end perform mail action with messages
end using terms from
über Safari funktioniert das Script - wäre aber schon schöner es würde unbemerkt im Hintergrund laden.......
 
Weil du kein wget installiert oder es nicht im suchpfad hast. Also schau wo es liegt und gib den Pfad mit an.
 
Habe gerade nachgelesen - ist bei OS X nicht mit dabei und demzufolge bei mir nicht installiert.
Gibt es Alternative die in OS X vorhanden ist? curl?
Wenn ich einfach nur die Download-Link-Zeile im Terminal kopiere, lädt er auch ordentlich. Ich habe aber schon probiert

Code:
do shell script myURL
Macht er nicht
 
Zuletzt bearbeitet:
ich weiss, etwas unverständlich ausgedrückt ;-)

Was zeigt "which wget"?
nein, kommt kein Pfad - quasi nicht installiert

Code:
do shell script "curl -O " & myURL
Damit lädt er die Dateien erst einmal im Hintergrund herunter, aber in mein User-Verzeichnis und nicht in Downloads. Ich will nun vor dem curl-Befehl noch ein cd machen, so dass er curl im Downloadordner ausführt und die Files da ablegt. Wie bekomme ich 2 Befehle hinter do shell script hin?
 
Ich denke jetzt läuft das script und beim Eingang neuer Emails mit Downloadlink werden diese automatisch im Hintergrund ins Downloadverzeichnis gespeichert.

Code:
using terms from application "Mail"
    on perform mail action with messages theMessages for rule theRule
        repeat with eachMessage in theMessages
            tell application "Mail"
                set this_subject to subject of eachMessage
                set this_body to content of eachMessage
                #display dialog this_subject
                #display dialog this_body
                #say 1
                #set myURL to paragraph 5 of this_body # variante 1
                set myURL to do shell script "echo " & quoted form of this_body & " | grep -iom 1 'ftp:.*zip'" # variante 2
                #display dialog myURL
                #tell application "Safari" to open location myURL
                #do shell script "wget -p ~/Downloads " & myURL
                do shell script "cd ~/Downloads; curl -O " & myURL
                #say 2
            end tell
        end repeat
    end perform mail action with messages
end using terms from

Danke @Olivetti für deine super Unterstützung!!!
 
prego!
 
  • Gefällt mir
Reaktionen: svenson1
Guten Abend,
mein Script, welches in diesem Thread diskuttiert wurde, lief immer perfekt.

Ich muss nun eine Anpassung durchführen, weil sich die Eingangsmails verändert haben. Und zwar steht jetzt in der Betreffzeile in eckigen Klammern der zu isolierende String. Dieser String ist der Dateiname einer ZIP die von einem FTP geladen werden soll.
Ich habe das Script wie folgt verändert:

Code:
using terms from application "Mail"
    on perform mail action with messages theMessages for rule theRule
        repeat with eachMessage in theMessages
            tell application "Mail"
                set this_subject to subject of eachMessage
                set this_body to content of eachMessage
                #display dialog this_subject
                #display dialog this_body
                set myURL to do shell script "echo " & quoted form of this_subject & " | grep -oP '(?<=[)(.*?)(?=])'"
                display dialog myURL
                #tell application "Safari" to open location myURL
                #do shell script "wget -p ~/Downloads " & myURL
                #do shell script "cd ~/Downloads; curl -O " & myURL
            end tell
        end repeat
    end perform mail action with messages
end using terms from

Das Script sollte mir nur erst einmal Anzeigen, was in myURL steht. Leider bekomme ich keine Anzeige.
Was ist an dem grep-Befehl noch nicht richtig?
 
Code:
echo "thema [123456]" | grep -iom 1 '\[.*\]' | sed -e 's/\[//' -e 's/\]//'

# oder

echo "thema [123456]" | sed 's/.*\[\([^]]*\)].*/\1/'
 
Super - Vielen Dank! LÄUFT :)
 
Zurück
Oben Unten