Wednesday, January 24, 2018

#1 2006-06-09 08:09:54 am

bob
Member
Registered: 2005-08-29
Posts: 25

Possible to make a applescript that works like a screensaver?

Goodday everybody,

Is it possible to create an applescript that works like a screensaver? So when there is no system activity it can launch an application. So that while I'm working this app doesn't suck too much system power (like a Cinema 4D client) and while I'm gone or go to sleep (and forget to put in on)  this will automaticly launch it and go render..... think you get the point.

Thanks....

Bob

ps have two machines A Minimac B G4
The G4 has the main Cinema 4D render app & one client renderer.
The Minimac I use as main machine two work on. This script has two launch the second client render app so it can help render the animations etc

Offline

 

#2 2006-06-10 05:34:31 am

Fistoprince
Member
Registered: 2006-06-07
Posts: 161

Re: Possible to make a applescript that works like a screensaver?

From what little I know, applescript can remotly controll applications. But I don't think it can display graphics which is the main use of a screensaver. If I'm wrong, just say.


Set stumpy to "Pet Rock"
copy stumpy to ± 15 meters above right_foot
say "Ouch!" using "agnes"
set right_foot_HP to 0

Offline

 

#3 2006-06-10 12:59:20 pm

mark hunte
Member
From:: Hello, London Calling
Registered: 2006-03-20
Posts: 1030
Website

Re: Possible to make a applescript that works like a screensaver?

look at this pages
http://www.macosxhints.com/article.php? … 0161158532
http://bbs.applescript.net/viewtopic.php?id=16030



Also I run  this in one of my scripts to run part of my script if there is no keys pressed for a set period of time.
i.e I am not using the mac

I can not remember where I found my part but it may help you do a search.
The part of AS below  is put with in a idle handler

Applescript:


-- idle handler and other parts of script here which runs every 30 seconds or so -----

set idletime to do shell script "ioreg -c IOHIDSystem | awk '/HIDIdleTime/ {print int($NF/1000000000); exit}'"
   set idletime to idletime as string
   set idletime to idletime as integer
   if idletime is greater than 110 then -- 110 = 1 minute and 50 seconds without a key being pressed
---- your action here -----
else
---- your other action here -----

you could try and google

"ioreg -c IOHIDSystem applescript"

Last edited by mark hunte (2006-06-10 01:05:40 pm)


Tap,tap,tap , hello , testing 1..2,  1...2,
http://www.markosx.com/thecocoaquest/

Offline

 

#4 2006-06-11 06:54:56 am

bob
Member
Registered: 2005-08-29
Posts: 25

Re: Possible to make a applescript that works like a screensaver?

Phistoprince & Mark thank both off you for your time responding....

Mark will test your suggestion, let you know when it's ready.

Greetings

Bob

Offline

 

#5 2006-06-11 09:50:11 am

bob
Member
Registered: 2005-08-29
Posts: 25

Re: Possible to make a applescript that works like a screensaver?

The idletime sollutions was a liitle bit to much asked for my limited Applescript skils wink

so searched a little bit further on this forum and found some stuff that could work (in this case not)

tell application "System Events"
    set ScreenSaverEngine_exists to (exists process "ScreenSaverEngine")
end tell
if ScreenSaverEngine_exists then
    activate application "C4D Client"
end if

This one doesn't work

also tried the following:

tell application "System Events"
    if not (exists process "ScreenSaverEngine") then
        tell application "C4D Client"
            activate
        end tell
    end if
end tell

But that script triggers it directly... guess it must be the IF NOT .. that should be IF YES, but that does not work.

Anyone has a clue?

Thanks


Filed under: System, C4D

Offline

 

#6 2006-06-11 12:55:31 pm

mark hunte
Member
From:: Hello, London Calling
Registered: 2006-03-20
Posts: 1030
Website

Re: Possible to make a applescript that works like a screensaver?

save this as a application and stay open ticked.

change the process to your process name.
and the seconds to what you want.

Applescript:

