本文将带您了解关于如何在Mac上的Python中列出所有工作区中的所有窗口?的新内容,同时我们还将为您解释如何在mac上的python中列出所有工作区中的所有窗口的相关知识,另外,我们还将为您提供关于
本文将带您了解关于如何在Mac上的Python中列出所有工作区中的所有窗口?的新内容,同时我们还将为您解释如何在mac上的python中列出所有工作区中的所有窗口的相关知识,另外,我们还将为您提供关于c# – 如何在.Net中列出堆中的所有托管对象?、c# – 如何枚举进程中的所有窗口?、macos – 列出所有应用程序的所有窗口、Python如何列出目录中的所有文件?的实用信息。
本文目录一览:- 如何在Mac上的Python中列出所有工作区中的所有窗口?(如何在mac上的python中列出所有工作区中的所有窗口)
- c# – 如何在.Net中列出堆中的所有托管对象?
- c# – 如何枚举进程中的所有窗口?
- macos – 列出所有应用程序的所有窗口
- Python如何列出目录中的所有文件?
如何在Mac上的Python中列出所有工作区中的所有窗口?(如何在mac上的python中列出所有工作区中的所有窗口)
以下Python 2代码打印当前工作区中所有窗口的列表:
#!/usr/bin/pythonimport Quartzfor window in Quartz.CGWindowListCopyWindowInfo(Quartz.kCGWindowListOptionOnScreenOnly, Quartz.kCGNullWindowID): print("%s - %s" % (window[''kCGWindowOwnerName''], window.get(''kCGWindowName'', u''Unknown'').encode(''ascii'',''ignore'')))
尽管它不会打印全屏显示的应用程序(因为它位于另一个工作区中)。
如何修改上述脚本以列出所有桌面上的所有窗口?
答案1
小编典典以下脚本应在任何桌面/工作区/显示器,全屏和详细信息(坐标,pid,标题等)上返回窗口信息:
#!/usr/bin/pythonimport Quartzimport timefrom Quartz import CGWindowListCopyWindowInfo, kCGWindowListExcludeDesktopElements, kCGNullWindowIDfrom Foundation import NSSet, NSMutableSetdef windowList(wl): for v in wl: print ( str(v.valueForKey_(''kCGWindowOwnerPID'') or ''?'').rjust(7) + '' '' + str(v.valueForKey_(''kCGWindowNumber'') or ''?'').rjust(5) + '' {'' + ('''' if v.valueForKey_(''kCGWindowBounds'') is None else ( str(int(v.valueForKey_(''kCGWindowBounds'').valueForKey_(''X''))) + '','' + str(int(v.valueForKey_(''kCGWindowBounds'').valueForKey_(''Y''))) + '','' + str(int(v.valueForKey_(''kCGWindowBounds'').valueForKey_(''Width''))) + '','' + str(int(v.valueForKey_(''kCGWindowBounds'').valueForKey_(''Height''))) ) ).ljust(21) + ''}'' + ''\t['' + ((v.valueForKey_(''kCGWindowOwnerName'') or '''') + '']'') + ('''' if v.valueForKey_(''kCGWindowName'') is None else ('' '' + v.valueForKey_(''kCGWindowName'') or '''')) ).encode(''utf8'') # remove ''encode'' for Python 3.xwl1 = CGWindowListCopyWindowInfo(kCGWindowListExcludeDesktopElements, kCGNullWindowID)print(''Move target window (or ignore)\n'')time.sleep(5)print(''PID''.rjust(7) + '' '' + ''WinID''.rjust(5) + '' '' + ''x,y,w,h''.ljust(21) + '' '' + ''\t[Title] SubTitle'')print(''-''.rjust(7,''-'') + '' '' + ''-''.rjust(5,''-'') + '' '' + ''-''.ljust(21,''-'') + '' '' + ''\t-------------------------------------------'')wl2 = CGWindowListCopyWindowInfo(kCGWindowListExcludeDesktopElements, kCGNullWindowID)w = NSMutableSet.setWithArray_(wl1)w.minusSet_(NSSet.setWithArray_(wl2))wl = Quartz.CGWindowListCopyWindowInfo( Quartz.kCGWindowListOptionAll, Quartz.kCGNullWindowID)wl = sorted(wl, key=lambda k: k.valueForKey_(''kCGWindowOwnerPID''))windowList(wl)print(''\nDetailed window information: {0}\n''.format(w))
c# – 如何在.Net中列出堆中的所有托管对象?
我想做这样的事情:
IEnumerable<GCHandle> listofObjectsInHeap = GetlistofObjectsFromHeap();
解决方法
c# – 如何枚举进程中的所有窗口?
我正在使用C#/ .NET
解决方法
macos – 列出所有应用程序的所有窗口
有趣的是,当我听到所有打开的应用程序的名称时,我的脚本说他们都打开了0个窗口.我该如何解决这个问题?
这是我的代码:
tell application "System Events" repeat with theProcess in (every process) if background only of theProcess is false then if name of theProcess is not "Finder" then if name of theProcess is "Google Chrome" then say "Chrome woo hoo" say (count windows as string) else say name of theProcess as string say (count windows as string) tell theProcess repeat with theWindow in windows say "found a window of" say (name of theProcess) as string tell theWindow click button 2 end tell end repeat end tell end if end if end if end repeat end tell
我使用的是Mac OS X 10.7.5,使用automator 2.2.4来编写/运行这个AppleScript
解决方法
你告诉过程要说出它的名字,例如“将theProcess的名称称为字符串”但是你只使用“说(将窗口计为字符串)”……没有任何过程与此相关联.尝试“计算过程的窗口”.基本上,你有时会告诉流程,有时你不会告诉流程,有时你告诉流程,即使你已经告诉过程,所以你要做两次.这就是你说“说(进程的名称)为字符串”,但该代码在“告诉进程”块中,因此它已被告知进程.
真的,你需要通过你的代码,更准确.提示…如果您想单击窗口中的按钮,则窗口必须位于屏幕的最前面,否则您无法单击它.另一个提示……“名称”已经是一个字符串,因此您不需要将其强制转换为字符串.
顺便说一句,我同意Michael Dautermann对你的帖子的评论……会有一些你无法访问的过程.但随着你的进步,你会发现它.
这是我编写代码的方式.基本上我会在开头使用“tell theProcess”块获取所有变量.然后我可以用这些变量做些事情.我希望有所帮助.请注意,我只是将过程放在最前面,这意味着如果打开多个窗口,它只会单击前窗上的按钮.在单击其按钮之前,您必须添加代码以使每个窗口都显示在前面.祝好运.
tell application "System Events" repeat with theProcess in processes if not background only of theProcess then tell theProcess set processName to name set theWindows to windows end tell set windowsCount to count of theWindows if processName is "Google Chrome" then say "Chrome woo hoo" say windowsCount as text else if processName is not "Finder" then say processName say windowsCount as text if windowsCount is greater than 0 then repeat with theWindow in theWindows say "found a window of " & processName tell theProcess set frontmost to true tell theWindow click button 2 end tell end tell end repeat end if end if end if end repeat end tell
Python如何列出目录中的所有文件?
在Python中,可以使用os.walker
或glob
创建一个类似于find()
的函数来搜索或列出指定目录中的文件或文件夹以及它的子目录。
1. os.walker
1.1. 列出指定目录+子目录中的所有.txt
文件。
import os
path = '/home/maxsu/hc2'
files = []
# r=root d=directories f = files
for r d f in os.walk(path):
for file in f:
if '.txt' in file:
files.append(os.path.join(r file))
for f in files:
print(f)
1.2. 列出指定目录+子目录中的所有目录。
import os
path = '/home/maxsu/projects/hc2/'
folders = []
# r=root, d=directories, f = files
for r, d, f in os.walk(path):
for folder in d:
folders.append(os.path.join(r, folder))
for f in folders:
print(f)
3. glob
在Python 3.5版中更改:使用**
支持递归globs
。
2.1. 列出指定目录中的所有.txt
文件+子目录(**
)。
import glob
path = '/home/maxsu/projects/hc2/'
files = [f for f in glob.glob(path + **/*.txt, recursive=True)]
for f in files:
print(f)
2.2. 列出指定目录中的所有目录+子目录(**
)。
import glob
folders = [f for f in glob.glob(path + **/, recursive=True)]
for f in folders:
print(f)
关于如何在Mac上的Python中列出所有工作区中的所有窗口?和如何在mac上的python中列出所有工作区中的所有窗口的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于c# – 如何在.Net中列出堆中的所有托管对象?、c# – 如何枚举进程中的所有窗口?、macos – 列出所有应用程序的所有窗口、Python如何列出目录中的所有文件?的相关知识,请在本站寻找。
本文标签: