python正則替換,python查找當前路徑,在Python中查找當前終端選項卡的當前目錄

 2023-11-12 阅读 30 评论 0

摘要:明白了。感謝您提供了有用的AppleScript見解,幫助您找到了這個解決方案Zero。在from subprocess import Popen, PIPE, check_output, STDOUTdef runAppleScript(script):"Returns the result of running string in osascript (Applescript)"if hasattr(script,

明白了。感謝您提供了有用的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}$

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/4/172371.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息