Page 1 of 1

Help converting simple Mail Applescript to python

PostPosted: Thu Oct 22, 2020 6:32 pm
by joekewe
Can someone help me convert this AppleScript to python so I can move to Indigo 7.4?

Code: Select all
property emailAddress : “bob@mac.com"
property emailSubject : "Office Alarm!"
property newline : ASCII character (10)

if value of variable "emailBob” < 50 then
        set emailBody to “Office alarm: " & value of variable "alarmCause" & newline
        set emailBody to emailBody & "Current time: " & time string of (current date) & newline
        send email to emailAddress with subject emailSubject with body emailBody
end if

Thanks,

Joe

Re: Help converting simple Mail Applescript to python

PostPosted: Thu Oct 22, 2020 8:17 pm
by FlyingDiver
Have you looked at the instructions in the Wiki on sending emails?

https://wiki.indigodomo.com/doku.php?id ... l_settings

Re: Help converting simple Mail Applescript to python

PostPosted: Fri Oct 23, 2020 3:46 pm
by joekewe
FlyingDiver wrote:
Have you looked at the instructions in the Wiki on sending emails?

https://wiki.indigodomo.com/doku.php?id ... l_settings


Yes. If I am not mistaken, Indigo's built-in email capability can only send pre-written text. It looks like you are the author of "Better Email," which is... better, because it lets you send Indigo variables and device states, but still not the current time like my little AppleScript does.

I was also hoping to use this as my intro to python scripting Indigo - to learn how to define variables and control external software like Mail. Any help appreciated.

Re: Help converting simple Mail Applescript to python

PostPosted: Fri Oct 23, 2020 4:25 pm
by FlyingDiver
You can use an Indigo action to put the current time into a variable, then include that variable in the email. Check under "Variable Actions".

The Better Email plugin wiki has an example script for sending an email: https://github.com/FlyingDiver/Indigo-B ... etterEmail

Combine that with a line of code to get the current time in a string: https://www.programiz.com/python-progra ... rrent-time

Actually controlling the Mail application without AppleScript is pretty much impossible. It's easier to use the native email sender or the BE plugin.