From ff52bad137298edcbb5a7ea54801579ffbb47a2b Mon Sep 17 00:00:00 2001 From: koekeishiya Date: Fri, 12 Jul 2019 14:24:16 +0200 Subject: [PATCH] #108 add command to check if the latest scripting-addition version is installed --- doc/yabai.1 | 11 ++++++++--- doc/yabai.asciidoc | 5 ++++- src/osax/sa.h | 1 + src/osax/sa.m | 24 ++++++++++++++++++++---- src/yabai.c | 5 +++++ 5 files changed, 38 insertions(+), 8 deletions(-) diff --git a/doc/yabai.1 b/doc/yabai.1 index 8676ef6a..2be6f084 100644 --- a/doc/yabai.1 +++ b/doc/yabai.1 @@ -2,12 +2,12 @@ .\" Title: yabai .\" Author: [see the "AUTHOR(S)" section] .\" Generator: Asciidoctor 2.0.6 -.\" Date: 2019-07-11 +.\" Date: 2019-07-12 .\" Manual: Yabai Manual .\" Source: Yabai .\" Language: English .\" -.TH "YABAI" "1" "2019-07-11" "Yabai" "Yabai Manual" +.TH "YABAI" "1" "2019-07-12" "Yabai" "Yabai Manual" .ie \n(.g .ds Aq \(aq .el .ds Aq ' .ss \n[.ss] 0 @@ -32,7 +32,7 @@ yabai .SH "SYNOPSIS" .sp -\fByabai\fP [\fB\-v\fP,\fB\-\-version\fP|\fB\-V\fP,\fB\-\-verbose\fP|\fB\-m\fP,\fB\-\-message\fP \fImsg\fP|\fB\-c\fP,\fB\-\-config\fP \fIconfig_file\fP|\fB\-\-install\-sa\fP|\fB\-\-uninstall\-sa\fP|\fB\-\-load\-sa\fP] +\fByabai\fP [\fB\-v\fP,\fB\-\-version\fP|\fB\-V\fP,\fB\-\-verbose\fP|\fB\-m\fP,\fB\-\-message\fP \fImsg\fP|\fB\-c\fP,\fB\-\-config\fP \fIconfig_file\fP|\fB\-\-install\-sa\fP|\fB\-\-uninstall\-sa\fP|\fB\-\-check\-sa\fP|\fB\-\-load\-sa\fP] .SH "DESCRIPTION" .sp \fByabai\fP is a tiling window manager for macOS based on binary space partitioning. @@ -68,6 +68,11 @@ Install scripting\-addition. Must be ran as root. Path is /System/Library/Script Uninstall scripting\-addition. Must be ran as root. Path is /System/Library/ScriptingAdditions on macOS High Sierra, and /Library/ScriptingAdditions on Mojave and newer. .RE .sp +\fB\-\-check\-sa\fP +.RS 4 +Returns zero if the latest version of the scripting\-addition is installed. +.RE +.sp \fB\-\-load\-sa\fP .RS 4 Loads the scripting\-addition into Dock.app. diff --git a/doc/yabai.asciidoc b/doc/yabai.asciidoc index 3b9befd6..d2fd2833 100644 --- a/doc/yabai.asciidoc +++ b/doc/yabai.asciidoc @@ -24,7 +24,7 @@ yabai Synopsis -------- -*yabai* [*-v*,*--version*|*-V*,*--verbose*|*-m*,*--message* 'msg'|*-c*,*--config* 'config_file'|*--install-sa*|*--uninstall-sa*|*--load-sa*] +*yabai* [*-v*,*--version*|*-V*,*--verbose*|*-m*,*--message* 'msg'|*-c*,*--config* 'config_file'|*--install-sa*|*--uninstall-sa*|*--check-sa*|*--load-sa*] Description ----------- @@ -51,6 +51,9 @@ Options *--uninstall-sa*:: Uninstall scripting-addition. Must be ran as root. Path is /System/Library/ScriptingAdditions on macOS High Sierra, and /Library/ScriptingAdditions on Mojave and newer. +*--check-sa*:: + Returns zero if the latest version of the scripting-addition is installed. + *--load-sa*:: Loads the scripting-addition into Dock.app. diff --git a/src/osax/sa.h b/src/osax/sa.h index ce338b2b..153dd892 100644 --- a/src/osax/sa.h +++ b/src/osax/sa.h @@ -8,6 +8,7 @@ #define PAYLOAD_STATUS_NO_ATTRIB 2 #define PAYLOAD_STATUS_CON_ERROR 3 +int scripting_addition_check(void); int scripting_addition_load(void); bool scripting_addition_is_installed(void); int scripting_addition_uninstall(void); diff --git a/src/osax/sa.m b/src/osax/sa.m index eb692f0b..8addc2fc 100644 --- a/src/osax/sa.m +++ b/src/osax/sa.m @@ -54,9 +54,9 @@ - (void) eventDidFail:(const AppleEvent*)event withError:(NSError*)error "CFBundlePackageType\n" "osax\n" "CFBundleShortVersionString\n" - "1.0.1\n" + ""OSAX_VERSION"\n" "CFBundleVersion\n" - "1.0.1\n" + ""OSAX_VERSION"\n" "NSHumanReadableCopyright\n" "Copyright © 2019 Åsmund Vikane. All rights reserved.\n" "OSAScriptingDefinition\n" @@ -97,9 +97,9 @@ - (void) eventDidFail:(const AppleEvent*)event withError:(NSError*)error "CFBundlePackageType\n" "BNDL\n" "CFBundleShortVersionString\n" - "1.0.1\n" + ""OSAX_VERSION"\n" "CFBundleVersion\n" - "1.0.1\n" + ""OSAX_VERSION"\n" "NSHumanReadableCopyright\n" "Copyright © 2019 Åsmund Vikane. All rights reserved.\n" "NSPrincipalClass\n" @@ -309,6 +309,22 @@ int scripting_addition_uninstall(void) return 0; } +int scripting_addition_check(void) +{ + @autoreleasepool { + + if (!scripting_addition_is_installed()) return 1; + + NSString *payload_path = [NSString stringWithUTF8String:osax_payload_dir]; + NSBundle *payload_bundle = [NSBundle bundleWithPath:payload_path]; + NSString *ns_version = [payload_bundle objectForInfoDictionaryKey:@"CFBundleVersion"]; + + bool status = string_equals([ns_version UTF8String], OSAX_VERSION); + return status ? 0 : 1; + + } +} + int scripting_addition_load(void) { @autoreleasepool { diff --git a/src/yabai.c b/src/yabai.c index 08ff671c..17b9fd47 100644 --- a/src/yabai.c +++ b/src/yabai.c @@ -16,6 +16,7 @@ #define SCRPT_ADD_INSTALL_OPT "--install-sa" #define SCRPT_ADD_UNINSTALL_OPT "--uninstall-sa" +#define SCRPT_ADD_CHECK_OPT "--check-sa" #define SCRPT_ADD_LOAD_OPT "--load-sa" #define MAJOR 1 @@ -209,6 +210,10 @@ static void parse_arguments(int argc, char **argv) exit(scripting_addition_uninstall()); } + if (string_equals(argv[1], SCRPT_ADD_CHECK_OPT)) { + exit(scripting_addition_check()); + } + if (string_equals(argv[1], SCRPT_ADD_LOAD_OPT)) { exit(scripting_addition_load()); }