0
votes

Python: 2.7 Mac OSX: 10.12

I am brand new to using apple script and I am trying to use it to basically open a Python file (from its current directory without having to define the full path) that uses tkinter to open a GUI. Also, I do not want the terminal application to open.

I have both scripts below that I have found on stackover flow:

1.) Opens the Python file with AppleScript from current directory (without defining the full path in the script):

tell application "Finder"
    open file "pythonfile.py" of folder of (file (path to me))
end tell

2.) Opens a Python file with AppleScript, and does not open the terminal application when ran.

do shell script "export LC_ALL=en_US.UTF-8; export LANG=en_US.UTF-8; /usr/bin/python '/full/path/to/Pythonfile/pythonfile.py'  &> /dev/null &"

So I basically need help combining the two answers above, so that I do not have to write the full path in #2 and the terminal application window does not open when ran, which it will open in #1.

1

1 Answers

1
votes

get the path in Unix style

set scriptPath to (POSIX path of ((path to me as text) & "::") & "pythonfile.py") as text

then launch it

do shell script "export LC_ALL=en_US.UTF-8; export LANG=en_US.UTF-8; /usr/bin/python " & quoted form of scriptPath & " &> /dev/null &"