Last active
April 15, 2019 14:59
-
-
Save remorse/1d29281cbf5a075fa49aae7faf1a17a9 to your computer and use it in GitHub Desktop.
Perl 6 to toggle greyscale on macOS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi! I received a lot of help making this work from the Perl6 IRC chatroom, in particular from
timotimo
; and also fromugexe
on GitHub.