Hi there
New here (to Macs, not just applescripts). Very new. Just found out what applescripts are yesterday.
Immediately I had a wonderful idea…
I would like to have a script that checks if my WORK screen name is signed on, then checks if I am currently engaged in a conversation with someone, and then checks (most importantly) if it is between 9 and 5. If not, it would sign me off.
Otherwise, if it is not signed on, it would check and see if it is between 9 and 5, and sign me on if that is the case and my computer is not idle.
I unfortunately cannot figure it out just yet, I have tried, and I of course have no background in programming, but here is the basic logic of the program…
tell application "iChat"
if service "workSN" is not Offline then --check to see if that SN is online, but my status may not be "available"... so... if it's anything but OFFLINE
repeat every 5 minutes
if idle time > 5 minutes then --see if I'm idle (But I want this "idle" to be whether or not I am speaking to someone with workSN, regardless of my personalSN)
if current time is less than 9 or current time is greater than 17 then --check the time
tell application iChat
log out "workSN"
end tell
else (*do nothing*)
end if
end if
end repeat
else if service "workSN" is Offline then
repeat every 5 minutes
if current day is not Sunday then --(no work on sundays!)
if current time is greater than 9 and current time is less than 17 then --check that it's work hours
tell application iChat
log in "workSN"
end tell
end if
end if
end repeat
end if
end tell
And that’s about as close as I can come… Maybe some of you can instruct me? This is far too ambitious a project for a beginner, I know!
Comments:
-I think the way to define the “idle” is to check when the last message was sent by me, and if it was over 5 minutes ago, I’ve probably finished working for the day…
-How do you code in something that will disregard this script if I manually sign in, so that if I manually sign OFF on a monday afternoon because I am too busy, it will not auto sign me in?
Thanks in advance!
Model: Macbook Pro Aluminum
AppleScript: Latest?
Browser: Firefox 3.0.4
Operating System: Mac OS X (10.5)
try this, save the script as stay open application.
idleTime is the real system idle time
property workSN : "myWorkSN"
on idle
tell application "iChat" to tell service workSN to set isOnline to enabled and status is connected
tell (current date) to set {hr, wk} to {its hours, weekday}
if isOnline and hr < 9 and hr > 17 then
set idleTime to (do shell script "ioreg -c IOHIDSystem | perl -ane 'if (/Idle/) {$idle=(pop @F)/1000000000; print $idle,\"\";last}'") as integer
if idleTime > 5 * minutes then tell application "iChat" to log out service workSN
else if not isOnline and wk is not Sunday and hr > 9 and hr < 17 then
tell application "iChat" to log in service workSN
end if
return 300
end idle
So a) how do i use it and b) will it sign off if the PC is not idle (I am chatting on my personal SN) but i haven’t sent a message in a while using WorkSN?
a) as mentioned above save it as stay open application and just run it
b) which PC? The given idle time is global idle time of the OS, not of iChat
To make sure, that the script affects only the work account, I added a line
property workSN : "myWorkSN"
on idle
tell application "iChat" to tell service workSN to set {workIsEnabled, workIsOnline} to {enabled, status is connected}
if workIsEnabled then
tell (current date) to set {hr, wk} to {its hours, weekday}
if workIsOnline and hr < 9 and hr > 17 then
set idleTime to (do shell script "ioreg -c IOHIDSystem | perl -ane 'if (/Idle/) {$idle=(pop @F)/1000000000; print $idle,\"\";last}'") as integer
if idleTime > 5 * minutes then tell application "iChat" to log out service workSN
else if not workIsOnline and wk is not Sunday and hr > 9 and hr < 17 then
tell application "iChat" to log in service workSN
end if
end if
return 300
end idle
Would you kindly explain to me what the above mentioned line of code is doing? It seems interesting, but my Perl powers are still low and I don’t understand it.
So I’d like to know though, is there any way to do this so that it goes based on the idle time of the work SN, not the system? Sometimes I am still active on my computer, but not on the work SN, which means I would want it to sign off if it’s not work hours!