Вы хотите разделение, от модуль shlex .
>>> import shlex
>>> shlex.split('this is "a test"')
['this', 'is', 'a test']
Это должно сделать точно, что Вы хотите.
Несколько потенциально полезных ссылок:
NSWindowList ()
-launchedApplications
и + runningApplications
CGWindowListCreate ()
и CGWindowListCopyWindowInfo ()
(требуется 10,5) CGSGetWindowProperty ()
CGSGetWindowProperty
официально не документировано , но я считаю, что вы можете использовать его с элементом NSWindowList ()
следующим образом (полностью непроверено):
OSErr err;
CGSValue titleValue;
char *title;
CGSConnection connection = _CGSDefaultConnection();
int windowCount, *windows, i;
NSCountWindows(&windowCount);
windows = malloc(windowCount * sizeof(*windows));
if (windows) {
NSWindowList(windowCount, windows);
for (i=0; i < windowCount; ++i) {
err = CGSGetWindowProperty(connection, windows[i],
CGSCreateCStringNoCopy("kCGSWindowTitle"),
&titleValue);
title = CGSCStringValue(titleValue);
}
free(windows);
}
В AppleScript это действительно просто:
tell application "System Events" to get the title of every window of every process
Вы можете вызвать applescript из приложения с помощью NSAppleScript или использовать appscript как мост ObjC-AppleScript. С Leopard вы можете использовать Scripting Bridge (более непроверенный код):
SystemEventsApplication *systemEvents = [SBApplication applicationWithBundleIdentifier:@"com.apple.systemevents"];
SBElementArray *processes = [systemEvents processes];
for (SystemEventsProcess* process in processes) {
NSArray *titles = [[process windows] arrayByApplyingSelector:@selector(title)];
}
Вы можете даже попробовать его за один длинный вызов, если вас не волнует удобочитаемость.
SystemEventsApplication *systemEvents = [SBApplication applicationWithBundleIdentifier:@"com.apple.systemevents"];
NSArray *titles = [[[systemEvents processes]
arrayByApplyingSelector:@selector(windows)]
arrayByApplyingSelector:@selector(arrayByApplyingSelector:)
withObject:@selector(title)];
Компилятор будет жаловаться, что @selector (title)
- неправильный тип, но он должен работать. Выполните ручную проверку делегирования, и вы сможете превратить вызов в [[[systemEventscesses] windows] title]
.