![](/img/trans.png)
[英]AppleScript : how to run Python file from current directory (without using full path) and not open terminal
[英]How to open Mac terminal at a specific directory using python + applescript script
from applescript import tell
command = 'cd Downloads/"SSR Drive"'
yourCommand = "PERF -i "+str(x)+" -u CFG.txt"
tell.app( 'Terminal', 'do script "' + command + '"')
tell.app( 'Terminal', 'do script "' + yourCommand + '"')
我正在使用此代碼通過我的 python 腳本在 Mac 終端上執行命令。
“command”告訴終端打開目錄
“yourCommand”告訴終端執行一個 biopython 模塊 function。
但是當我執行時,命令在單獨的終端 windows 上執行。 導致“command”進入目錄,但隨后“yourCommand”也在新終端中執行。 所以我用“command”指定的目錄更改沒有生效。 因此,“yourCommand”找不到該文件。
我讀到您可以更改終端的默認值以打開當前目錄而不是默認目錄,但這似乎是一個粗略的解決方案。
我想做的是在指定目錄上打開終端,然后在終端中運行“yourCommand”代碼。
TIA
只需使用&&
將命令連接成一個命令即可。
from applescript import tell
command = 'cd Downloads/"SSR Drive"'
yourCommand = "PERF -i "+str(x)+" -u CFG.txt"
tell.app( 'Terminal', 'do script "' + command + ' && ' + yourCommand + '"')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.