我想打开一个文件,等待下一条指令的执行,直到文件未关闭。我点击了链接“如何在python python中的mac OSX 10.8.2上打开文件”,但是它不起作用。
subprocess.call(['open','-W',FileName])
在texteditor中打开文件,但即使我关闭了打开的文件,也只有在强行退出文本编辑器时才执行next语句。意味着,它应该仅在文件关闭时才执行next语句,然后texteditor应该从dock中自动退出。
我也尝试过Popen,但是没有用
ss=subprocess.Popen("~/Downloads/DeletingDocs.txt",shell=True)
ss.communicate()
请提出一些方法
尝试将其保存为“ EditOneAndQuit”,然后执行以下操作:
chmod +x EditOneAndQuit
然后从Python开始:
#!/bin/bash
# Start textedit in background
open "$1" &
# Wait till textedit has zero documents open
while true
do
sleep 1
docs=`osascript -e 'tell application "textedit" to get documents'`
if [ -z "$docs" ]; then
# Kill off poor old textedit
osascript -e 'tell application "textedit" to quit'
exit
fi
done
首先通过创建文档并对其进行编辑,从shell中进行尝试:
ls > fred.txt
./OpenOneAndQuit fred.txt
您应该会看到,通过单击红色按钮关闭文档时,脚本以及textedit将退出。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句