home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1997 February / macformat-047.iso / Shareware Plus / Developers / CLImax 1.0 / AppleScript and CLImax / Advanced AppleScript / Useful Stuff < prev   
Encoding:
Text File  |  1996-11-07  |  3.8 KB  |  174 lines  |  [TEXT/ttxt]

  1. (*
  2.     CLImax: Useful tricks
  3.     This program is $15 shareware.
  4.  
  5.  
  6.     Want CLImax to turn really useful, really quick? Select all or part of this file, drag-and-drop the
  7.     text onto CLImax, hit return, and you'll automatically get all of the variables, references, and
  8.     handlers given here!
  9.  
  10.     Anything that is preceded by a double hyphen (--) or surrounded by parentheses with asterisks
  11.     will be treated as a comment by AppleScript and not executed.  Yes, this entire file is a perfectly
  12.     legal AppleScript, and it won't do anything nasty. :-)
  13.  
  14. *)
  15.  
  16.  
  17. -- Useful Shortcuts
  18. -- ____________________________________________________
  19. ------------------------------------------------------------
  20.  
  21. -- making AppleScript less verbose
  22. set fw to ref front window
  23. set abm to ref about this macintosh
  24. set mem to file "memory" of control panels folder
  25. set views to file "views" of control panels folder
  26.  
  27.  
  28. -- variables for applications and remote machines
  29. set finder to app "Finder"
  30. set climax to app "CLImax"
  31. set rezcop to machine "rezcop"
  32. set gallagher to machine "Gallagher" of zone "umich-ENG-CAEN Admin"
  33. set gallagherf to application "Finder" of gallagher
  34.  
  35.  
  36. (*
  37.  
  38. -- saving window sets
  39. set x to close windows   -- temporarily saves the list of open windows while you do something else
  40. open x                   -- then restores whatever windows you had open, in the proper order
  41. set ws1 to windows       -- save frequently-used window sets in a variable and open them later!
  42.  
  43.  
  44. -- general tricks
  45. delete selection         -- in the Finder, if a window is covering the trash...
  46.  
  47.  
  48. *)
  49.  
  50.  
  51.  
  52.  
  53. --
  54. -- Handy Handlers
  55. -- ____________________________________________________
  56. ------------------------------------------------------------
  57.  
  58. -- -- -- -- -- -- -- -- --  Who needs drag and drop when you've got a command line?
  59. on ctc( t, c )
  60.  tell finder to set file type of selection to t
  61.  tell finder to set creator type of selection to c
  62. end ctc
  63.  
  64.  
  65. -- -- -- -- -- -- -- -- --  the inverse of ctc, returns the type and creator of the selection.
  66. on tc()
  67.  tell app "Finder"
  68.   set n to count files of selection
  69.   if n is 0 then return "No files selected."
  70.   set t to file type of files of selection
  71.   set c to creator type of files of selection
  72.   if n is 1 then return {t,c}
  73.   -- else do some more processing
  74.   set r to {}
  75.   repeat with x from 1 to n
  76.    set r to r & {{item x of t, item x of c}}
  77.   end repeat
  78.   return r
  79.  end tell
  80. end tc
  81.  
  82.  
  83. -- -- -- -- -- -- -- -- -- I whipped these up while writing CLImax's documentation...
  84. on edit()
  85.  ctc("TEXT","ttxt")
  86.  tell app "Finder" to open selection
  87.  tell app "CLImax" to hide window
  88. end edit
  89.  
  90.  
  91. on ttro()
  92.  ctc("ttro","ttxt")
  93. end ttro
  94.  
  95.  
  96.  
  97. -- -- -- -- -- -- -- --  miscellaneous shortcuts
  98.  
  99. on frontapp()
  100.   tell finder to set x to processes whose frontmost is true
  101.   if x is {} then set x to finder
  102.   return x
  103. end
  104.  
  105. on cfiles()
  106.   tell app "Finder" to return (files of front window whose name ends with ".c")
  107. end
  108.  
  109. on textfiles()
  110.   tell finder to return (files of fw whose file type is "TEXT")
  111. end
  112.  
  113. -- try this: put away servers()
  114. on servers()      
  115.   tell finder to return (disks whose local volume is false)
  116. end servers
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125. (*
  126.    build( projectList )
  127.  
  128.    This handler accepts a list of project file
  129.    aliases, and will tell CodeWarrior to build
  130.    each of them in the order they appear in the list.
  131.    At the end of the build it will re-open whatever
  132.    project was open at time of invocation.  I actually
  133.    used this script while developing CLImax.
  134.  
  135.  
  136. to build( projectList )
  137.  tell app "CodeWarrior IDE 1.6"
  138.   activate
  139.   set oldProject to Get Project Specifier
  140.  
  141.   repeat with x in projectList
  142.    open x
  143.    Make Project
  144.   end repeat
  145.    
  146.   if (oldProject as text) isn't "" then open oldProject
  147.  end tell
  148.  "Successful."
  149. end build
  150.  
  151. *)
  152.  
  153.  
  154.  
  155.  
  156. -- closing remarks
  157. return "AppleScript is the bestest language EVER!"
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170. -- Remember to register CLImax.  :-)
  171. -- Have a nice day.
  172.  
  173.  
  174.