I need to make an app that starts recording the time since login, then automatically opens a screen at the end to bill for that time (maybe I just provide a link to a website where the credit card info can be added)?
Essentially, it’s billing someone for the time they use the computer (like you would see at a Kinkos/Fedex, but for Mac).
Here’s an example:
User will login to the public computer this software would be used on;
This program then starts counting the elapsed time since the login (runs in the background, and can not be turned off);
When the person is ready to log off, they click the “log-off” button on this software, which then brings them to the billing screen (maybe even open a website link where billing can be done - whichever is easier);
The system then automatically inputs the time the computer was used, and calculates the total;
User then enters CC information, and clicks submit. After the payment is processed successfully, the computer runs a program to delete all files and downloads user installed, and logs the computer off.
I think it’s pretty simple. I looked around online to find software that does this (or for various components of applescript that would eventually make this software when pieced together), but have had no luck. Is anyone here able to do this? Are you aware of software that already exists that does this (for Mac, obviously)? Thank you in advance!
What if the users uses the terminal, looks up the process, kills it and start it right before he ends his session. Instead of hours only a few minutes are recorded.
AppleScripts is no saint and it can crash, what should you do then?
If the AppleScript is managed by launchd to tackle down problem #2, the recorded time is still not accurate because it will quit and restarts processes by its own will (to make Mac OS X look faster than other OS’es).
What to do with fast user switching?
You can cancel out the login by creating an process where the delegate method applicationShouldTerminate: returns false but what do you do when the user force quits? The user won’t see a recording screen and can logout for free. Re-login will reset the timer to 0.
What if the users halts the system?
What if an kernel panic occurs (Mac OS X’s version of BSOD)?
These are common problem when you see in practice and therefore internet cafes uses different solutions.
I agree with DJ that getting this right would be a significant programming project, not a quick Applescript.
Unless you want to hire a team of developers for months, you want something off-the-shelf. Do more Googling. It didn’t take me long to find some possibilities:
Those programs seem to be more for online use. I need the entire computer (not just the internet) use billable. Say someone wants to create a Word document. That needs to be billed time while logged in. What am I missing from my google searches?
I agree also that this has got lots of ifs and buts to it but I put this script together that I think should cover points 1-3 of the original post:
set currUser to do shell script "whoami"
set loginTime to do shell script "w -h " & currUser & " | awk '{print $4}' | awk 'NR==1{print}'"
set currDateString to date string of (current date)
set fullLoginTime to date (currDateString & " at " & loginTime)
set loginSeconds to (current date) - fullLoginTime
---------------------------------------------this part is credit to StefanK http://macscripter.net/viewtopic.php?id=43844---------------------------------------------
set totalLoginTime to secondsToHMS from loginSeconds
display dialog currUser & " has been logged in for " & totalLoginTime
on secondsToHMS from theSeconds
tell theSeconds to return my pad(it div hours) & ":" & my pad(it mod hours div minutes) & ":" & my pad(it mod minutes)
end secondsToHMS
on pad(v)
return text -2 thru -1 of (v + 100 as text)
end pad
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
It seems to work fine for points 1-3. Thank you! I’ll see what else I can piece together for the rest (if anything), and will try to remember to post back. lol