on idle
   
   set idletime to do shell script "ioreg -c IOHIDSystem | awk '/HIDIdleTime/ {print int($NF/1000000000); exit}'"
   set idletime to idletime as string
   set idletime to idletime as integer
   tell application "System Events"
       
       if idletime is greater than 120 then (* 120 is 120 seconds. If a key was NOT tapped
       within the 120 seconds it then checks to see if the app was already open. *)

           if not (exists process "chess") then
               launch application "Chess"
               return 30 -- checks again in 30 seconds
           else
               return 30 -- a key was tapped within the 120 seconds so checks again in 30 seconds
               
           end if
       end if
   end tell
end idle


Tap,tap,tap , hello , testing 1..2,  1...2,
http://www.markosx.com/thecocoaquest/


Filed under: System

Offline

 

#7 2006-06-11 01:54:19 pm

kai
Member
From:: Brighton, UK
Registered: 2005-05-28
Posts: 912

Re: Possible to make a applescript that works like a screensaver?

Hi guys.

Here's another way of doing it. (If the target app is already up, the launch command won't have any effect - so we can avoid an if/then statement):

Applescript:

property max_idle : 30 (* the number of seconds the system must be idle before your routine kicks in: modify as required *)

on idle
   tell max_idle - (do shell script "ioreg -c IOHIDSystem | awk '/HIDIdleTime/ {print int($NF/1000000000); exit}'") to if it > 0 then return it
   launch application "Chess" (* or whatever: modify as required *)
   max_idle
end idle


kai

Offline

 

#8 2006-06-11 02:17:07 pm

bob
Member
Registered: 2005-08-29
Posts: 25

Re: Possible to make a applescript that works like a screensaver?

Hello Mark & Kai,

Tried it like you discribed but it both didn't work.

ps have system 10.4.6 and have Enabled acces for assistive devices (for using System Events)
Further have the Energy Saver settings to Restored Defaults.
Perhaps it can be caused due the fact thats a little bit hot overhere in the Netherlands so the ventilator is working hard too cool the machine down?

Think we are close thanks to your effort.....

Bob

Offline

 

#9 2006-06-11 03:36:25 pm

kai
Member
From:: Brighton, UK
Registered: 2005-05-28
Posts: 912

Re: Possible to make a applescript that works like a screensaver?

You don't say how the scripts don't work, Bob. Is there an error message?

