sindresorhus / Actions

⚙️ Supercharge your shortcuts
https://sindresorhus.com/actions
MIT License
2.55k stars 107 forks source link

Action proposal: IsGrayscaleEnabled #163

Closed msubb closed 10 months ago

msubb commented 10 months ago

Description

I think it would be valuable to be able to detect if grayscale is enabled on the device.

I tried to add it myself but was unable to figure out how to implement it.

I put this at the bottom of the enum Device {

    /**
     If grayscale is enabled on the device, Boaz code
     */
    static var isGrayscaleEnabled: Bool {
        UIAccessibility.isGrayscaleEnabled
    }
}

I also added this code to Intents Extension/Actions/

import AppIntents

struct IsGrayscaleEnabled: AppIntent, CustomIntentMigratedAppIntent {
    static let intentClassName = "IsGrayscaleOnIntent"
    static let title: LocalizedStringResource = "Is Grayscale On"
    static let description = IntentDescription(
"""
Returns whether Grayscale is on or off.
""",
categoryName: "Device"
    )
    func perform() async throws -> some IntentResult & ReturnsValue<Bool> {
        .result(
            value: Device.isGrayscaleEnabled
        )
    }
}

I'm not sure what I am doing wrong, the extension showed up in the shortcuts app but didn't seem to actually be detecting the state of grayscale.

sindresorhus commented 10 months ago

It probably has to run in the main app, not the intents extension. I added it. Will be available in the next update.

Boaztheostrich commented 10 months ago

Awesome thank you! I’m excited to use it in future shortcuts. If you don’t mind me asking do you know when the next update will be released?

sindresorhus commented 10 months ago

Not soon. Every update requires some users to restart their device (because of a dumb iOS bug), so I try not to release updates too often.

msubb commented 10 months ago

Gotcha, I implemented the fix you mentioned moving the code I wrote from Intents Extension/Actions/ To Shared Actions

image

Testing it on my Iphone 13 Mini it appears that the shortcut just always returns yes. Looking at the pictures I uploaded it looks like I had grayscale disabled in both but I guess it is just not captured by IOS screenshots.

IMG_2567 Gray Scale ON IMG_2566 Shortcut Logic IMG_2565 Gray Scale OFF

sindresorhus commented 10 months ago

The action I added works on my device (iOS 17). Try the code from the main branch instead of your changes.