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?
Asked
Active
Viewed 706 times
0
user4396386
- 255
-
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. – user3439894 Oct 29 '18 at 12:19
1 Answers
0
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
ʀ2ᴅ2
- 1,064
-
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 sleepnowas the command. – user3439894 Oct 29 '18 at 12:21 -

