Re: tab delimeted log file
Re: tab delimeted log file
- Subject: Re: tab delimeted log file
- From: Sander Tekelenburg <email@hidden>
- Date: Wed, 4 Apr 2001 16:41:15 +0200
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
At 00:28 -0400 UTC, on 04/04/2001, Brian wrote:
>
Forgive the blatant cry for help but I've noticed how generously many users
>
of this forum will offer snippets or complete scripts to help newbies like
>
myself out....
Posted scripts and/or snippets thereof are useful as examples only. If all
you need to do is copy & paste you'll never learn to do anything yourself and
remain dependant on others. You won't see any of that in this message. If
you're still interested, read on:
>
I've developed several simple scripts which I'm using as folder actions
>
currently to control the flow of graphics files in a multi-step production
>
environment and I've noticed that either user-error or network gremlins are
>
causing files to disappear well before they're completed. My current
>
scripts all follow the same basic pattern and work basically like this:
>
>
-- wraps got kind of ugly, sorry
>
on adding folder items to this_folder after receiving added_items
>
tell application "Finder"
>
mount volume "volume1" on server "GSI_NT-4" as user name ,
>
"name" with password "word" -- mount server
>
set move_list to (every file of this_folder whose label index ,
>
is not 3)
my makeLog(move_list)
>
move move_list to folder "In Stock" of folder "To Be Worked" ,
>
of disk "Volume1"
my CheckMove(move_list)
-- might be smart to do this a bit later on though
-- to give the Finder time enough to copy everything
>
select every item of this_folder
>
set label index of selection to 3
>
end tell
>
end adding folder items to
>
>
I'd like to institute some logging to provide error checking capabilities
>
to make sure everything is moving the way it's supposed to and so I can see
>
where in the process a file disappears. These log files would be
>
researched manually when need be and more than anything would have "CYA"
>
value if you get my meaning....although if they show a systemic error that
>
would also of course be beneficial.
>
>
My objective would be to develop is a script that can be added to the body
>
of my existing folder actions scripts that will (when an item is added to
>
the source folder and subsequently moved to its target) log the name of the
>
file, the current time and the destination folder to which it was
>
successfully duplicated.
(* Create a list of items that are to be moved; coerce it to text; coerce it
to tab delimited text *)
on makeLog(move_list)
set ToBeMoved to ""
repeat with i in move_list
set i to i as string -- coerce alias to string
set ToBeMoved to ToBeMoved & i & tab -- add filepaths to log text
end
end
(* Create a list of items that were not moved; coerce it to text; coerce it
to tab delimited text *)
on CheckMove(move_list)
set NotMoved to ""
repeat with i in move_list
tell app "Finder"
set itsName to name of i -- coerce alias to file name
set itsPath to "Volume1:To Be Worked:In Stock:" & itsName as alias
exists itsPath -- does file exist at new location?
set theExistence to the result
if theExistence is false -- file does not exist at new location
set NotMoved to NotMoved & i & tab -- add to list
end
end
end
end
>
Preferably this log file would be a tab delimited
>
text file whose name is something like "push log mm/dd/yy.txt"
This could be used to creat such a file name:
set theDate to {month, day, year} of (current date)
set LogName to "push log "
repeat with i in theDate
set LogName to LogName & i & "/"
end repeat
set LogName to LogName & ".txt"
Note that the month is a name. If you want it as number you'll need to write
some routine for that. More importantly: I think it's stupid to use such a
'proprietary' date notation. It causes confusion as not everybody on the
planet uses this notation. "April 4, 2001" is much clearer. If you must use
numbers, use "century/year/month/day". There is an ISO standard for date
notation: ISO 8601.
Now combine the above:
Tell the Finder to create a new file. You have its name in this variable:
LogName.
Then open it for access with write permission and write the log text to it
(check the Standard Additions' dictionary for how to write to a file). You
can choose to write either the variables ToBeMoved or NotMoved or both to it
- - whichever you prefer. Don't forget to close acces to the file again.
DISCLAIMER: None of this has been tested. There's bound to be some mistake in
there somewhere... The odd coercion mistake perhaps. Or I may have missed the
need to set 1 or 2 variables as globals. And of course you may want to place
something in a try block so you can catch errors.
You could also choose to not create a new log every time, but add to an
existing log. You'd then of course waht to use a different name for that log,
and add the date to every new log entry. This is what my shareware applet
"Disk Watcher" does. (Source code is locked, but you can run it and view the
log to see what's possible - just not how to do it ;))
Note that this is just one approach. Another could be to have the copy
command in a try block, catch every error, and add them to a list that you
can write to a log file. Might be somewhat less reliable though.
HTH
-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <
http://www.pgp.com>
iQA/AwUBOssyc+sywKfXgqKdEQImiQCfZ9NzPtfFrHKVN+qdPWpCIL/kFncAoIqt
esLIPy7A5efmC+trgoBcfIAu
=hPGg
-----END PGP SIGNATURE-----
--
Sander Tekelenburg, <
mailto:email@hidden>
Web site at <
http://www.euronet.nl/~tekelenb/>
Mac user: "Macs only have 40 viruses, tops!"
PC user: "SEE! Not even the virus writers support Macs!"