1

Why doesn't this work?

Applescript:

set script_path to "$HOME/Desktop"
do shell script "python & script_path & hello_world.py"

Python script:

#!/usr/bin/env python
print "Content-Type: text/html"
print
print """\
<html>
 <head>
  <title>Python - Hello World</title>
 </head>
 <body>
  Hello World
 </body>
</html>

"""

Errors:

tell current application do shell script "python & script_path & hello_world.py" --> error "sh: script_path: command not found sh: hello_world.py: command not found" number 127 Result: error "sh: script_path: command not found sh: hello_world.py: command not found" number 127

1
  • 1
    Is that really how you concatenate in AppleScript? I'd guess that that runs python in the background, script_path in the background, and hello_world.py. (The latter two don't exist.) Commented Apr 20, 2013 at 22:58

1 Answer 1

2

The ampersands concatenate the string literals and variable substitutions. Like so:

set script_path to "$HOME/Desktop"
do shell script "python " & script_path & "/hello_world.py"

You also need a slash before hello_world.py or at the end of $HOME/Desktop. The example above shows it before hello_world.py.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.