明白了。感謝您提供了有用的AppleScript見解,幫助您找到了這個解決方案Zero。在from subprocess import Popen, PIPE, check_output, STDOUT
def runAppleScript(script):
"Returns the result of running string in osascript (Applescript)"
if hasattr(script, "encode"): #Assumes Python 3
script = script.encode("utf-8")
python正則替換。osa = Popen(["osascript", "-"], stdout=PIPE, stdin=PIPE, stderr=PIPE)
results, err = osa.communicate(script)
if err:
raise Exception(err)
return results.decode("utf-8")
def runBash(command):
python argv。output = check_output(command, stderr=STDOUT, shell=True)
return output
def getCurrentTerminalTTYS():
script = '''
tell application "Terminal"
return (tty of selected tab of front window)
python import函數?end tell
'''
result = runAppleScript(script)
return result.strip()
def getPathForTTYS(ttys):
lsof = runBash('lsof').split('\n')
python獲取當前路徑的文件夾、process = None
for line in lsof:
if ttys in line:
process = line.split()[1]
break
path = None
python獲取當前目錄。for line in lsof:
if 'cwd' in line and process in line:
path = ' '.join(line.split()[8:])
break
return path
def getCurrentTerminalPath():
python hist。ttys = getCurrentTerminalTTYS()
return getPathForTTYS(ttys)
它可以存儲為字符串,使用
^{pr2}$
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态