【问题标题】:Change macOS display arrangement through command line / applescript?通过命令行/applescript 更改 macOS 显示排列?
【发布时间】:2018-11-19 08:12:25
【问题描述】:

我有一个 3 显示器设置在工作中,顺序如下(从左到右):

  • MB Pro Retina 15" / 内部
  • 联想 23" / 外置
  • 联想 23" / 外置

macOS 版本:10.13.6

很可能当我重新启动时,订单消失了,我必须通过System Preferences -> Display -> Arrangement重置它

有没有办法通过命令行或者applescript来改变排列方式?

【问题讨论】:

  • 我相信 AppleScriptObjC/JXA 可以做到这一点,但由于我只有一个显示器,所以我无法测试。
  • 这看起来很有希望...apple.stackexchange.com/q/249447

标签: macos command-line applescript display


【解决方案1】:

我厌倦了同样的问题,并设法减少 Mark Setchell 链接中提到的“displayPlacer”,以解决这个特殊问题:

#include <IOKit/graphics/IOGraphicsLib.h>
#include <ApplicationServices/ApplicationServices.h>
#include <unistd.h>
#include <math.h>
#include <stdio.h>

int main(int argc, const char * argv[]) {

    CGDirectDisplayID screenList[3];
    CGDirectDisplayID external1;
    CGDirectDisplayID external2;
    CGGetOnlineDisplayList(INT_MAX, screenList, NULL);

    if(CGDisplayIsMain(screenList[0])){
        external1 = screenList[1];
        external2 = screenList[2];
    }else if(CGDisplayIsMain(screenList[1])){
        external1 = screenList[0];
        external2 = screenList[2];
    }else{
        external1 = screenList[1];
        external2 = screenList[2];
    }


    CGDisplayConfigRef configRef;
    CGBeginDisplayConfiguration(&configRef);

    CGConfigureDisplayOrigin(configRef, external1, CGDisplayBounds(external2).origin.x, CGDisplayBounds(external2).origin.y);
    CGConfigureDisplayOrigin(configRef, external2, CGDisplayBounds(external1).origin.x, CGDisplayBounds(external1).origin.y);
    
    CGCompleteDisplayConfiguration(configRef, kCGConfigurePermanently);
}

我的 C 生锈了,可能不是很干净......它只是找到了 2 个外部屏幕并反转它们的位置。如果您在两个设置之间进行更改,则制作预配置的多个位置并不难。它在 C 中,但可以完成工作。

【讨论】:

  • 你有一个 gcc/clang 单线器来配合这个美妙的小 sn-p 吗?
  • 对不起,我没有,我什至不记得编码了。当我读到它时,我发现'mainScreen detection'条件external1 = screenList [1]中的最后一个else可能存在错误;外部2 =屏幕列表[2]; //应该是screenList[0];我认为
  • clang -o swap -f CoreGraphics swap.c 可能工作得很好
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-27
  • 1970-01-01
  • 2013-09-11
  • 1970-01-01
相关资源
最近更新 更多