If not, perhaps we should just make sure that some of the fundamentals are in place. For an idle handler to work correctly, the script must be saved as a stay-open application. Specifically, that means:

    • Select the "File/Save as..." (Archief/Bewaar als...") menu
    • In the resulting Save dialog, click on the menu button labelled "File Format:" ("Structuur:")
    • In the menu that appears, select the "application" ("Programma:) option
    • From the 3 check boxes labelled "Options:" ("Opties:") check only the box marked "Stay Open" ("Niet sluiten")
    • Click the "Save" ("Bewaar") button

Then try running the script application by double-clicking its icon in Finder.

If you've already tried this, then I apologise. Perhaps you could give us a little more detail about what does or what doesn't happen. smile


kai

Offline

 

#10 2006-06-11 03:40:57 pm

bob
Member
Registered: 2005-08-29
Posts: 25

Re: Possible to make a applescript that works like a screensaver?

Hallo Kai,

I did it exactly like you discribed it (sorry that I was not clear on that part). So when starting the script the chess program (and tested the Cinema 4D render client but that worked neither) does not start, not even after waiting 5 minutes and doing nothing woth the machine (and hard to do not to work for 5 minutes, get a little bit of neurotic wink )

Mmmm strange isnt it? Maybee there is a bacground program running I'm not aware off...need to investigate that I think...

Thanks

Bob

Offline

 

#11 2006-06-11 04:02:56 pm

kai
Member
From:: Brighton, UK
Registered: 2005-05-28
Posts: 912

Re: Possible to make a applescript that works like a screensaver?

Curious, Bob. Works perfectly here (Mac OS X 10.4.6, too). If I leave my machine alone for 30 seconds (not easy, but there you go) - the Chess application pops up without fail... hmm

How about a shorter test? What result does this give you? (Just run from Script Editor):

Applescript:

delay 10
do shell script "ioreg -c IOHIDSystem | awk '/HIDIdleTime/ {print int($NF/1000000000); exit}'"
--> "10" (* The result I get here *)


kai

Offline

 

#12 2006-06-11 04:05:47 pm

bob
Member
Registered: 2005-08-29
Posts: 25

Re: Possible to make a applescript that works like a screensaver?

the result when I press on run within the scripteditor is

"7"

Offline

 

#13 2006-06-11 04:27:23 pm

kai
Member
From:: Brighton, UK
Registered: 2005-05-28
Posts: 912

Re: Possible to make a applescript that works like a screensaver?

Seems like there might be something jumping in there, Bob.

The following routine, which aims to take a sample roughly every second, should give you a better indication. At this level of granularity, the shell introduces a certain amount of delay - but you can see from my results that the value never returns to "0". I suspect that, with your results, it might - but it could also give you an indication of how frequently that occurs:

Applescript:

set l to {}
repeat 100 times
   set l's end to do shell script "ioreg -c IOHIDSystem | awk '/HIDIdleTime/ {print int($NF/1000000000); exit}'"
   delay 1
end repeat
l --> {"0", "1", "2", "3", "4", "5", "6", "7", "9", "10", "11", "12", "13", "14", "15", "17", "18", "19", "20", "21", "22", "23", "25", "26", "27", "28", "29", "30", "31", "33", "34", "35", "36", "37", "38", "39", "40", "42", "43", "44", "45", "46", "47", "48", "50", "51", "52", "53", "54", "55", "56", "58", "59", "60", "61", "62", "63", "64", "66", "67", "68", "69", "70", "71", "72", "74", "75", "76", "77", "78", "79", "80", "81", "83", "84", "85", "86", "87", "88", "89", "91", "92", "93", "94", "95", "96", "97", "98", "100", "101", "102", "103", "104", "105", "106", "108", "109", "110", "111", "112"}


kai

Offline

 

#14 2006-06-11 04:43:44 pm

bob
Member
Registered: 2005-08-29
Posts: 25

Re: Possible to make a applescript that works like a screensaver?

{"0", "0", "0", "0", "1", "0", "1", "2", "3", "4", "5", "6", "8", "9", "0", "1", "3", "4", "5", "6", "7", "9", "0", "1", "2", "3", "0", "1", "2", "4", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "1", "2", "3", "4", "5", "0", "1", "2", "3", "0", "1", "2", "4", "5", "0", "1", "3", "4", "5", "6", "7", "8", "0", "0", "2", "3", "4", "5", "6", "8", "9", "0", "1", "2", "0", "1", "2", "3", "4", "0", "1", "2", "3", "4", "5", "6", "8", "0", "0", "1", "2", "3", "4", "5", "7", "8", "9", "0"}

These results are "slightly" different then yours........ for now have to quit because need to get up very early.....

Will do the following tomorow: shut the machine down. Then reboot and not have any application open. Then try to run your script again....... Thinking right now maybee Little snitch can cause troubles?

Anyway Kai many thanks for your time to help. Will let you know tomorrow night if the test worked better.

Greetings

Bob

Offline

 

#15 2006-06-11 04:55:31 pm

kai
Member
From:: Brighton, UK
Registered: 2005-05-28
Posts: 912

Re: Possible to make a applescript that works like a screensaver?

Oh yes, Bob. Looks like you have something something activating every 10 seconds, there. (I'll leave you to investigate further...) Sleep tight. smile


kai

Offline

 

#16 2006-06-11 06:20:48 pm

kel
Member
Registered: 2002-11-20
Posts: 2031

Re: Possible to make a applescript that works like a screensaver?

Hi Bob,

Your ScreenSaverEngine script should work.

Scripts with idle handlers need to be saved as "stay open" applications. When the following script is run, it starts beeping when the screen saver comes on.

Applescript:


on idle
   tell application "System Events"
       set f to (exists process "ScreenSaverEngine")
   end tell
   if f then
       beep 1
   end if
   return 1
end idle

Save as "stay open" application. You can activate the screen saver app by using a hot corner, in the System Preferences, for testing.

gl,


Kel


Filed under: System

Offline

 

#17 2006-06-11 08:27:34 pm

kai
Member
From:: Brighton, UK
Registered: 2005-05-28
Posts: 912

Re: Possible to make a applescript that works like a screensaver?

I just wonder if whatever is stopping Bob's machine from idling for more than ten seconds would also prevent the ScreenSaver from launching. I'd be very interested to know if ioreg detects activity that the ScreenSaver launcher doesn't - since I'd have expected such data to come from the same source. However, if his ScreenSaver still activates successfully, then something like this should also do the trick:

Applescript:

on idle
   tell application "System Events" to if (exists process "ScreenSaverEngine") then launch application "Chess"
   30
end idle

Last edited by kai (2006-06-12 08:55:37 am)


kai


Filed under: System

Offline

 

#18 2006-06-12 03:02:34 am

mark hunte
Member
From:: Hello, London Calling
Registered: 2006-03-20
Posts: 1030
Website

Re: Possible to make a applescript that works like a screensaver?

kai wrote:

Hi guys.

Here's another way of doing it. (If the target app is already up, the launch command won't have any effect - so we can avoid an if/then statement):

Applescript:

property max_idle : 30 (* the number of seconds the system must be idle before your routine kicks in: modify as required *)

on idle
   tell max_idle - (do shell script "ioreg -c IOHIDSystem | awk '/HIDIdleTime/ {print int($NF/1000000000); exit}'") to if it > 0 then return it
   launch application "Chess" (* or whatever: modify as required *)
   max_idle
end idle


Doh I changed it from activate to launch at the last minute and forgot that launch takes care of what I was trying to avoid with the if/then statement.

Thanks..


Tap,tap,tap , hello , testing 1..2,  1...2,
http://www.markosx.com/thecocoaquest/

Offline

 

#19 2006-06-12 01:40:33 pm

bob
Member
Registered: 2005-08-29
Posts: 25

Re: Possible to make a applescript that works like a screensaver?

Hello all smile

For some still unclear reasons my screensaver doesn't start without force... but a big step further because tried kel's

on idle
   tell application "System Events"
       set f to (exists process "ScreenSaverEngine")
   end tell
   if f then
       beep 1
   end if
   return 1
end idle

That one worked when I used the hotcorner from the screensaver app.

Also Kai your script worked in forced screensaver mode;

on idle
   tell application "System Events" to if (exists process "ScreenSaverEngine") then launch application "Chess"
   30
end idle

Think maybee try to get rid off the pref settings from the screensaver but need to dig in it alittle bit further.......

Great help really appriciate it!

Thanks

Bob

ps will let you know the follow up


Filed under: System

Offline

 

#20 2006-06-14 02:53:58 pm

bob
Member
Registered: 2005-08-29
Posts: 25

Re: Possible to make a applescript that works like a screensaver?

After several day of finding what could cause the problem that the screensaver does not start by itself (and visited a lot off sites with possible tricks) almos giving up....but have a new idea; Is it perhaps possible that there is some code like this;

if no mouse movement after 10 minutes start screensaver and start also chess

please note this is off course Applescript but think you understand what I suggest.

ps bytheway did make a completely new account on my system and the the screensaver worked.......... but moving all my stuff to the new account will take me too much time.

Thanks (again)

Bob

Model: minimac PPC 1.4
Browser: Safari 417.9.3
Operating System: Mac OS X (10.4)

Offline

 

#21 2006-06-14 04:56:01 pm

kel
Member
Registered: 2002-11-20
Posts: 2031

Re: Possible to make a applescript that works like a screensaver?

Hi Bob,

The mouse thing used to happen on my other computer. What I did was turn the mouse upside down. I eventually got a wireless.

gl,


Kel

Offline

 

#22 2006-06-15 01:48:47 am

bob
Member
Registered: 2005-08-29
Posts: 25

Re: Possible to make a applescript that works like a screensaver?

Wraagh.... feel like an idiot..... found what caused the problem preventing my machine falling in sleep mode...it was Salling Clicker Device Preferences...had the option "keep computer awake" on.......

Now it works fantastic...... thank you all for your help.

Greetings

Bob

Last edited by bob (2006-06-15 01:49:15 am)

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)