首先是Run Script,是在TextMate中运行脚本输出结果,但是我不能直接使用,提示python command not found 于是我手工修改了python的路径为我的python3的绝对路径: cmd + R 即可运行
不过我不喜欢这个内置的输出,因为如果是长时间跑脚本的话,他的输出会有延迟,还是在iTerm中直接运行该py文件比较方便,这时候就要用Run Script(Terminal)。但是由于它是用AppleScript调用iTerm,而AppleScript使用了一种过时的表达tell the current terminal导致无法使用,需要修改,这是我修改后的版本:
# run script using either Terminal.app or iTerm.app # if iTerm is open or if TM_TERMINAL is set to iTerm then use iTerm # otherwise default to Terminal.app since that is standard. # 这里将自带终端改成了iTerm TP=${TM_TERMINAL:=iTerm} TPY=${TM_PYTHON:-python}
# 主要改了这个地方的AppleScript # 然后删除临时文件由rm -rf改成了移至垃圾桶,避免误删文件导致文件丢失(一般不会生成临时文件所以用了个if做判断) if [ "$TP" == iTerm ] || [ $(iTerm_running) == 0 ]; then osascript <<END tell application "iTerm" activate set newWindow to (create window with default profile) tell newWindow tell current session write text "clear; cd $(esc "${TM_DIRECTORY}"); /usr/bin/python3 $(esc "${TM_FILEPATH}"); if [ -f $(esc "${TM_TMPFILE}") ]; then mv $(esc "${TM_TMPFILE}") ~/.Trash; fi" end tell end tell end tell END else osascript <<- APPLESCRIPT tell app "Terminal" launch activate do script "clear; cd $(esc "${TM_DIRECTORY}"); /usr/bin/python3 $(esc "${TM_FILEPATH}");if [ -f $(esc "${TM_TMPFILE}") ]; then mv $(esc "${TM_TMPFILE}") ~/.Trash; fi" set position of first window to { 100, 100 } end tell APPLESCRIPT fi