Advertisement
applehelpwriter

CLI Tools Summary Script

Jul 2nd, 2016
895
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # From: http://applehelpwriter.com/2016/07/02/learning-the-terminal-part-three/
  2. # start
  3. (*
  4. This script produces a summary of all the CLI tools
  5. in /usr/bin and displays it in a text document
  6. *)
  7. set noDocsList to {}
  8. on extractDescription(aText)
  9.     repeat with i from 1 to count of items in aText
  10.         set this_item to item i of aText
  11.         if this_item contains "NNAAMMEE" then
  12.             set r to item (i + 1) of aText
  13.             try
  14.                 set o to offset of "—" in r
  15.                 set short_r to text (o + 1) thru -1 of r
  16.                 set r to short_r
  17.             end try
  18.             return r
  19.         end if
  20.     end repeat
  21. end extractDescription
  22. set theDescriptions to return & return & "**********************************" & return & "SUMMARY OF CLI TOOLS (Version 2)" & return & "**********************************" & return & return & return
  23. tell application "System Events"
  24.     set theItems to name of every file of folder "bin" of folder "usr" of startup disk
  25. end tell
  26. repeat with i from 1 to count of theItems
  27.     set this_item to item i of theItems
  28.     set n_item to length of this_item
  29.     try
  30.         set what_is to do shell script "whatis " & this_item
  31.         if text 1 thru n_item of what_is is this_item and what_is does not contain "nothing appropriate" then
  32.             set theDescriptions to theDescriptions & return & what_is & return
  33.         else
  34.             try
  35.                 set getMan to paragraphs of (do shell script "man " & this_item)
  36.                 set desc to extractDescription(getMan)
  37.                 set what_is to this_item & tab & tab & tab & tab & desc
  38.                 set theDescriptions to theDescriptions & return & what_is & return
  39.             on error
  40.                 set end of my noDocsList to this_item & return
  41.             end try
  42.         end if
  43.     end try
  44. end repeat
  45. set theApp to "TextEdit"
  46. tell application "Finder"
  47.     if exists POSIX file "/Applications/TextWrangler.app" then
  48.         set theApp to "TextWrangler"
  49.     end if
  50. end tell
  51. set theDescriptions to theDescriptions & return & return & return & "The following tools do not have any documentation: " & return & return & noDocsList
  52. tell application theApp
  53.     activate
  54.     make new document
  55.     set front document's text to my theDescriptions
  56. end tell
  57.  
  58. # EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement