Quit application on Sleep ...

Hi,

Some of my applications are in conflict with the screen suspension mode (translated from french … first the screen saver then the screen «suspension mode»).

How can I quit these applications when the screen suspension mode activates ?

Thanks in advance.

You could have a simple sleep script. Just save all document and close. then quit. then sleep.

tell application "TextEdit"
	close every document with saving
	quit
end tell
tell application "Finder"
	sleep
end tell

But if there untitle files and other application requirements could be fun.

Hi,

What is screen suspension mode?

gl,

I am french, so I have translated it … You have the screensaver mode and after a lapse of time the screen get dark … That is what I call the screen suspension mode.

I use a preference pane called “Scenario”. It will run scripts kept in its folders at log out, log in, Sleep, and Idle. Not free but only $10.

Thank you Adam. It should do the job perfectly.

Robert

What kind of application do you have that is not working when the display sleeps? If it’s a script applcation that you can modify, then you could detect when screensaver is running and not display anything. Note that when display sleeps, screensaver is still on.

gl,

Good catch, Kel: the distinction between “running” and “displaying”.

Hi Kel,

I cannot suspend my computer’s activity for some reason … I am looking for a way, by script, to QUIT an application when the screen’s activity is suspended. But better, it should QUIT after a preset idle time. Adam suggested Scenario, a little preference pane, that should do the job perfectly.

I wonder if there is a way to script that ? If Adam is using SCENARIO, it is means simpler and less trouble that to script it …

Thanks for helping.

;);):wink:

P.S. Is there a way, in my profile (not by checking these choices everytime), to receive replies to my post and to include my System info automaticaly ?

Model: iMac G5 1.6 MHZ - 2GB
AppleScript: 1.10.7
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

Yeah but you don’t want to use another application if you can do it your self. That’s the first reason why I learned applescript. So I wouldn’t have to buy anything else. Consider that I doloed out 1800 bucks to 2000 for this laptop and the software. But wer’re not talking about me but you.

Way at the bottom of each thread page there is a “Subscribe to this topic” link. If you click that (it is not the default and you cannot make it the default) you’ll get emails when there are changes to the topic.

In your profile, select “Personality” and enter:

Robert Lesperance
Model: iMac G5 1.6 MHZ - 2GB
AppleScript: 1.10.7
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

in your footer which will accept more than one line.

OK … Now that I have «Scenario» I thought I was on my way, but the script that should be simple does not work.

The application I am trying to ACTIVATE or QUIT is «HP COMMUNICATIONS». It is a small HP application/driver ??? that works in background with my All-in-one HP printer. Because this little piece of software gives me Kernell panics when left unatended for a while (and because HP does not give any support because the printer as 5 years old) , I want to QUIT it after an idle time of 45 minutes. It is probably important to say that it is nested in MACINTOSH<LIBRARY<PRINTERS<HP. I dont know if this is important the file is owned by DAEMON (???).

I have 2 scripts. One to ACTIVATE and the other to QUIT the app, and they read:

tell application "System Events" to exists process "HP Communications"
set appRunning to result

if result is false then
	activate application "HP Communications"
	delay 2
	activate application "HP All-in-One Device Chooser"
end if
tell application "System Events" to exists process "HP Communications"
set appRunning to result

if appRunning is true then
	quit application "HP Communications"
end if

There seem to be a communication problem with «HP Communications». The ACTIVATE script activates «HP Communications», then hangs and never activates the second app. If runned from the AS editor, I get a message that there is an AppleScript timout event. If I double click the «HP Communications» icon it activates without delay.

The QUIT script hangs also but executes after 1 or 2 minutes …

What could be the problem ???

Model: iMac G5 1.6 MHZ - 2GB
AppleScript: 1.10.7
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

Try putting inside a try and timeout, likely to help. Strange behavior, it must be looking for print jobs or something like that, and timesout

if result is false then
   try
   with timeout of 3 seconds
   activate application "HP Communications"
   end timeout
   end try
   activate application "HP All-in-One Device Chooser"
end if

Have fun

Hi Bevos,

On ACTIVATE «HP Communications» does in fact activate but the AppleScript Editor (ASE) was waiting for something that I do not understand. The TRY statement eliminates that hanging time and seems to have fix my problem. I will have to try out more extensively to see if everything is OK.

I found on internet an article on the problem many HP printers are having with TIGER. There seem to be many other users who experiment this situation. HP still does not want to correct the problem, stating that my printers has 5 years old. I am a little bit surprise with this attitude from HP …

I don’t know if you better understand the limits and possibilities of the article. The link is:

http://captnswing.net/2004/02/27/fix_hp_officejet.html

Thanks for helping.

Hi RE;

I would try something like this (which I can’t compile):


tell application "system Events" to if not exists process "HP Communications" then
ignoring application responses
activate application "HP Communications"
delay 2
activate application "HP All-in-One Device Chooser"
end ignoring
else
ignoring application responses
quit application "HP Communications"
end ignoring
end if

Hi Adam,

Can you tell me what is the difference with Bevos’s script ?
Why do you say you can compile the script ?

Finaly this is my script:

tell application "System Events" to exists process "HP Communications"

if result is true then
	try
		with timeout of 5 seconds
			quit application "HP Scan"
			quit application "PageSender"
			delay 5
			quit application "HP Communications"
			
		end timeout
	end try
end if

This script in conjuction with SCENARIO quits HP COMMUNICATIONS and other related apps when the IDLE time is more than 15 minutes. I never add any more kernell panics since, except last night.

I discovered that each user as a HP COMMUNICATIONS app running. My daughter opened her user and HP COMMUNICATIONS was activated at startup in the back ground. My copy was closed after 15 minutes of IDLE time but not my daugther’s.

Can I have a script quit HP COMMUNICATIONS for all users ??

Thanks in advance.

Robert

Model: iMac G5 1.6 MHZ - 2GB
AppleScript: 1.10.7
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

For obvious reasons, OS X doesn’t want you to quit applications that belong to another user from your account. You may have to resort to a shell script. set U to (do shell script “users”) will find out who’s logged in. “killall procName” will force quit anything given appropriate permissions and privileges.

To find out if something is running anywhere, I use this (using ntpd as an example: Do not quit it!):


set Running to true
try
	do shell script "top -l 1 | grep ntpd" -- that's a -(lower case L) so that top runs only once.
on error -- grep fails to find it
	set Running to false
end try
Running --> true, doesn't matter whose process

set Run2 to false
tell application "System Events" to if exists process "ntpd" then set Run2 to true
Run2 --> false, not my process