Simple applescript help

Joined
Dec 28, 2009
Messages
3
Reaction score
0
Points
1
Hey folks, I'm a php dev who has fumbled in here and needs a little assistance.

My issue is pretty simple, I need to track the user, time logged on and time logged off on a mac.

My basic script looks like this

logon:
Code:
do shell script "whoami  >> $MacHD/LogApplicationUse/OpenDoc.txt"
do shell script "date  >> $MacHD/LogApplicationUse/OpenDoc.txt"

logoff

Code:
#!/bin/bash
osascript -e 'do shell script "date  >> $MacHD/LogApplicationUse/OpenDoc.txt"'
osascript -e 'do shell script "var=out; echo $var >> $MacHD/LogApplicationUse/OpenDoc.txt"'

This works great for output like this:

user
time in
time out
user
time in
time out

But I'd really like it in this format:

user, time in, time out
user, time in, time out

I started goofing around and came up with this (untested):

Code:
set user to do shell script "whoami"
set log_in to do shell script "date"
set line to user & ", " & log_in ", "
do shell script "line >> $MacHD/LogApplicationUse/OpenDoc.txt"

for my login, which should get me halfway, but even if it works, I'm still stuck with my logout script starting on a new line:

user, time in,
time out
user, time in,
time out

Can someone point me in the right direction here?

> will write over the existing data
>> will append, but it does so with a carriage return
 
OP
D
Joined
Dec 28, 2009
Messages
3
Reaction score
0
Points
1
Wow, so either I'm so far out there no one is following my question, or this is much more difficult than I expected.
 

Slydude

Well-known member
Staff member
Moderator
Joined
Nov 15, 2009
Messages
17,596
Reaction score
1,072
Points
113
Location
North Louisiana, USA
Your Mac's Specs
M1 MacMini 16 GB - Ventura, iPhone 14 Pro Max, 2015 iMac 16 GB Monterey
You might find a bit more help with the scripting at MacScripter.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top