我希望能够随时告诉用户当前在 macOS 10.13 上以编程方式使用的任务控制工作区。我在搜索过程中找不到任何有效的答案。任何语言都可以,任何工作区标识符都适合我(uuid,工作区编号......)
感谢您的帮助!
我希望能够随时告诉用户当前在 macOS 10.13 上以编程方式使用的任务控制工作区。我在搜索过程中找不到任何有效的答案。任何语言都可以,任何工作区标识符都适合我(uuid,工作区编号......)
感谢您的帮助!
Build Settings
并将该文件夹添加到User Header Search Paths
然后你可以这样做:
#import "AppDelegate.h"
#import "CGSInternal/CGSSpace.h"
@implementation AppDelegate
typedef int CGSConnection;
extern CGSConnection _CGSDefaultConnection(void);
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
CGSSpaceID activeSpace = CGSGetActiveSpace(_CGSDefaultConnection());
NSLog(@"activeSpace: %zu", activeSpace);
CFArrayRef spaceArray = CGSCopySpaces(_CGSDefaultConnection(), kCGSAllSpacesMask);
NSLog(@"allSpaces: %@", spaceArray);
}
@end
如果您想要一个“工作答案”,请使用间接 GUI“变量”来告诉您您在哪里:
(<= 更短但政治上不正确)tell application "System Events" to text items 27 thru -1 of item 1 of (picture of every desktop as list) as string
set delimOrgs to text item delimiters
set text item delimiters to {"/"}
tell application "System Events" to set BGpict to ¬
last text item of (picture of current desktop as text)
set text item delimiters to delimOrgs
return BGpict [improved: user3439894's suggestion]
…例如返回"Lion.jpg"
我的 4 个工作区之一,"Sierra.jpg"
另一个,这意味着我首先使用桌面 3,现在使用桌面 1。
看起来这需要未记录的 API 调用。
https://github.com/asmagill/hs._asm.undocumented.spaces/blob/master/CGSSpace.h
和
CG_EXTERN CGSSpaceID CGSGetActiveSpace(CGSConnectionID cid);
可能会做你想做的事,但是这段代码在 3 年内没有被触及,所以系统/api 可能已经迁移,并且使用未记录的 API 的所有问题都适用。
在项目中找到这个https://github.com/asmagill/hs._asm.undocumented.spaces
没有使用或验证过。