Login AppleScript won't write to file - UPDATE
Login AppleScript won't write to file - UPDATE
- Subject: Login AppleScript won't write to file - UPDATE
- From: "Timothy K. Wilkinson" <email@hidden>
- Date: Fri, 29 Jun 2001 08:28:26 -0400
I tried to only include the area (I thought) was the trouble area in my
previous post. Obviously if it won't compile then no one can help! Here is
the entire code. Thanks already to those who have responded. I hope this
makes things a little clearer. I am using the OSAX "Date String For" in
this script.
Thanks again!
Tim Wilkinson
ITC-ACHS
University of Virginia
email@hidden
email@hidden
-----Begin Script-----------
--get the name of the computer
set cname to (computer name) as string
--check to see if the volume with the log file is mounted and mount it if
not
tell application "Finder"
if not (exists disk "Data") then
mount volume "Data" on server "ourserver" as user name cname with
password "serverpassword"
end if
end tell
--set the path to the log file
set loginFile to "
Data:log:lablogin.txt"
--set a flag to check if the email is a UVA ID
set idFlag to ""
with timeout of 1814400 seconds
repeat until idFlag is "true"
display dialog "Please enter your UVA Computing ID:" default answer
"" buttons "OK" default button "OK"
set userID to text returned of result as text
--checks to make sure the ID is valid
set idCount to (count of userID)
set the disallowed_characters to {"0", "1", "2", "3", "4", "5", "6",
"7", "8", "9"}
if idCount > 6 or userID = "" or idCount < 2 or (userID = cname) or
character 1 of userID is in the disallowed_characters or character 2 of
userID is in the disallowed_characters or ,
character idCount of userID is in the disallowed_characters then
display dialog "Please enter a UVA Computing ID" & return &
"Example: abc2d" buttons "OK" default button "OK"
set idFlag to "false"
else
set idFlag to "true"
end if
end repeat
set cname to (computer name) as text
--this call uses the OSAX "date string for"
set cDate to date string for (current date) in short format
set the cTime to my format_time_using(the current date, ":", {"HH",
"MM", "SS"})
set login_time to (cDate & space & cTime) as text
--writes all the information to loginData
set loginData to ("login" & " " & userID & " " & cname & " " &
cname & " " & login_time & (ASCII character 13) & (ASCII character 10))
as text
--writes the information to a text file as tab-delimited
write loginData to file loginFile starting at eof
end timeout
--subroutine for converting the time to the HH:MM:SS format
on format_time_using(this_date_record, delimiter_string, format_list)
set the time_index to the time of this_date_record
set the hour_index to ((the time_index) / hours) div 1
set the minute_index to ,
(((the time_index) / minutes) - (the hour_index * 60)) div 1
set the seconds_index to ,
((the time_index) - (the hour_index * 3600) - (the minute_index *
60)) div 1
set the formatted_time to ""
-- count the number of items in the list
set the item_count to the count of the format_list
-- parse the format list
repeat with i from 1 to the item_count
set this_item to item i of the format_list
if this_item is "H" then
set the formatted_time to ,
the formatted_time & the hour_index as string
else if this_item is "HH" then
if the hour_index is less than 10 then ,
set hour_index to ,
("0" & (the hour_index as string))
set the formatted_time to ,
the formatted_time & hour_index as string
else if this_item is "M" then
set the formatted_time to ,
the formatted_time & the minute_index as string
else if this_item is "MM" then
if the minute_index is less than 10 then ,
set minute_index to ,
("0" & (the minute_index as string))
set the formatted_time to ,
the formatted_time & minute_index as string
else if this_item is "S" then
set the formatted_time to ,
the formated_time & the seconds_index as string
else if this_item is "SS" then
if the seconds_index is less than 10 then ,
set seconds_index to ,
("0" & (the seconds_index as string))
set the formatted_time to ,
the formatted_time & seconds_index as string
end if
if i is not the item_count then
-- add delimiter
set the formatted_time to ,
the formatted_time & delimiter_string as string
end if
end repeat
return the formatted_time
end format_time_using
---------End Script----------------