AppleScript per ottenere il contenuto del file in Apple Mail

0

Sto tentando di creare un bot per auto repeater. Il bot risponderà in modo diverso (ed eseguirà azioni diverse) in base al messaggio ricevuto. Invece di inviare email al bot, scriverò il bot (con un iPhone). Il mio fornitore (Verizon) riceve il messaggio e lo invia come un allegato , in un file denominato text_0.txt , come testo semplice.

Sfortunatamente, non so come ottenere AppleScript per ottenere il contenuto del file.

Quindi la mia domanda è la seguente, come posso ottenere AppleScript (scrivendo questo codice non Apple per renderlo più facile da capire) fai questo:

if (email contains type["file"]) {

if (email.file[0].name() === "text_0.txt") {

contents = email.file[0].content;

// Do stuff

} else {
// Do some other stuff
}

} else {
content = email.content;
}
    
posta JBis 25.07.2018 - 19:54
fonte

1 risposta

1

Sono un po 'confuso su quello che stai cercando di ottenere. Questa non è una soluzione esatta alla tua domanda, ma forse questo codice seguente ti aiuterà a metterti nella giusta direzione.

La prima parte del seguente codice con i comandi "Mail" prenderà il messaggio attualmente selezionato in Mail.app e salverà tutti gli allegati e-mail in quel messaggio sul desktop.

La seconda parte di questo codice seguente, con i comandi "Finder", leggerà il contenuto di qualsiasi file .txt nell'elenco dei file memorizzati in savedFileList e salverà tali informazioni nella variabile theContent

set saveFilePath to POSIX path of (path to desktop)
set savedFileList to {}

tell application "Mail"
    set theCount to every mail attachment of item 1 of (get selection)
    repeat with i from 1 to count of theCount
        try -- handles if "downloaded of (get mail attachment id theID of item 1 of (get selection))" is false
            set thisItem to item i of theCount
            set theID to id of thisItem
            set theFile to mail attachment id theID of item 1 of (get selection)
            set isDownloaded to downloaded of (get mail attachment id theID of item 1 of (get selection))
            set theName to name of theFile
            save theFile in POSIX file (saveFilePath & theName)
            set end of savedFileList to (saveFilePath & theName) as POSIX file as alias
        end try
    end repeat
end tell

set nameExtensions to {"txt"}

tell application "Finder"
    repeat with j from 1 to count of savedFileList
        set thisItem2 to item j of savedFileList
        if name extension of thisItem2 is in nameExtensions then
            set theContent to read thisItem2
        end if
    end repeat
end tell

A questo punto dovresti essere in grado di inviare file effettivi o contenuti dai file txt che hai ricevuto dal messaggio attualmente selezionato in "Mail.app". (Poiché tutte le informazioni sono state memorizzate in diverse variabili nel codice ... Per poter scegliere e agire su)

    
risposta data 26.07.2018 - 03:42
fonte

Leggi altre domande sui tag