Scripts on sleep and wake?

Would it be possible to write a script which would cause the utility to quit on sleep and be started on wake?
Ted Lee wrote on :

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

Tom Stiller replied on :

In article 3c229b92-87b2-4980-9599-9679d48d7527@redacted.invalid, Ted Lee TMPLee@redacted.invalid 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.

Donald Hall replied on :

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

In article 3c229b92-87b2-4980-9599-9679d48d7527@redacted.invalid, Ted Lee TMPLee@redacted.invalid 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

Ted Lee replied on :

On Apr 6, 10:04=A0pm, Tom Stiller tomstil...@redacted.invalid 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

Tom Stiller replied on :

In article fc500ed6-6978-48e7-8103-13bf9200e890@redacted.invalid, Ted Lee TMPLee@redacted.invalid wrote:

On Apr 6, 10:04 pm, Tom Stiller tomstil...@redacted.invalid 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 " in the .wake script will probably start the application, although I don't know how to start it hidden.

"killall " 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).

Ted Lee replied on :

On Apr 7, 9:55=A0am, Tom Stiller tomstil...@redacted.invalid wrote:

In article fc500ed6-6978-48e7-8103-13bf9200e...@redacted.invalid, =A0Ted Lee TMP...@redacted.invalid wrote:

On Apr 6, 10:04=A0pm, Tom Stiller tomstil...@redacted.invalid wrote:

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

"killall " 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

Tom Stiller replied on :

In article d92c7dce-0d58-41a3-869c-17d9222fb28f@redacted.invalid, Ted Lee TMPLee@redacted.invalid wrote:

On Apr 7, 9:55 am, Tom Stiller tomstil...@redacted.invalid wrote:

In article fc500ed6-6978-48e7-8103-13bf9200e...@redacted.invalid, Ted Lee TMP...@redacted.invalid wrote:

On Apr 6, 10:04 pm, Tom Stiller tomstil...@redacted.invalid wrote:

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

"killall " 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).

Ted Lee replied on :

On Apr 7, 9:55=A0am, Tom Stiller tomstil...@redacted.invalid wrote:

In article

"open -a " 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

Tom Stiller replied on :

In article 4aa2c3ca-3207-4d4d-b2cf-e8c0abe01ccb@redacted.invalid, Ted Lee TMPLee@redacted.invalid wrote:

On Apr 7, 9:55 am, Tom Stiller tomstil...@redacted.invalid wrote:

In article

"open -a " 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.

Ted Lee replied on :

On Apr 7, 4:11=A0pm, Tom Stiller tomstil...@redacted.invalid wrote:

In article 4aa2c3ca-3207-4d4d-b2cf-e8c0abe01...@redacted.invalid, =A0Ted Lee TMP...@redacted.invalid wrote:

On Apr 7, 9:55=A0am, Tom Stiller tomstil...@redacted.invalid wrote:

In article

"open -a " 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

nospam replied on :

In article c72942d2-a0e2-4b45-ac25-2a6bc3c4736d@redacted.invalid, Ted Lee TMPLee@redacted.invalid wrote:

"open -a " 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.

Ted Lee replied on :

On Apr 7, 6:38=A0pm, nospam nos...@redacted.invalid wrote:

In article c72942d2-a0e2-4b45-ac25-2a6bc3c47...@redacted.invalid, Ted

Lee TMP...@redacted.invalid wrote:

"open -a " 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

Simon Slavin replied on :

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

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.

william mitchell replied on :

Simon Slavin slavins.delete.these.four.words@redacted.invalid writes:

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

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.

Jolly Roger replied on :

In article m2skxuwl17.fsf@redacted.invalid, william mitchell mitchell@redacted.invalid wrote:

Simon Slavin slavins.delete.these.four.words@redacted.invalid writes:

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

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 ] [-a ] [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.