From 6491eb8084253b3c7ec6c99c3b6f0e458aa26b1d Mon Sep 17 00:00:00 2001 From: Andrew Zellman Date: Mon, 23 May 2016 12:34:03 -0700 Subject: [PATCH] Show Enabled/Disabled in command line --list --- DisableMonitor-Info.plist | 2 +- DisableMonitor.xcodeproj/project.pbxproj | 11 ++++++----- .../xcschemes/DisableMonitor.xcscheme | 19 ++++++++++++------- MonitorDataSource.m | 7 +++++-- main.m | 2 +- 5 files changed, 25 insertions(+), 16 deletions(-) diff --git a/DisableMonitor-Info.plist b/DisableMonitor-Info.plist index e96e99d..f444546 100644 --- a/DisableMonitor-Info.plist +++ b/DisableMonitor-Info.plist @@ -9,7 +9,7 @@ CFBundleIconFile icon CFBundleIdentifier - eun.${PRODUCT_NAME:rfc1034identifier} + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/DisableMonitor.xcodeproj/project.pbxproj b/DisableMonitor.xcodeproj/project.pbxproj index e08b7b1..2e792c5 100644 --- a/DisableMonitor.xcodeproj/project.pbxproj +++ b/DisableMonitor.xcodeproj/project.pbxproj @@ -777,7 +777,7 @@ 29B97313FDCFA39411CA2CEA /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0510; + LastUpgradeCheck = 0730; }; buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "DisableMonitor" */; compatibilityVersion = "Xcode 3.2"; @@ -866,8 +866,8 @@ GCC_PREPROCESSOR_DEFINITIONS = ""; INFOPLIST_FILE = "DisableMonitor-Info.plist"; INSTALL_PATH = "$(HOME)/Applications"; + PRODUCT_BUNDLE_IDENTIFIER = "eun.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = DisableMonitor; - SDKROOT = macosx10.6; }; name = Debug; }; @@ -890,8 +890,8 @@ GCC_PREPROCESSOR_DEFINITIONS = ""; INFOPLIST_FILE = "DisableMonitor-Info.plist"; INSTALL_PATH = "$(HOME)/Applications"; + PRODUCT_BUNDLE_IDENTIFIER = "eun.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = DisableMonitor; - SDKROOT = macosx10.6; }; name = Release; }; @@ -899,13 +899,14 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_LINK_OBJC_RUNTIME = NO; + ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_OPTIMIZATION_LEVEL = 0; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; ONLY_ACTIVE_ARCH = YES; PREBINDING = NO; - SDKROOT = macosx10.6; + SDKROOT = macosx; }; name = Debug; }; @@ -917,7 +918,7 @@ GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; PREBINDING = NO; - SDKROOT = macosx10.6; + SDKROOT = macosx; }; name = Release; }; diff --git a/DisableMonitor.xcodeproj/xcshareddata/xcschemes/DisableMonitor.xcscheme b/DisableMonitor.xcodeproj/xcshareddata/xcschemes/DisableMonitor.xcscheme index 0602ffa..62dd1e1 100644 --- a/DisableMonitor.xcodeproj/xcshareddata/xcschemes/DisableMonitor.xcscheme +++ b/DisableMonitor.xcodeproj/xcshareddata/xcschemes/DisableMonitor.xcscheme @@ -1,6 +1,6 @@ + shouldUseLaunchSchemeArgsEnv = "YES"> @@ -38,17 +38,21 @@ ReferencedContainer = "container:DisableMonitor.xcodeproj"> + + - + - + . * * Authors: Tobias Salzmann */ #import #import "MonitorDataSource.h" #import "DisableMonitorAppDelegate.h" #import "DisplayIDAndName.h" int cmd_list(NSString* arg) { NSMutableArray *dict = [MonitorDataSource GetSortedDisplays]; if (dict == nil) { printf("No Displays found"); } else { printf(" ID Name\n"); printf("----------- -----------------\n"); for (DisplayIDAndName* idAndName in dict) { printf(" %-10u %s\n", [idAndName id], [[idAndName name] UTF8String]); } printf("----------- -----------------\n"); [dict release]; } return 0; } int cmd_disable(NSString *arg) { if ([arg length] < 2) return 1; CGDisplayCount nDisplays = 0; CGDirectDisplayID displayList[0x10]; CGDisplayErr err = CGSGetDisplayList(0x10, displayList, &nDisplays); CGDirectDisplayID displayID = [[NSUserDefaults standardUserDefaults] integerForKey:[arg substringFromIndex:1]]; if (err == 0 && nDisplays > 0) { for (int i = 0; i < nDisplays; i++) { if (displayList[i] == displayID) { if (CGDisplayIsOnline(displayID) && CGDisplayIsActive(displayID)) { [DisableMonitorAppDelegate toggleMonitor:displayID enabled:NO]; return 0; } } } } printf("Could not find display %u!\n", displayID); return 1; } int cmd_enable(NSString *arg) { if ([arg length] < 2) return 1; CGDisplayCount nDisplays = 0; CGDirectDisplayID displayList[0x10]; CGDisplayErr err = CGSGetDisplayList(0x10, displayList, &nDisplays); CGDirectDisplayID displayID = [[NSUserDefaults standardUserDefaults] integerForKey:[arg substringFromIndex:1]]; if (err == 0 && nDisplays > 0) { for (int i = 0; i < nDisplays; i++) { if (displayList[i] == displayID) { if (CGDisplayIsOnline(displayID) && !CGDisplayIsActive(displayID)) { [DisableMonitorAppDelegate toggleMonitor:displayID enabled:YES]; return 0; } } } } printf("Could not find display %u!\n", displayID); return 1; } int cmd_help(NSString *arg) { printf( "usage: DisableMonitor [options]\n" \ "Options:\n" \ "-l, --list list all attached monitors\n" \ "-d, --disable ID disable monitor with specified id\n" \ "-e, --enable ID enable monitor with specified id\n" \ "-h, --help show this help\n"); return 0; } int main(int argc, char *argv[]) { NSArray *arguments = [[NSProcessInfo processInfo] arguments]; for (NSString* arg in arguments) { if ([arg caseInsensitiveCompare:@"--list"] == NSOrderedSame || [arg caseInsensitiveCompare:@"-list"] == NSOrderedSame || [arg caseInsensitiveCompare:@"-l"] == NSOrderedSame) { return cmd_list(arg); return 0; } else if ([arg caseInsensitiveCompare:@"--disable"] == NSOrderedSame || [arg caseInsensitiveCompare:@"-disable"] == NSOrderedSame || [arg caseInsensitiveCompare:@"-d"] == NSOrderedSame) { return cmd_disable(arg); } else if ([arg caseInsensitiveCompare:@"--enable"] == NSOrderedSame || [arg caseInsensitiveCompare:@"-enable"] == NSOrderedSame || [arg caseInsensitiveCompare:@"-e"] == NSOrderedSame) { return cmd_enable(arg); } else if ([arg caseInsensitiveCompare:@"--help"] == NSOrderedSame || [arg caseInsensitiveCompare:@"-help"] == NSOrderedSame || [arg caseInsensitiveCompare:@"-h"] == NSOrderedSame) { return cmd_help(arg); } } return NSApplicationMain(argc, (const char **) argv); } \ No newline at end of file +/** * DisableMonitor, Disable Monitors on Mac * * Copyright (C) 2014 Tobias Salzmann * * DisableMonitor is free software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, either version 2 of the * License, or (at your option) any later version. * * DisableMonitor is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * See the GNU General Public License for more details. You should have received a copy of the GNU * General Public License along with DisableMonitor. If not, see . * * Authors: Tobias Salzmann */ #import #import "MonitorDataSource.h" #import "DisableMonitorAppDelegate.h" #import "DisplayIDAndNameCondition.h" int cmd_list(NSString* arg) { NSMutableArray *dict = [MonitorDataSource GetSortedDisplays]; if (dict == nil) { printf("No Displays found"); } else { printf(" ID Name Enabled\n"); printf("----------- ----------------- -------\n"); for (DisplayIDAndNameCondition* idAndName in dict) { printf(" %-10u %-17s %s\n", [idAndName id], [[idAndName name] UTF8String], [(DisplayIDAndNameCondition*)idAndName enabled] ? "YES" : "NO"); } printf("----------- ----------------- -------\n"); [dict release]; } return 0; } int cmd_disable(NSString *arg) { if ([arg length] < 2) return 1; CGDisplayCount nDisplays = 0; CGDirectDisplayID displayList[0x10]; CGDisplayErr err = CGSGetDisplayList(0x10, displayList, &nDisplays); CGDirectDisplayID displayID = [[NSUserDefaults standardUserDefaults] integerForKey:[arg substringFromIndex:1]]; if (err == 0 && nDisplays > 0) { for (int i = 0; i < nDisplays; i++) { if (displayList[i] == displayID) { if (CGDisplayIsOnline(displayID) && CGDisplayIsActive(displayID)) { [DisableMonitorAppDelegate toggleMonitor:displayID enabled:NO]; return 0; } } } } printf("Could not find display %u!\n", displayID); return 1; } int cmd_enable(NSString *arg) { if ([arg length] < 2) return 1; CGDisplayCount nDisplays = 0; CGDirectDisplayID displayList[0x10]; CGDisplayErr err = CGSGetDisplayList(0x10, displayList, &nDisplays); CGDirectDisplayID displayID = [[NSUserDefaults standardUserDefaults] integerForKey:[arg substringFromIndex:1]]; if (err == 0 && nDisplays > 0) { for (int i = 0; i < nDisplays; i++) { if (displayList[i] == displayID) { if (CGDisplayIsOnline(displayID) && !CGDisplayIsActive(displayID)) { [DisableMonitorAppDelegate toggleMonitor:displayID enabled:YES]; return 0; } } } } printf("Could not find display %u!\n", displayID); return 1; } int cmd_help(NSString *arg) { printf( "usage: DisableMonitor [options]\n" \ "Options:\n" \ "-l, --list list all attached monitors\n" \ "-d, --disable ID disable monitor with specified id\n" \ "-e, --enable ID enable monitor with specified id\n" \ "-h, --help show this help\n"); return 0; } int main(int argc, char *argv[]) { NSArray *arguments = [[NSProcessInfo processInfo] arguments]; for (NSString* arg in arguments) { if ([arg caseInsensitiveCompare:@"--list"] == NSOrderedSame || [arg caseInsensitiveCompare:@"-list"] == NSOrderedSame || [arg caseInsensitiveCompare:@"-l"] == NSOrderedSame) { return cmd_list(arg); return 0; } else if ([arg caseInsensitiveCompare:@"--disable"] == NSOrderedSame || [arg caseInsensitiveCompare:@"-disable"] == NSOrderedSame || [arg caseInsensitiveCompare:@"-d"] == NSOrderedSame) { return cmd_disable(arg); } else if ([arg caseInsensitiveCompare:@"--enable"] == NSOrderedSame || [arg caseInsensitiveCompare:@"-enable"] == NSOrderedSame || [arg caseInsensitiveCompare:@"-e"] == NSOrderedSame) { return cmd_enable(arg); } else if ([arg caseInsensitiveCompare:@"--help"] == NSOrderedSame || [arg caseInsensitiveCompare:@"-help"] == NSOrderedSame || [arg caseInsensitiveCompare:@"-h"] == NSOrderedSame) { return cmd_help(arg); } } return NSApplicationMain(argc, (const char **) argv); } \ No newline at end of file