Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toggle on and off via AppleScript #43

Open
drewbarontini opened this issue Jan 8, 2016 · 11 comments
Open

Toggle on and off via AppleScript #43

drewbarontini opened this issue Jan 8, 2016 · 11 comments

Comments

@drewbarontini
Copy link

Hello!

Previously, with Caffeine, I was able to use the following AppleScript to toggle it on and off via the keyboard:

tell application "System Events"
    if exists (process "Caffeine") then
        tell application "Caffeine"
            if active is false then
                turn on
            else
                turn off
            end if
        end tell
    else
        tell application "Caffeine" to activate
    end if
end tell

When trying that with this application (subbing "Caffeine" with "KeepingYouAwake"), it doesn't work. Using the Script Editor application, it seems that the active variable is not present. As far as I can tell, there aren't any available actions when using the Script Editor Dictionary, but I thought I'd confirm here.

@newmarcel
Copy link
Owner

You are right, I should probably integrate some scripting definitions to be a good Cocoa and AppleScript citizen.

I'll do some research if it is easily possible to ship basic AppleScript support in the next release. I'll report any findings here.

Thanks for reminding me 😀

@drewbarontini
Copy link
Author

Awesome! Thank you, sir 👍

@newmarcel
Copy link
Owner

I'm sorry for the delay, but I became absolutely discouraged from developing this feature when I saw how these AppleScript APIs and scripting definitions should be implemented 😭.

I'll have a look at this year's AppleScript-related WWDC sessions to see if there is anything new in there to make my life easier implementing scripting support.

I'll update this issue when I've gathered new insights into AppleScript. Thanks for your patience!

@marcphk
Copy link

marcphk commented Mar 20, 2018

Just to add - I would very much like this too if it's something that's still on the cards.

@tsankuanglee
Copy link

tsankuanglee commented Apr 1, 2019

Or is there a way to do it in bash (some command line tool)? Having an API-like service can open up possibilities such as user-defined scripts (therefore a lot of custom features can be offload to user scripts), control from the touch bar, etc.

AppleScript can then call the bash script (or some command line tool) to achieve the same thing.

@babul
Copy link

babul commented Jan 2, 2022

My use case was I wanted to reset the countdown to 5 hours via a bash script, which is how I got here.

To workaround not being able to AppleScript it, I just set the default activation period to 5 hours, then close and reopen the app from Bash. Easy peasy!

@AlecRust
Copy link

Is there still not a simple way to toggle KeepingYouAwake from the command line?

I've been using Lungo only because it has a CLI for this.

@newmarcel
Copy link
Owner

@AlecRust Since version 1.3.0 you can use URL schemes to control KYA from the command line, e.g.

open "keepingyouawake:///activate"
open "keepingyouawake:///deactivate"
open "keepingyouawake:///activate?minutes=5"

(please note the quotes when using zsh)

Is that insufficient for your use case? If that is the case I would even recommend using Apple's caffeinate command line tool directly.

@AlecRust
Copy link

Oh that's great, thanks!

@alexraileanu
Copy link

alexraileanu commented Dec 6, 2023

it wasn't entirely obvious to me but looking thru the source code, i found out that there is also

open "keepingyouawake:///toggle"

to, you guessed it, toggle activation state.

@RX4NT9UP
Copy link

FYI on 1.6.5 at least to make this work consistently I had to do
open “keepingyouawake:///deactivate” && open “keepingyouawake:///activate”

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

No branches or pull requests

8 participants