I'm trying to run pmset sleepnow
linked to a keyboard shortcut with automator. When I use the shortcut, it's giving me a 'Cancel' or 'Continue' prompt. Anyway to skip this so the script just runs when I press the key combo?
-
Like ʀ2ᴅ2, I too cannot reproduce your issue. I'd suggest you edit your question to include additional information to help us diagnose/troubleshoot.– user3439894Commented Oct 29, 2018 at 12:19
Add a comment
|
1 Answer
I'm not able to replicate your prompt issue if I code the sleepnow
in a do shell
.
- Launch Automator
- Go to
File > New
- Select Service and click Choose
- Select "No input" in drop-down list
- Select in drop-down list "Any application"
- Select "Run AppleScript" and double-click or drag and drop
- Replace the script with a
do shell
- Save the service
- Add service in keyboard
The code:
try
display notification "Attempting sleep"
delay 2
set result to do shell script "pmset sleepnow"
on error result
display dialog result
end try
The service with shortcut:
System specs:
macOS Sierra Version 10.12.6 on Macbook Pro
-
There should not be a need to use a Run AppleScript action when all that's needed is a Run ShellScript action with simply
pmset sleepnow
as the command. Commented Oct 29, 2018 at 12:21 -
Well if there was an error to occur it will render the error.– ʀ2ᴅ2Commented Oct 30, 2018 at 13:07