Forums
New posts
Articles
Product Reviews
Policies
FAQ
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Menu
Log in
Register
Install the app
Install
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
Simple applescript help
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Doc Thirst" data-source="post: 969376" data-attributes="member: 137513"><p>Hey folks, I'm a php dev who has fumbled in here and needs a little assistance.</p><p></p><p>My issue is pretty simple, I need to track the user, time logged on and time logged off on a mac.</p><p></p><p>My basic script looks like this</p><p></p><p>logon:</p><p>[CODE]</p><p>do shell script "whoami >> $MacHD/LogApplicationUse/OpenDoc.txt"</p><p>do shell script "date >> $MacHD/LogApplicationUse/OpenDoc.txt"[/CODE]</p><p></p><p>logoff</p><p></p><p>[CODE]#!/bin/bash</p><p>osascript -e 'do shell script "date >> $MacHD/LogApplicationUse/OpenDoc.txt"'</p><p>osascript -e 'do shell script "var=out; echo $var >> $MacHD/LogApplicationUse/OpenDoc.txt"'[/CODE]</p><p></p><p>This works great for output like this:</p><p></p><p>user</p><p>time in</p><p>time out</p><p>user</p><p>time in</p><p>time out</p><p></p><p>But I'd really like it in this format:</p><p></p><p>user, time in, time out</p><p>user, time in, time out</p><p></p><p>I started goofing around and came up with this (untested):</p><p></p><p>[CODE]set user to do shell script "whoami"</p><p>set log_in to do shell script "date"</p><p>set line to user & ", " & log_in ", "</p><p>do shell script "line >> $MacHD/LogApplicationUse/OpenDoc.txt"[/CODE]</p><p></p><p>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:</p><p></p><p>user, time in, </p><p>time out</p><p>user, time in, </p><p>time out</p><p></p><p>Can someone point me in the right direction here?</p><p></p><p>> will write over the existing data</p><p>>> will append, but it does so with a carriage return</p></blockquote><p></p>
[QUOTE="Doc Thirst, post: 969376, member: 137513"] 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"[/CODE] 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"'[/CODE] 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"[/CODE] 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 [/QUOTE]
Verification
Post reply
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
Simple applescript help
Top