Re: Posting scripts (was more scoping aggravation)
Re: Posting scripts (was more scoping aggravation)
- Subject: Re: Posting scripts (was more scoping aggravation)
- From: "Stockly, Ed" <email@hidden>
- Date: Mon, 17 Jan 2011 13:05:48 -0600
- Acceptlanguage: en-US
- Thread-topic: Posting scripts (was more scoping aggravation)
On 1/17/11 6:48 AM, "tom wible" <email@hidden> wrote:
> i've got a utility lib, sammylib:
I'm sorry but this is truly a mess, and a much bigger issue, in my book,
than top posting.
If you're going to post a scripting question on this list, please, please,
please make your posted script sample easy to test and trouble shoot.
In this case, the script won't compile without files stored on the OP's
drive, which none of us have access to and has undefined variables which we
must assign values in order to run.
Even once the script is compiled, it requires a lot of moving bits around
just to make parts of it work, and that moving, in this case, obscures the
scoping issue.
What I do, and I learned from others posting on this list, is begin self
contained scrip portions thusly:
--------------
property newline : return
global resultMsg
set resultMsg to {}
--variables reslultMsg and newLine had no assigned value
write_log("MyMessage")
on write_log(msg)
log msg
try
set now to current date
set end of resultMsg to (now & " - " & msg & newline as string)
on error errText
set resultMsg to {now & " - " & msg & errText}
end try
end write_log
on clear_log()
set resultMsg to {}
end clear_log
on getResults()
return resultMsg as string
end getResults
--------------
Any remarks or comments that I might make are commented out. As are any
results of commands or the log entries added for clarity.
Basically, everything between the
--------------
Lines should be tested so that it could be in a script editor, compiled and
run.
If I'm offering two versions to illustrate a point, I handle them
separately.
--------------
property SAMMY_LIB : "" -- "/DVR/scripts/sammyLib.app"
property sammylib : "" --(load script POSIX file (SAMMY_LIB as string))
property tvpiSender : "Some Text"
property tvpiName : "Some Other Text"
property cmds : "Even more Text"
property interactive : true
--the variables tvpiSender,tvpiname and cmds were not defined in the OPs
script
on write_log(msg)
if interactive then ¬
display alert msg giving up after 20
sammylib's write_log(msg)
end write_log
on get_log()
return sammylib's getResults()
end get_log
on clear_log()
sammylib's clear_log()
end clear_log
write_log(tvpiSender & " - " & cmds)
display alert get_log() -- dbg
write_log(tvpiName)
display alert get_log() -- dbg
--------------
That said, after doing the work needed to have running versions of these two
scripts, I see no scoping issues.
The other point is that the sample script posted should have the fewest
commands and variables needed to illustrate the problem.
Just the quasi-scientific process of eliminating the variables may not only
help the OPs resolve the issues on their own, but make it easier for the
many experienced scripters on this list (most of whom have other things
going on in their lives) to reach a definitive answer.
I hope this helps and I hope it is taken in the spirit it is intended.
Please, help us help you!
ES
> ...
> global resultMsg
>
> on write_log(msg)
> log msg
> try
> set now to current date
> set end of resultMsg to (now & " - " & msg & newline as string)
> on error
> set resultMsg to {now & " - " & msg}
> end try
> end write_log
>
> on clear_log()
> set resultMsg to {}
> end clear_log
>
> on getResults()
> return resultMsg as string
> end getResults
> ...
> which i include & use:
>
> property SAMMY_LIB : "/DVR/scripts/sammyLib.app"
> property sammylib : (load script POSIX file (SAMMY_LIB as string))
> ...
> on write_log(msg)
> if interactive then ¬
> display alert msg giving up after 20
> sammylib's write_log(msg)
> end write_log
>
> on get_log()
> return sammylib's getResults()
> end get_log
>
> on clear_log()
> sammylib's clear_log()
> end clear_log
> ...
> write_log(tvpiSender & " - " & cmds)
> display alert get_log() -- dbg
> write_log(tvpiName)
> display alert get_log() -- dbg
>
> and here's what i get:
>
> (*airdrummer - tvpi2DVR:send2eyetv:runlonger =30*) -- the log in
> sammylib's write_log(msg)
> current date
> date "Monday, January 17, 2011 9:28:30 AM" -- the date in
> sammylib's write_log(msg)
> display alert "Monday, January 17, 2011 9:28:30 AM -
> email@hidden - tvpi2DVR:send2eyetv:runlonger =30"
> {button returned:"OK"}
> (*/Users/tomw/Desktop/program.tvpi*) -- the log in sammylib's
> write_log(msg)
> current date
> date "Monday, January 17, 2011 9:28:38 AM" -- the date in
> sammylib's write_log(msg)
> display alert "Monday, January 17, 2011 9:28:38 AM - /Users/tomw/
> Desktop/program.tvpi"
> {button returned:"OK"}
>
> please explain why resultMsg is local, not global as specified:-
> ( this used to work:
>
> Outsourced # Sari, Charlie # 4-1 # 10:30PM every Thu # 30mins
> Saturday, January 8, 2011 6:42:07 AM - airdrummer -
> tvpi2DVR:send2eyeTV:weekly
> Saturday, January 8, 2011 6:42:07 AM - /tmp/11_01_08__06_42_05-
> program.tvpi
> Saturday, January 8, 2011 6:42:07 AM - weekly
> Saturday, January 8, 2011 6:42:08 AM - persistSched:sent2eyetv
> Saturday, January 8, 2011 6:42:08 AM -
> resolveConflicts4etv:updateSchedList:#dirtyScheds=0
> Saturday, January 8, 2011 6:42:10 AM - crontab updated
>
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden