0
psutilモジュールを使用して、実行中のアプリケーションのリストを取得します。そこから、それらのアプリケーションのオープン '.plist'ファイルをチェックします。次に、'plist 'ファイルを読み込んで、アプリケーションで現在開いているドキュメントのタイトル(' NSTitle ')を取得します。OSX(python)のアプリケーションで公開されている文書の名前を取得
この同じタスクを達成するためのより良い/最適化された方法はありますか?
import psutil
import os
import plistlib
def check_files(application):
plist_original_path = ""
while True:
for i in psutil.process_iter():
try:
if application in i.name():
for j in i.open_files():
if ".plist" in j.path:
plist_original_path = j.path
except psutil.ZombieProcess:
continue
except psutil.NoSuchProcess:
continue
try:
with open(plist_original_path, 'rb') as plist:
read_plist = plistlib.load(plist)
for i in read_plist:
try:
title = i["NSTitle"]
print(title)
except:
pass
except FileNotFoundError:
pass
check_files("Excel")