Re: parent properties - [it's your breath...let's talk scope]
Re: parent properties - [it's your breath...let's talk scope]
- Subject: Re: parent properties - [it's your breath...let's talk scope]
- From: What does not kill you only makes you stronger <email@hidden>
- Date: Sun, 04 Feb 2001 22:33:25 -0600
on 02/04/01 9:49 PM, email@hidden wrote:
>
If you've sweated for weeks over a script which automates your website
>
updates, odds are there's a number of handlers which could be generalized
>
and reused. The obvious thing to do would be to pluck these out, pepper
>
with comments, add a version resource, a brief header, and a read me file,
>
uploading it somewhere so that when another user wants to do something
>
similar, they have to option to build on what you've already done, simply
>
by a sticking the file in their additions folder or library folder.
Here is one example of something I have been using for my own internal
scripts for awhile now. They make my life a ton easier.. (Watch those line
wraps, etc.. ;-)
--Save below as a run only script named: txtLib.library. If you really want
you can use your friend ResEdit to delete all resources except of type
"scpt" and change the file type to "shlb". <shrug> I usually add a "vers"
resource to keep life simpler, and I suppose the kHelp() handler should
return a version number also.. Oh well.
*************************************************************
global kConvertedDateTime
global kCurrentDateTime
property kMonths : {{"jan", "01"}, {"feb", "02"}, {"mar", "03"}, {"apr",
"04"}, {"may", "05"}, {"jun", "06"}, {"jul", "07"}, {"aug", "08"}, {"sep",
"09"}, {"october", 10}, {"nov", 11}, {"dec", 12}}
on kOutputData(addDateSlug, kNoteName, kNoteLocation, kNoteInput)
tell application "Finder"
if file kNoteName of (kNoteLocation as alias) exists then
set logfile to file kNoteName of (kNoteLocation as alias)
else
set logfile to make file at (kNoteLocation as alias) with
properties {name:kNoteName}
end if
end tell
if addDateSlug = true then
my kDateSlug()
end if
try
set fileRef to open for access logfile with write permission
on error
close access logfile
set fileRef to open for access logfile with write permission
end try
if addDateSlug = true then
write (kNoteInput & kCurrentDateTime) & return to fileRef starting
at (get eof of logfile) + 1
else if addDateSlug = false then
write kNoteInput & return to fileRef starting at (get eof of
logfile) + 1
end if
close access fileRef
end kOutputData
on kDateSlug()
set kCurrentDate to current date
set kStandardAdditionsMonth to month of (kCurrentDate) as string
repeat with akMonth in kMonths
if kStandardAdditionsMonth starts with (item 1 of akMonth) then
set KMonth to item 2 of akMonth
exit repeat
else
set KMonth to kStandardAdditionsMonth --error
end if
end repeat
set KYear to items -2 through length of (year of (kCurrentDate) as
string)
set KDay to day of (kCurrentDate) as string --(current date) as string
if (count of every character of KDay) = 1 then
set KDay to "0" & KDay
end if
set KTime to characters length through -11 of (kCurrentDate as string)
if KTime starts with " " then set item 1 of KTime to 0
set kCurrentDateTime to " " & KMonth & "/" & KDay & "/" & KYear & "/" &
KTime as string
end kDateSlug
on kConvertDateSlug(kInput)
set kStandardAdditionsMonth to month of (kInput) as string
repeat with akMonth in kMonths
if kStandardAdditionsMonth starts with (item 1 of akMonth) then
set KMonth to item 2 of akMonth
exit repeat
else
set KMonth to kStandardAdditionsMonth --error
end if
end repeat
set KYear to items -2 through length of (year of (kInput) as string)
set KDay to day of (kInput) as string --(current date) as string
if (count of every character of KDay) = 1 then
set KDay to "0" & KDay
end if
set KTime to characters length through -11 of (kInput as string)
if KTime starts with " " then set item 1 of KTime to 0
set kConvertedDateTime to " " & KMonth & "/" & KDay & "/" & KYear & "/"
& KTime as string
end kConvertDateSlug
on kHelp()
return "txtLib.library v1.4
my kOutputData(addDateSlug,kNoteName, kNoteLocation, kNoteInput)--handler to
include
addDateSlug--adds optional date/time slug at end of string (true or
false)
kNoteName--text file name
kNoteLocation--text file location
kNoteInput--text you want written
my kConvertDateSlug(kInput)--handler to include
kInput--date to send (ex: last modified date)
returns kConvertedDateTime
" as string
end kHelp
*************************************************************
Place the file txtLib.library in the same folder as your script editor, and
run the following script below. (A better solution may be to put the file
txtLib.library in "Mac HD:System Folder:Scripts:Libraries:txtLib.library"
but I prefer to keep these types of files in the same folder as the
application that will be using them - for portability reasons. No whoops,
sorry, I forget to send the lib files -- Out of sight, out of mind..
Oh, one more thing: If you check the "Show Event Results" in the Event Log
in Script Editor, you WILL get an error trying to run the script below.
<Finger got an error: Source not available.>
*************************************************************
property kIOLIb : {}
property kNoteLocation : {}
property kNoteName : "kTestNote.txt"
on run
tell application "Finder"
set kAppPath to container of (path to me) as string
set kNoteLocation to kAppPath
set kIOLIb to load script (kAppPath & "txtLib.library" as string) as
alias
end tell
set y to my kHelp() of kIOLIb --get help
my kOutputData(true, kNoteName, kNoteLocation, y) of kIOLIb
end run
*************************************************************
I intentionally left out exactly what this script does, thats for you to
figure out. Feel free to comment on what you like and don't like.
Constructive feedback is wonderful..
-- 6E38