Le 2015/11/20 à 20:26, Stan Cleveland < email@hidden> a écrit :
On Nov 20, 2015, at 02:12 AM, S. J. Cunningham <email@hidden> wrote:
I need an app to audit my scripts. In particular I would like something which prepares a Design Report showing all handlers and lists any external properties they use and conversely, shows for each property and global which handlers use them and which are declared but never used. Probably other things too. Something like what File Maker's Design Report does.
I though't I'd ask if anyone has or knows of one before i invest time in writing my own.
Hi Steve, Smile[1], the free AppleScript programming environment from Satimage, has a 'validate' command. This command will, according to them, "find undefined variables (you made a typo) and unused variables (you forgot something)." While this falls far short of your very-ambitious ideas, it IS a starting point. I must commend Satimage for achieving something that’s niether simple nor easy. I work primarily with Script Debugger[2], so have written a script that grabs the frontmost Debugger script, invokes the Smile 'validate' command and parses the result to generate a report that includes the line numbers in which errant variables appear. It could probably be repurposed to work with Script Editor, rather than Debugger. If anyone would like a copy of it let me know off list. (If I get many requests, I may just post it here to save time.) Steve, I wish you well in your Design Report project—it’s a worthy, if difficult, goal. I, and others here, will be interested to see what you come up with. Regards, Stan C. ______ [1] See http://www.satimage.fr/software/en/smile/index.html[2] See http://www.latenightsw.com
As it’s easy for a script saved as an application to open a script and export it as .applescript file, I started with such a file.
The script below build a list of the declared properties and a list of the defined handlers (minus possible run and open ones).
set theScript to (path to desktop as text) & "work in progress 1.applescript" as alias
set itsText to read theScript as «class ut16»
set theProperties to {}
set maybe to my decoupe(itsText, "property ")
repeat with i from 2 to count maybe set maybe2 to my decoupe(maybe's item i, space) if item 2 of maybe2 starts with ":" then set end of theProperties to item 1 of maybe2 end if end repeat theProperties # List of declared properties
set theHandlers to {} set maybe to my decoupe(itsText, linefeed & "on ") repeat with i from 2 to count maybe set maybe2 to maybe's item i if (maybe2 does not start with "run") and maybe2 does not start with "open" then set end of theHandlers to item 1 of my decoupe(maybe2, "(") end if end repeat
theHandlers # list of handlers
#=====
on decoupe(t, d) local oTIDs, l set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d} set l to text items of t set AppleScript's text item delimiters to oTIDs return l end decoupe
#=====
Yvan KOENIG running El Capitan 10.11.1 in French (VALLAURIS, France) vendredi 20 novembre 2015 21:11:25
|