Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I quite often use the python -m SimpleHTTPServer command in the Terminal to fire up a webserver for testing apps. Having just learned the basics of the Automator, I figured this would be a great use for it - having added the following as a service I can now right-click on a folder and have a webserver launch pointing at that folder.

cd $1
python -m SimpleHTTPServer 8000

The only problem I have, is the lack of output from the workflow. Doing it manually I have a Terminal window displaying the requests coming in and enabling me to Ctrl+C to end the webserver.

The Automator workflow is silent and I have to open Activity Monitor and quit Python to close it. Is there a way to have it run the script in a Terminal window?

share|improve this question
add comment

2 Answers 2

If you like using Automator try the Growl Notifier in Automator (below is an example). Growl is extensible to almost any application/script/service on OS X. It works really well for showing output for just about anything imaginable.

Auto Growling

share|improve this answer
    
Doesn't seem to work with python, still no output anywhere. –  littlecharva Sep 21 '11 at 6:15
add comment
up vote 3 down vote accepted

Figured out how to do it myself based upon adapting the following article.

http://hints.macworld.com/article.php?story=20050827164648766

Added a line in to run the python command:

on run {input, parameters}
  tell application "Terminal"
    activate
    if (the (count of the window) = 0) or ¬
     (the busy of window 1  = true) then
      tell application "System Events"
        keystroke "n" using command down
      end tell
    end if
    do script "cd \"" & (POSIX path of ¬
     (input as string)) & "\"" in window 1
    do script "python -m SimpleHTTPServer 8000" in window 1
  end tell
  return input
end run
share|improve this answer
    
Replace the 'tell application "System Events"' block with just "do script". A "do script" command with no parameters will open a new terminal window. Simulating keystrokes is an unreliable means to script an application; only do it as a last resort, if there's no means to directly tell it to do what you want. –  Chris Page Sep 26 '11 at 14:16
    
That "do script" command won't work will all valid pathnames. Remove the quotes from the shell command string (\") and use quoted form of (POSIX path of (input as string)) instead. quoted form of knows how to correctly quote all characters that need to be quoted for shell commands. –  Chris Page Sep 26 '11 at 14:23
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.