Python neophyte - command computer to "sleep"

Posted on
Thu Aug 19, 2021 11:17 am
KSimmons offline
User avatar
Posts: 15
Joined: Mar 24, 2017

Python neophyte - command computer to "sleep"

Running Indigo 7.4.1 under Catalina in a rather warm hangar in Florida. I previously used AppleScript to put the computer to sleep when the outside temp variable went above 85°. Now that AppleScript is no longer supported, what is the Python script that I use to perform this same function. (I have the computer wake itself up later that evening when temps have cooled, using the "Wake on LAN" function)

I could not find an answer searching the Forum. I'm very new to Pythin.

– Kevin

Posted on
Thu Aug 19, 2021 11:23 am
FlyingDiver offline
User avatar
Posts: 7213
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Python neophyte - command computer to "sleep"

You can still issue AppleScript commands, you just can’t control Indigo with AppleScript.


Sent from my iPhone using Tapatalk

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Thu Aug 19, 2021 11:56 am
KSimmons offline
User avatar
Posts: 15
Joined: Mar 24, 2017

Re: Python neophyte - command computer to "sleep"

Thanks for the quick reply.

I was getting the error because I had the AppleScript embedded in the Actions tab as an "Execute Script". Rather than create a separate AppleScript and run it as a File, I wanted to try my hand at doing the same using Python.

Any suggestions for this as a Python command?

– Kevin

Posted on
Thu Aug 19, 2021 12:42 pm
FlyingDiver offline
User avatar
Posts: 7213
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Python neophyte - command computer to "sleep"

What was your AppleScript to do it?

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Thu Aug 19, 2021 12:49 pm
KSimmons offline
User avatar
Posts: 15
Joined: Mar 24, 2017

Re: Python neophyte - command computer to "sleep"

This what I had as the AppleScript:
tell application "Finder"
sleep
end tell

Pretty simple. I would think this would be easy to translate over to Python.

– Kevin

Posted on
Thu Aug 19, 2021 12:53 pm
FlyingDiver offline
User avatar
Posts: 7213
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Python neophyte - command computer to "sleep"

KSimmons wrote:
This what I had as the AppleScript:
tell application "Finder"
sleep
end tell

Pretty simple. I would think this would be easy to translate over to Python.

– Kevin


Only by calling AppleScript from Python to do the "tell Finder" thing.

This should work:

Code: Select all
import os
os.system("pmset sleepnow")

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Thu Aug 19, 2021 1:08 pm
KSimmons offline
User avatar
Posts: 15
Joined: Mar 24, 2017

Re: Python neophyte - command computer to "sleep"

import os
os.system("pmset sleepnow")


Aha! I did see a reference to "pmset sleepnow" when searching for Python commands for "sleep". I did not know how to implement it correctly within Indigo however.

I will give this a try. Thank you!

– Kevin

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest