Skip to content

Instantly share code, notes, and snippets.

@remorse
Last active April 15, 2019 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save remorse/1d29281cbf5a075fa49aae7faf1a17a9 to your computer and use it in GitHub Desktop.
Save remorse/1d29281cbf5a075fa49aae7faf1a17a9 to your computer and use it in GitHub Desktop.
Perl 6 to toggle greyscale on macOS
#!/usr/bin/env perl6
# see <https://indiestack.com/2019/04/toggle-system-grayscale-mode/> for the background on this.
use v6;
use NativeCall;
sub UALib { "/System/Library/PrivateFrameworks/UniversalAccess.framework/UniversalAccess" }
sub UAGrayscaleIsEnabled returns int32 is native(&UALib) { * }
sub UAGrayscaleSetEnabled (int32 $status) is native(&UALib) { * }
UAGrayscaleSetEnabled(UAGrayscaleIsEnabled() == 0);
say UAGrayscaleIsEnabled() ?? "Grayscale now enabled" !! "Colors now enabled";
@remorse
Copy link
Author

remorse commented Apr 15, 2019

Hi! I received a lot of help making this work from the Perl6 IRC chatroom, in particular from timotimo; and also from ugexe on GitHub.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment