How to hide an "on idle" applescript process?

I know how to hide a normal process (set visible of process x to false).

But I created an applescript app that stays resident, functioning via an “on idle” command.

How do I make this process invisible after each execution? The script name remains in the menubar after execution, but if I try to set its visible property I get an error. And I can’t find the process name in Activity Monitor.

I just want to go back to the previously open and foremost app after the script executes.

Thanks…

chico

Hi,

It’s not a rule that a script with an idle handler becomes frontmost when the idle handler fires. Something in your idle handler is bringing it to the front. Try something like this:

global my_name
on run
set my_name to (name of (info for (path to me)))
end run
on idle
tell application “System Events” to set fpn to name of first process whose frontmost is true
– your stuff here
activate
tell application “System Events”
set frontmost of process fpn to true
set visible of process my_name to false
end tell
return 10
end idle

The activate command is there just to bring the script app to the front and is not necessary.

gl,

Thanks. Lots to learn, but it’s happening.

By the way, when a script is running as an “on idle” process, why is its name not present in the Activity Monitor window? Apparently its a type of process different than a standard application?

Hi chico,

Glad it worked. I don’t have an activity monitor, just Process Viewer here in Jaguar. It shows up in Process Viewer.

From the Script Editor, you can see all running application processes.

tell app “System Events”
name of every process whose visible is true
end tell

gl,

In 10.3.8, using the command “name of every process” produces a small subset of those shown in the Activity Monitor. If idle handlers are not always shown, how can I discover whether one I was working on some time ago is still operating? I don’t see it, but I do see some behavior that suggests it is running. Is this possible after a restart?

I look in the dock to see if applications are running. Just got an idea. What if you put the idle handler in the Applications folder? Maybe the activity minitor looks in there.

I don’t know what you mean when you say “Is this possible after restart?”.

gl,

Not a good question, kel; It had to do with persistent energy saver behavior that I haven’t been able to stop. Clearly somethng has been set that doesn’t show in pmset and I don’t know where else to look. Unfortunately, I’m running an enhanced B&W G3 and their behavior doesn’t meet modern “sleep” standards - it’s a “dozer”. I never let it sleep because my video card (a Radeon 7000 flashed Mac) doesn’t know how to wake up (doesn’t reboot itself when the PCI bus power comes back on).

I think someone posted a question on this (waking the display after sleep) because I had this script. It continues running after waking from sleep longer than 3 minutes.

global target_date

on run
set the_date to (current date)
set target_date to the_date + 180
end run

on idle
set the_date to (current date)
if the_date > target_date then
set target_date to the_date + 180
beep 3
tell application “System Events” to keystroke space
end if
return 2
end idle

gl,

Hi,

That must have been the test script. target_date should be updated each time:

global target_date

on run
set the_date to (current date)
set target_date to the_date + 180
end run

on idle
set the_date to (current date)
if the_date > target_date then
beep 3
tell application “System Events” to keystroke space
end if
set target_date to the_date + 180
return 2
end idle

gl,

If all you want is to keep the screens from sleeping:

-- Set sleep time for screens to "Never"
tell application "Keychain Scripting"
	launch
	tell current keychain
		tell (some generic key whose name is "youNameIt")
			set myPW to password
		end tell
	end tell
end tell
delay 1
do shell script "sudo pmset -a dim 0 spindown 30" password myPW with administrator privileges
delay 1
do shell script "sudo -k" -- timeout the sudo capability
delay 1
quit

Although this does successfuly set the dim time to never, the screens still dim in my case, so kel’s “jiggler” might be the better solution (without the beep, of course).

I haven’t tried it, but doesn’t this mean that you’ll come back to find a lot of spaces in a document that was frontmost when you left?

A much simpler way to keep screens from sleeping: Stick Software’s “Jiggler” which nudges the cursor periodically. Price is right too - Free

Hi NovaScotian,

The script should wait until the computer wakes after more than 3 minutes of deep sleep before it hits the space bar. It’s mainly a do something after deep sleep script. I didn’t know if it worked or not. Maybe it should activate the Finder before it keystrokes the space (or something else that wakes the display), so that it wouldn’t change any documents that might have been in front.

If it did work, then it might save display life. An example might be a laptop’s display not waking after you open the lid. You don’t want to have a laptop’s display on all the time.

gl,

I never sleep my CPU - it’s a G3 dozer anyway and my Radeon 7000 video card doesn’t wake up gracefully (the G3 turns off the PCI bus power).

I used to use this script (which works) to sleep the screens soon,

tell application "Keychain Scripting"
	launch
	tell current keychain
		tell (some generic key whose name is "applescriptAllow")
			set myPW to password
		end tell
	end tell
end tell
try
	do shell script "sudo pmset -a dim 1 spindown 1" password myPW with administrator privileges
	delay 2
	do shell script "sudo -k" -- timeout sudo ability
end try
delay 1
quit

And this one at wake up time:

tell application "Keychain Scripting"
	launch
	tell current keychain
		tell (some generic key whose name is "applescriptAllow")
			set myPW to password
		end tell
	end tell
end tell
delay 1
try
	do shell script "sudo pmset -a dim 0 spindown 30" password myPW with administrator privileges
	delay 1
	do shell script "sudo -k" -- timeout sudo ability
end try
delay 1
quit

Of course for that to work, you’ve got to set up the generic password in your Keychain. Alternatively, you can just stick your password in the do shell script statement and forget the Keychain stuff.