The conversation on this page has been archived and is no longer active.

Scripts on sleep and wake?

Message #1 - Posted 2008/04/06 - Ted Lee

Apropos my wireless card, I have discovered one thing that may be related to why I couldn't make it work at first -- the utility (analogous to airport menu) is not well-behaved when the computer is put to sleep. If the WireLess utility (an application that came with the card -- used for managing it) is running when the computer is put to sleep, the computer won't wake up -- I have to force a shutdown by holding the power key, and then restarting. This isn't a problem when not using encryption, because it'll connect automatically (just using the card firmware and kernel extension) without the utility being running. On the other hand, when using encryption the utility has to be running (I assume because that's what knows/gets the password.) So, if I quit the utility, put the computer to sleep, wake it, then start the utility everything's fine -- it even connects automatically -- but that's what I regard as two unnecessary steps. Would it be possible to write a script which would cause the utility to quit on sleep and be started on wake? I can see how it might not be possible to run a "quit-on-sleep" script, because the process would already be asleep, so I guess it'd at least help to have a "start-on-wake" script -- I'd just have to remember to quit the utility before closing the cover.

I know, I'm lazy!

Ted Lee
Minnetonka, MN

Message #2 - Posted 2008/04/06 - Tom Stiller

Previously, Ted Lee wrote:

Apropos my wireless card, I have discovered one thing that may be related to why I couldn't make it work at first -- the utility (analogous to airport menu) is not well-behaved when the computer is put to sleep. If the WireLess utility (an application that came with the card -- used for managing it) is running when the computer is put to sleep, the computer won't wake up -- I have to force a shutdown by holding the power key, and then restarting. This isn't a problem when not using encryption, because it'll connect automatically (just using the card firmware and kernel extension) without the utility being running. On the other hand, when using encryption the utility has to be running (I assume because that's what knows/gets the password.) So, if I quit the utility, put the computer to sleep, wake it, then start the utility everything's fine -- it even connects automatically -- but that's what I regard as two unnecessary steps. Would it be possible to write a script which would cause the utility to quit on sleep and be started on wake? I can see how it might not be possible to run a "quit-on-sleep" script, because the process would already be asleep, so I guess it'd at least help to have a "start-on-wake" script -- I'd just have to remember to quit the utility before closing the cover.

I know, I'm lazy!

Have a look at sleepwatcher
<http://www.versiontracker.com/dyn/moreinfo/macosx/17579>.

Tom Stiller

PGP fingerprint = 5108 DDB2 9761 EDE5 E7E3 7BDA 71ED 6496 99C0 C7CF

Message #3 - Posted 2008/04/07 - Donald Hall

Ted,

Take a look at Script Timer at:

http://www.appsandmore.com

You can use it to schedule AppleScript, perl, or shell scripts just before the computer goes to sleep, or just after it wakes up. (Script Timer also can schedules scripts at set times of the day, repeating intervals, at login and logout, and when the computer goes idle or leaves an idle state.)

You could write a one line script to quit your application and schedule it to run at sleep time, and another one line script to start it up again on wake.

Don

Previously, Ted Lee wrote:

Apropos my wireless card, I have discovered one thing that may be related to why I couldn't make it work at first -- the utility (analogous to airport menu) is not well-behaved when the computer is put to sleep. If the WireLess utility (an application that came with the card -- used for managing it) is running when the computer is put to sleep, the computer won't wake up -- I have to force a shutdown by holding the power key, and then restarting. This isn't a problem when not using encryption, because it'll connect automatically (just using the card firmware and kernel extension) without the utility being running. On the other hand, when using encryption the utility has to be running (I assume because that's what knows/gets the password.) So, if I quit the utility, put the computer to sleep, wake it, then start the utility everything's fine -- it even connects automatically -- but that's what I regard as two unnecessary steps. Would it be possible to write a script which would cause the utility to quit on sleep and be started on wake? I can see how it might not be possible to run a "quit-on-sleep" script, because the process would already be asleep, so I guess it'd at least help to have a "start-on-wake" script -- I'd just have to remember to quit the utility before closing the cover.

I know, I'm lazy!

Ted Lee
Minnetonka, MN

Donald S. Hall, Ph.D.
Apps & More Software Design, Inc.
http://www.appsandmore.com don at appsandmore dot com
"Schedule your scripts with Script Timer"

Message #4 - Posted 2008/04/07 - Ted Lee

On Apr 6, 10:04=A0pm, Tom Stiller wrote:

Have a look at sleepwatcher
<http://www.versiontracker.com/dyn/moreinfo/macosx/17579>.

That does indeed look like it will probably do the trick. Thanks. However, I have to plead only a very rudimentary knowledge of unix (and most of that 30 years old and unused) and if I may I'd like to ask for a little more help. Suppose the path to the utility is / Applications/CardBusUtility. What do I put in the "sleep" script to make it quit gracefully? (since it's running I shouldn't need -- or probably want -- a force quit.) What do I put in the "wake" script to start it running -- and, if possible, I'd like it to start hidden, as if it were a login item with the "hide" box checked. It's a very simple application with a single window that always comes up which I don't need if everything's working fine. (forgive me if the man page for sleepwatcher has the answers to those questions -- I haven't installed it yet.)

Ted Lee
Minnetonka, MN

Message #5 - Posted 2008/04/07 - Tom Stiller

Previously, Ted Lee wrote:

On Apr 6, 10:04†pm, Tom Stiller wrote:

Have a look at sleepwatcher
<http://www.versiontracker.com/dyn/moreinfo/macosx/17579>.

That does indeed look like it will probably do the trick. Thanks. However, I have to plead only a very rudimentary knowledge of unix (and most of that 30 years old and unused) and if I may I'd like to ask for a little more help. Suppose the path to the utility is / Applications/CardBusUtility. What do I put in the "sleep" script to make it quit gracefully? (since it's running I shouldn't need -- or probably want -- a force quit.) What do I put in the "wake" script to start it running -- and, if possible, I'd like it to start hidden, as if it were a login item with the "hide" box checked. It's a very simple application with a single window that always comes up which I don't need if everything's working fine. (forgive me if the man page for sleepwatcher has the answers to those questions -- I haven't installed it yet.)

"open -a <path to application>" in the .wake script will probably start the application, although I don't know how to start it hidden.

"killall <application name>" in the .sleep script should terminate the application gracefully.

Don't forget that both the .wake and .sleep scripts must have unix EOL characters (\n), not Mac EOL characters (\r).

Tom Stiller

PGP fingerprint = 5108 DDB2 9761 EDE5 E7E3 7BDA 71ED 6496 99C0 C7CF

Message #6 - Posted 2008/04/07 - Ted Lee

On Apr 7, 9:55=A0am, Tom Stiller wrote:

Previously, =A0Ted Lee wrote:

On Apr 6, 10:04=A0pm, Tom Stiller wrote:

"open -a <path to application>" in the .wake script will probably start the application, although I don't know how to start it hidden.

"killall <application name>" in the .sleep script should terminate the application gracefully.

Don't forget that both the .wake and .sleep scripts must have unix EOL characters (\n), not Mac EOL characters (\r).

Well, since I expect both scripts to consist of a single line, I assume they won't have any EOL characters! (but are you saying I have to remember how to us vi?)

Ted Lee
Minnetonka, MN

Message #7 - Posted 2008/04/07 - Tom Stiller

Previously, Ted Lee wrote:

On Apr 7, 9:55†am, Tom Stiller wrote:

Previously, †Ted Lee wrote:

On Apr 6, 10:04†pm, Tom Stiller wrote:

"open -a <path to application>" in the .wake script will probably start the application, although I don't know how to start it hidden.

"killall <application name>" in the .sleep script should terminate the application gracefully.

Don't forget that both the .wake and .sleep scripts must have unix EOL characters (\n), not Mac EOL characters (\r).

Well, since I expect both scripts to consist of a single line, I assume they won't have any EOL characters! (but are you saying I have to remember how to us vi?)

While I can use vi, I prefer the (free) TextWrangler which, among many other things, easily converts/establishes EOL conventions for Mac, Unix, and DOS (ugh).

Tom Stiller

PGP fingerprint = 5108 DDB2 9761 EDE5 E7E3 7BDA 71ED 6496 99C0 C7CF

Message #8 - Posted 2008/04/07 - Ted Lee

On Apr 7, 9:55=A0am, Tom Stiller wrote:

In article

"open -a <path to application>" in the .wake script will probably start the application, although I don't know how to start it hidden.

You sure about that? I'm not at my Mac now, so I haven't had chance to look at the command, but in standard Unix "open" is the way to open a file (or anything like a file) for writing or reading -- not the way you start a program running!

Ted Lee
Minnetonka, MN

Message #9 - Posted 2008/04/07 - Tom Stiller

Previously, Ted Lee wrote:

On Apr 7, 9:55†am, Tom Stiller wrote:

In article

"open -a <path to application>" in the .wake script will probably start the application, although I don't know how to start it hidden.

You sure about that? I'm not at my Mac now, so I haven't had chance to look at the command, but in standard Unix "open" is the way to open a file (or anything like a file) for writing or reading -- not the way you start a program running!

Yes.

Tom Stiller

PGP fingerprint = 5108 DDB2 9761 EDE5 E7E3 7BDA 71ED 6496 99C0 C7CF

Message #10 - Posted 2008/04/07 - Ted Lee

On Apr 7, 4:11=A0pm, Tom Stiller wrote:

Previously, =A0Ted Lee wrote:

On Apr 7, 9:55=A0am, Tom Stiller wrote:

In article

"open -a <path to application>" in the .wake script will probably star=

t

the application, although I don't know how to start it hidden.

You sure about that? =A0 I'm not at my Mac now, so I haven't had chance to look at the command, but in standard Unix "open" is the way to open a file (or anything like a file) for writing or reading -- not the way you start a program running!

Yes.

Yup. Indeed it does (I was about to tell you it didn't work, then realized I forgot to put the .app as part of the applications name!)

Someone in an Apple discussions forum said to use Applescript -- if I had to do it from a command line, use osascript -- problem is, I know Applescript even less than I know Unix, but I assume that might give me the ability to tell the app to hide itself.

Ted Lee
Minnetonka, MN

Message #11 - Posted 2008/04/07 - nospam

Previously, Ted Lee wrote:

"open -a <path to application>" in the .wake script will probably start the application, although I don't know how to start it hidden.

Yup. Indeed it does (I was about to tell you it didn't work, then realized I forgot to put the .app as part of the applications name!)

it doesn't need .app (or the full path).

open -a Safari

will work.

Message #12 - Posted 2008/04/08 - Ted Lee

On Apr 7, 6:38=A0pm, nospam wrote:

Previously, Ted

Lee wrote:

"open -a <path to application>" in the .wake script will probably =

start

the application, although I don't know how to start it hidden.

Yup. =A0 Indeed it does =A0(I was about to tell you it didn't work, then=

realized I forgot to put the .app as part of the applications name!)

it doesn't need .app (or the full path).

open -a Safari

will work.

Yes, I later discovered that. What I did find was that if I *did* put the full path in, but left off the .app extension, it didn't work. So somehow it knows when you don't supply the full path to take what you do supply as an application name not a file name (which happens to be a package) leading to an application.

Ted Lee
Minnetonka, MN

Message #13 - Posted 2008/04/09 - Simon Slavin

On 07/04/2008, Ted Lee wrote in message <4aa2c3ca-3207-4d4d-b2cf- e8c0abe01ccb@m73g2000hsh.googlegroups.com>:

I'm not at my Mac now, so I haven't had chance to look at the command, but in standard Unix "open" is the way to open a file (or anything like a file) for writing or reading -- not the way you start a program running!

On a Mac the 'open' command does both: if the thing you point it to happens to be a program it runs that program.

Simon.

Message #14 - Posted 2008/04/09 - william mitchell

Simon Slavin <slavins.delete.these.four.words@hearsay.demon.co.uk> writes:

On 07/04/2008, Ted Lee wrote in message <4aa2c3ca-3207-4d4d-b2cf- e8c0abe01ccb@m73g2000hsh.googlegroups.com>:

I'm not at my Mac now, so I haven't had chance to look at the command, but in standard Unix "open" is the way to open a file (or anything like a file) for writing or reading -- not the way you start a program running!

On a Mac the 'open' command does both: if the thing you point it to happens to be a program it runs that program.

I believe that the "open" command that Ted is thinking about is probably the routine in the C (and other languages) programming library for opening a file. I'm not aware of a standard commandline program by that name.

Message #15 - Posted 2008/04/09 - Jolly Roger

Previously, william mitchell wrote:

Simon Slavin <slavins.delete.these.four.words@hearsay.demon.co.uk> writes:

On 07/04/2008, Ted Lee wrote in message <4aa2c3ca-3207-4d4d-b2cf- e8c0abe01ccb@m73g2000hsh.googlegroups.com>:

I'm not at my Mac now, so I haven't had chance to look at the command, but in standard Unix "open" is the way to open a file (or anything like a file) for writing or reading -- not the way you start a program running!

On a Mac the 'open' command does both: if the thing you point it to happens to be a program it runs that program.

I believe that the "open" command that Ted is thinking about is probably the routine in the C (and other languages) programming library for opening a file. I'm not aware of a standard commandline program by that name.

# open -h
Usage: open [-e] [-t] [-f] [-W] [-n] [-g] [-h] [-b <bundle identifier>] [-a <application>] [filenames]
Help: Open opens files from a shell.
By default, opens each file using the default application for that file.
If the file is in the form of a URL, the file will be opened as a URL.
Options:
-a Opens with the specified application.
-b Opens with the specified application bundle identifier.
-e Opens with TextEdit.
-t Opens with default text editor.
-f Reads input from standard input and opens with TextEdit.
-W, --wait-apps Blocks until the used applications are closed (even if they were already running).
-n, --new Open a new instance of the application even if one is already running.
-g, --background Does not bring the application to the foreground. -h, --header Searches header file locations for headers matching the given filenames, and opens them.

Need Help? Have a Question?

Looking for more help, comments, and answers?

Ask your questions on Ask Different. Ask Different is a community of Apple users ready to help.