Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Feb 18, 2011, 06:22 PM   #1
BlueRevolution
macrumors 601
 
BlueRevolution's Avatar
 
Join Date: Jul 2004
Location: Montreal, QC
Applescript shell script won't run when display is sleeping

I wrote the following shell script to sleep my computer from the command line:

/usr/bin/sleepy:
#!/usr/bin/osascript
tell application "system events" to sleep


It works perfectly when run from Terminal or over a ssh connection while the computer is running normally, but while the display is asleep and the command is run over ssh, it does nothing, even though all other commands work fine. Since the point was to be able to sleep the computer remotely, that's a bit of a serious flaw.

Any suggestions?
__________________
PIRATE PARTY OF CANADA Information leadership for the 21st century
BlueRevolution is offline   0 Reply With Quote
Old Feb 18, 2011, 07:31 PM   #2
Doctor Q
Administrator
 
Doctor Q's Avatar
 
Join Date: Sep 2002
Location: Los Angeles
Just to get the obvious question out of the way, are you sure that it's the case where they display is sleeping, as opposed to when the computer is sleeping? Do you actually get a connection in which to use the command?
__________________
Oh do pay attention 007. In the wrong hands, this cylindrical 12-core Mac Pro with three 4K displays, FirePro graphics, and Thunderbolt 2 could be very dangerous.
Doctor Q is offline   0 Reply With Quote
Old Feb 18, 2011, 07:47 PM   #3
jiminaus
macrumors 65816
 
Join Date: Dec 2010
Location: Sydney
I'm surprised at this. I would have the thought the network activity produced by the remote connection would have prevented the computer from sleeping.
jiminaus is offline   0 Reply With Quote
Old Feb 18, 2011, 08:32 PM   #4
chown33
macrumors 603
 
Join Date: Aug 2009
This worked for me, with display sleeping or not:
Code:
cat sleepy
#!/bin/bash
/usr/bin/osascript -e 'tell app "System Events" to sleep'
So did this command:
Code:
sudo pmset sleepnow
chown33 is offline   0 Reply With Quote
Old Feb 18, 2011, 08:59 PM   #5
BlueRevolution
Thread Starter
macrumors 601
 
BlueRevolution's Avatar
 
Join Date: Jul 2004
Location: Montreal, QC
Quote:
Originally Posted by Doctor Q View Post
Just to get the obvious question out of the way, are you sure that it's the case where they display is sleeping, as opposed to when the computer is sleeping? Do you actually get a connection in which to use the command?
Yes. As I said, I can ssh in and run other commands while the display is asleep.

Quote:
Originally Posted by jiminaus View Post
I'm surprised at this. I would have the thought the network activity produced by the remote connection would have prevented the computer from sleeping.
Nope, when the computer sleeps it just stops responding to subsequent commands. Can't wake it up again remotely via ssh, only (by my understanding) with a wake-on-wireless-LAN–enabled computer and an Apple router.

Quote:
Originally Posted by chown33 View Post
This worked for me, with display sleeping or not:
Code:
cat sleepy
#!/bin/bash
/usr/bin/osascript -e 'tell app "System Events" to sleep'
No good. That's the same command.

Quote:
Originally Posted by chown33 View Post
So did this command:
Code:
sudo pmset sleepnow
Perfect! I'd rather not have to sudo up to run it, but it seems to work fine without sudo. Just rewrote that as a shell script and presto.

Thanks for the help, folks.
__________________
PIRATE PARTY OF CANADA Information leadership for the 21st century
BlueRevolution is offline   0 Reply With Quote
Old Feb 19, 2011, 12:55 AM   #6
chown33
macrumors 603
 
Join Date: Aug 2009
If pmset doesn't need sudo, then you're probably logged in as root. That might affect the running of AppleScripts.

I wasn't logged in as root when I ran my tests.
chown33 is offline   0 Reply With Quote
Old Feb 19, 2011, 03:11 AM   #7
BlueRevolution
Thread Starter
macrumors 601
 
BlueRevolution's Avatar
 
Join Date: Jul 2004
Location: Montreal, QC
I'm not. My user account is admin, but it's not root.
__________________
PIRATE PARTY OF CANADA Information leadership for the 21st century
BlueRevolution is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Tags
applescript, shell scripting, sleep

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Run Script with Administrative Privileges during PackageMaker Installation rebello95 Mac Programming 0 Nov 7, 2011 11:27 PM
Use backslash in Applescript running a Bash Shell Script rebello95 Mac Programming 12 Nov 3, 2011 01:56 PM
External 3.5" hard disk won't sleep only when mini is asleep ICEBreaker Mac OS X 10.7 Lion 0 Aug 24, 2011 12:28 PM
17" MBP Battery Life / Put Display to sleep / headphone jack / VZ Access Manager dkhanley MacBook Pro 1 Jul 19, 2011 06:25 PM
Don't Want My PB to go to sleep when display is closed ///mdriver Macintosh Computers 11 Mar 10, 2004 04:02 PM


All times are GMT -5. The time now is 01:43 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC