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

Similar Threads
thread Thread Starter Forum Replies Last Post
How do I build a Safari plugin that can run a shell script? moonman239 Mac Programming 1 May 9, 2014 05:46 PM
Why won't this applescript execute as folder action script? dancks Mac Programming 20 Jul 18, 2013 12:46 PM
Anyone know how to use AppleScript or shell-script? gba2000 Mac Applications and Mac App Store 0 Apr 23, 2013 11:14 AM
How to create a shell script and run it? Killwin98 Mac Programming 3 Mar 18, 2013 06:39 PM
iCal "Run Script" alert opens .scpt file in AppleScript Editor instead of running it drskot Mac Programming 3 Jun 7, 2012 12:47 PM

Forum Jump

All times are GMT -5. The time now is 03:11 AM.

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

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