Zie*_*eng 6 macos objective-c macos-high-sierra
我想在我的应用程序中获取当前工作区。我从valexa 的回答中找到了实现目标的方法:
-(int)spaceNumber
{
CFArrayRef windowsInSpace = CGWindowListCopyWindowInfo(kCGWindowListOptionAll | kCGWindowListOptionOnScreenOnly, kCGNullWindowID);
for (NSMutableDictionary *thisWindow in (NSArray *)windowsInSpace) {
if ([thisWindow objectForKey:(id)kCGWindowWorkspace]){
return [[thisWindow objectForKey:(id)kCGWindowWorkspace] intValue];
}
}
return -1;
}
Run Code Online (Sandbox Code Playgroud)
但是现在(对于我的情况 是macOS 10.13.3)kCGWindowWorkspace不再存在。那么还有其他方法可以实现我的目标吗?
提前致谢!
GitHub 实用程序 WhichSpace [github.com/gechr/WhichSpace] 将在工具栏中放置一个数字图标,指示哪个桌面编号是当前空间。可以使用 Applescript 进行查询:
\ntell application "System Events" \xc2\xac\n to tell process "WhichSpace" \xc2\xac\n to set temp to (title of menu bar items of menu bar 1)\nreturn item 1 of temp\nRun Code Online (Sandbox Code Playgroud)\n以下 Swift 代码将在桌面更改时调用一个函数。这也可能有用。
\ntell application "System Events" \xc2\xac\n to tell process "WhichSpace" \xc2\xac\n to set temp to (title of menu bar items of menu bar 1)\nreturn item 1 of temp\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
121 次 |
| 最近记录: |