Instale scriptisto
par
- Installation de Homebrew
- Installation de la cargaison avec
brew install --cask cargo
- Running
cargo install scriptisto
Vous devez également avoir installé les outils Xcode CLI ( xcode-select --install
).
Ensuite, sauvegardez ce qui suit comme gray_darwin.c
et le rendre exécutable ( chmod +x gray_darwin.c
).
#!/usr/bin/env scriptisto
// Self-contained, has no dependencies except Xcode CLI.
// scriptisto-begin
// script_src: main.c
// build_cmd: clang -g -O2 -std=c11 -Wall -framework ApplicationServices main.c -o ./script
// scriptisto-end
#include <stdio.h>
#include <ApplicationServices/ApplicationServices.h>
CG_EXTERN bool CGDisplayUsesForceToGray(void);
CG_EXTERN void CGDisplayForceToGray(bool forceToGray);
int main(int argc, char** argv)
{
bool isGrayscale;
if (argc > 1) {
if (argv[1][0] == 'y') {
isGrayscale = false; // will toggle this to true
} else if (argv[1][0] == 's') {
printf("Grayscale is now: %d\n", CGDisplayUsesForceToGray());
return 0;
}
else {
isGrayscale = true;
}
} else {
isGrayscale = CGDisplayUsesForceToGray();
printf("isGrayscale = %d\n", isGrayscale);
}
CGDisplayForceToGray(!isGrayscale);
printf("Grayscale is now: %d\n", CGDisplayUsesForceToGray());
return 0;
}
Maintenant vous pouvez l'utiliser comme ça :
function display-gray-is() {
[[ "$(gray_darwin.c s)" == "Grayscale is now: 1" ]]
}
function display-gray-toggle() {
gray_darwin.c
}
function display-gray-off() {
gray_darwin.c n
}
function display-gray-on() {
gray_darwin.c y
}