Skip to content

Commit

Permalink
#108 add command to check if the latest scripting-addition version is…
Browse files Browse the repository at this point in the history
… installed
  • Loading branch information
koekeishiya committed Jul 12, 2019
1 parent a14550c commit ff52bad
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 8 deletions.
11 changes: 8 additions & 3 deletions doc/yabai.1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
5 changes: 4 additions & 1 deletion doc/yabai.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----------
Expand All @@ -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.

Expand Down
1 change: 1 addition & 0 deletions src/osax/sa.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
24 changes: 20 additions & 4 deletions src/osax/sa.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ - (void) eventDidFail:(const AppleEvent*)event withError:(NSError*)error
"<key>CFBundlePackageType</key>\n"
"<string>osax</string>\n"
"<key>CFBundleShortVersionString</key>\n"
"<string>1.0.1</string>\n"
"<string>"OSAX_VERSION"</string>\n"
"<key>CFBundleVersion</key>\n"
"<string>1.0.1</string>\n"
"<string>"OSAX_VERSION"</string>\n"
"<key>NSHumanReadableCopyright</key>\n"
"<string>Copyright © 2019 Åsmund Vikane. All rights reserved.</string>\n"
"<key>OSAScriptingDefinition</key>\n"
Expand Down Expand Up @@ -97,9 +97,9 @@ - (void) eventDidFail:(const AppleEvent*)event withError:(NSError*)error
"<key>CFBundlePackageType</key>\n"
"<string>BNDL</string>\n"
"<key>CFBundleShortVersionString</key>\n"
"<string>1.0.1</string>\n"
"<string>"OSAX_VERSION"</string>\n"
"<key>CFBundleVersion</key>\n"
"<string>1.0.1</string>\n"
"<string>"OSAX_VERSION"</string>\n"
"<key>NSHumanReadableCopyright</key>\n"
"<string>Copyright © 2019 Åsmund Vikane. All rights reserved.</string>\n"
"<key>NSPrincipalClass</key>\n"
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions src/yabai.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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());
}
Expand Down

0 comments on commit ff52bad

Please sign in to comment.