What causes AppleScript error 1721 when trying to execute Python3 file

applescriptpythonterminal

I'm trying to make AppleScript to execute Python 3 script:

on run {input, parameters}
    tell application "Terminal"
        do shell script "/usr/local/bin/python3 /Users/UserName/Desktop/PyHello.py $@"
    end tell
    return input
end run

but I'm still getting an error 1721. I tried different types of file as well as changing Command Line command from:

/usr/local/bin/python3 /Users/UserName/Desktop/PyHello.py $@

to

/python3 /Users/UserName/Desktop/PyHello.py $@"

Both commands:

/usr/local/bin/python3 /Users/UserName/Desktop/PyHello.py $@

and

/python3 /Users/UserName/Desktop/PyHello.py $@"

Run OK, when typed directly within the Terminal.

Best Answer

Thank you user3439894 on the basis of your answers I was able to figure out the problem.

That's the correct script for AppleScript:

tell application "Terminal"
    do shell script "/usr/local/bin/python3 /Users/UserName/Desktop/PyHello.py $@"
end tell

This script is for Automator to run AppleScript:

on run {input, parameters}
    tell application "Terminal"
        do shell script "/usr/local/bin/python3 /Users/UserName/Desktop/PyHello.py $@"
    end tell
    return input
end run

Also following shebang is needed in initial Python script:

#!/usr/bin/env python3