17

I would like to be able to sleep while Models are running for much of the night in ArcGIS for Desktop .

I would like to have ArcGIS for Desktop play a sound when it finishes, to awaken me.

Is this possible?

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Aaron
  • 171
  • 3

2 Answers2

18

I really like Aarons answer, but something more simple and local:

subprocess.Popen([r"C:\Program Files (x86)\Windows Media Player\wmplayer.exe",r"C:\Users\Public\Music\Sample Music\Maid with the Flaxen Hair.mp3"])

using the subprocess module cause windows media player to open a file..

import subprocess

wmPlay = r"C:\Program Files (x86)\Windows Media Player\wmplayer.exe"
PlayFile= r"C:\Users\Public\Music\Sample Music\Maid with the Flaxen Hair.mp3"
subprocess.Popen([wmPlay,PlayFile])

Of course the sample music is more likely to put you to sleep so something more like my alarm clock tone might be more suitable.

But of course that's so simple you could do both, just tack that onto the end of Aarons' code.

Michael Stimson
  • 25,566
  • 2
  • 35
  • 74
  • 1
    Excellent idea! This could also be easily incorporated as a script tool. – Aaron Jun 26 '14 at 22:29
  • 2
    Love this script idea. I'd suggest an mp3 like the National Geographic theme music, or Where in the World is Carmen Sandiego, but that might be a little too geeky of me... – Erica Jun 27 '14 at 11:53
  • Everybody's musical taste is different. I chose a song that was loud and annoying as that's more likely to get attention. Flight of the Valkyries would be an excellent choice if you were unlikely to sleep though it. If you were really keen you could put in a parameter of the file to be played and get it reporting back with short tones at critical points as proof of life – Michael Stimson Jun 28 '14 at 04:07
  • and again, I pre-empted your answer with a 1998 AML which makes an annoying beep ;) – Stephen Lead Jul 01 '14 at 23:45
  • Ha ha @StephenLead, in ArcInfo just about everything made an annoying beep. You could walk away and make a coffee and know your process was still going just by the chain of beeps. This of course assumes your system speaker is installed. – Michael Stimson Jul 01 '14 at 23:47
17

How about e-mailing yourself when the model is finished? Make sure to set your phone to give you a tone when you receive the e-mail sent via the attached Python script. This is designed to be run as a script tool in ModelBuilder. If you are not familiar working with script tools, follow these instructions. Please not that this is configured to work with gmail. The tool is designed to work as follows (note the precondition attaching the bufferedPoints variable and the sendEmail script tool):

enter image description here


import smtplib, os, arcpy
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email import Encoders

# Fill in the necessary blanks here
gmail_user = sys.argv[1]
gmail_pwd = sys.argv[2]

# The parameters
to = sys.argv[3]
subject = sys.argv[4]
text = sys.argv[5]

def mail(to, subject, text):
    msg = MIMEMultipart()

    msg['From'] = gmail_user
    msg['To'] = to
    msg['Subject'] = subject

    # Attaches a text message to the e-mail
    msg.attach(MIMEText(text))

    mailServer =smtplib.SMTP("smtp.gmail.com", 587)
    mailServer.ehlo()
    mailServer.starttls()
    mailServer.ehlo()
    mailServer.login(gmail_user, gmail_pwd)
    mailServer.sendmail(gmail_user, to, msg.as_string())
    mailServer.close()

mail(to, subject, text)

Instructions for creating the script tool:

Create the script

  1. Open IDLE > File > New Window
  2. Copy and paste script on this post to the new window
  3. Save as > "SendEmail.py"

Create the script tool

  1. Right-click on a folder > New > Toolbox (This is where the script tool will be located)
  2. Right-click toolbox > Add > Script...
  3. Fill in Name, Lable, Description and check "Store relative path...."
  4. Hit Next
  5. Add the script you created "SendEmail.py"
  6. Hit Next
  7. Fill in the parameters exactly as in attached figure.
  8. Hit Finish
  9. Locate new tool in tool box and use as you would any other tool in ModelBuilder

enter image description here

Paul
  • 11,608
  • 1
  • 29
  • 47
Aaron
  • 51,658
  • 28
  • 154
  • 317
  • Hey, you've got the same name? are you related? That's a nice ouside-the-box solution, I like it. That way you don't need to be in the same room. Can that be configured for outlook/exchange or to they work differently? – Michael Stimson Jun 26 '14 at 22:03
  • 1
    @ Michael Miles-Stimson Funny coincidence, there are not too many Aaron's anymore. This script tool works directly through the e-mail service and is independent of outlook. However, if Outlook can read you e-mail and your phone can notify you when you get a e-mail via Outlook, it should work just fine. – Aaron Jun 26 '14 at 22:11
  • 1
    I work with an Aaron, he's cool too. I was referring to outgoing email, essentially I would be emailing myself.. message from me to me sent from work computer and read/notify on home computer on VPN. Outlook can be configured to play a sound when an email comes in. – Michael Stimson Jun 26 '14 at 22:16
  • 1
    OK. This is very promising! I dont quite understand where to put my actual email address. Do i substitute it for the phrase "gmail_user"? or is that the variable? What are the "sys.argv[#]" things? Is that where I put my information? – Aaron Jun 26 '14 at 22:46
  • 1
    @Aaron sys.argv is the list containing the arguments passed to the Python script from the command line. It is the equivalent of using arcpy.GetParameterAsText(i) – om_henners Jun 27 '14 at 00:04
  • 3
    If it helps anyone, I've put up an example gist that shows how to use @Aaron 's answer as a wrapper to notify on success or failure of a script. – om_henners Jun 27 '14 at 00:05
  • 1
    Read this http://resources.arcgis.com/en/help/main/10.2/index.html#/Adding_a_script_tool/00150000001r000000/ about making a script into a tool that can be used in modelbuilder. Each sys.argv relates to a parameter in the tool, sys.argv[1] is the first, sys.argv[2] is the second and so on.. Note: it also works on the command line if you want to use the script in VB using shell. – Michael Stimson Jun 27 '14 at 01:18
  • @Aaron I included more details on creating the script tool to address your comments. – Aaron Jun 27 '14 at 13:55
  • This script works great, but what if I wanted to cc another address using this same script? Does anyone know how I could modify the above script to do that? – Michael B Jun 22 '15 at 16:08
  • @MichaelB Check out the following post regarding CC'ing users using smtplib.email: http://stackoverflow.com/a/1546435/1446289 – Aaron Jun 22 '15 at 17:29
  • Thanks for the help. I am not good with python at all. I have tried experimenting using that example, but I cannot seem to make it work. The script your provided on this page is different enough from the example on stackoverflow to confuse me. – Michael B Jun 22 '15 at 18:53
  • @MichaelB I would advise posting your inquiry to Stack Overflow. – Aaron Jun 22 '15 at 19:00