home *** CD-ROM | disk | FTP | other *** search
/ Macwelt 1 / Macwelt DVD 1.toast / Web-Publishing / HTML-Editoren / Alpha ƒ / Mode Examples / AppleScript-Example.script < prev    next >
Encoding:
Text File  |  2000-10-30  |  5.0 KB  |  146 lines

  1. -- AppleScript-Example.script
  2. -- 
  3. -- Included in the Alpha distribution as an example of the Scrp mode
  4.  
  5. -- This applescript is included in the standard Macintosh Operating System,
  6. -- and can be found in the system folder, at
  7. --
  8. -- System Folder:Help:Mac Help:fp:shrd:SetKeyboardSwitching
  9. --
  10. -- It allows the user to switch the key-binding for the "Application Switcher", 
  11. -- which some Alpha users find indispensable.
  12. --
  13. -- (Alpha has traditionally used command-tab for electric completions.)
  14.  
  15.  
  16. -- Turn keyboard switching on or off and set the keyboard shortcut.
  17. -- By James Rodden, © Apple Computer, Inc, 1998
  18.  
  19. -- setting up localizable dialog strings
  20. set dialog1Text to "Would you like to use a keyboard shortcut to switch applications?  A keyboard shortcut is currently "
  21. set dialog2Text to "Which modifier key would you like to use?"
  22. set dialog3Text to "Would you like to change the keyboard shortcut?"
  23. set dialog4Text to "Enter the key that you would like to use to switch applications " & ¬
  24.     "(any single character or \\t for Tab)."
  25.  
  26. set enabledText to "turned on."
  27. set disabledText to "turned off."
  28.  
  29. set keyboardShortcutPrefix to "The current keyboard shortcut is "
  30. set errorString to "Changing the keyboard shortcut was unsuccessful."
  31. set bookPath to "Help:Mac Help:"
  32. set shrdPath to "shrd:"
  33. set ErrorDialogLibName to "ErrDialogLib"
  34. -- end localized text strings
  35.  
  36. set systemPath to path to system folder as string
  37. set ErrDialogLibPath to (systemPath & bookPath & shrdPath & ErrorDialogLibName)
  38. set ErrDialogLib to ""
  39.  
  40. global cmdKeyText, cntrlKeyText, optionKeyText, tabKeyText
  41.  
  42. set tabKeyText to "Tab"
  43. set cmdKeyText to "Command"
  44. set cntrlKeyText to "Control"
  45. set optionKeyText to "Option"
  46.  
  47. set cancelBtnText to "Cancel"
  48. set yesBtnText to "Yes"
  49. set noBtnText to "No"
  50. set okBtnText to "OK"
  51.  
  52. ---------------------------------------
  53. -- Enable/Disable keyboard switching?
  54. try
  55.     tell application "Application Switcher"
  56.         if (keyboard cycling active) then
  57.             set dialog1Text to dialog1Text & enabledText
  58.         else
  59.             set dialog1Text to dialog1Text & disabledText
  60.         end if
  61.     end tell
  62. on error errMsg number errNum
  63.     if ErrDialogLib = "" then set ErrDialogLib to load script file ErrDialogLibPath
  64.     tell ErrDialogLib to displayError(errMsg, errNum)
  65.     return
  66. end try
  67.  
  68. set response1 to display dialog dialog1Text ¬
  69.     buttons {cancelBtnText, noBtnText, yesBtnText} default button yesBtnText
  70.  
  71. try
  72.     if (the button returned of response1 is yesBtnText) then
  73.         -- Make keyboard cycling active
  74.         tell application "Application Switcher"
  75.             set the keyboard cycling active to true
  76.         end tell
  77.         
  78.         -- Change keyboard shortcut?
  79.         set response2 to display dialog ¬
  80.             (dialog3Text & return & keyboardShortcutPrefix & GetKeystrokeAsString() & ".") ¬
  81.                 buttons {noBtnText, yesBtnText} default button yesBtnText
  82.         
  83.         if (the button returned of response2 is yesBtnText) then
  84.             -- Select modifier key
  85.             set modifierKey to display dialog dialog2Text ¬
  86.                 buttons {cmdKeyText, cntrlKeyText, optionKeyText}
  87.             
  88.             -- Select activation key
  89.             set theString to the text returned of ¬
  90.                 (display dialog dialog4Text default answer "")
  91.             
  92.             tell application "Application Switcher"
  93.                 set theKey to character 1 of theString
  94.                 if (theKey is "\\") and (the number of characters of theString > 1) and ¬
  95.                     (character 2 of theString is "t") then set theKey to tab key
  96.                 
  97.                 if the button returned of modifierKey is cmdKeyText then
  98.                     set modifierKey to command down
  99.                 else if the button returned of modifierKey is cntrlKeyText then
  100.                     set modifierKey to control down
  101.                 else if the button returned of modifierKey is optionKeyText then
  102.                     set modifierKey to option down
  103.                 end if
  104.                 
  105.                 set the cycling keystroke to {key:theKey, modifiers:modifierKey}
  106.             end tell
  107.             
  108.             -- Report results
  109.             display dialog (keyboardShortcutPrefix & GetKeystrokeAsString() & ".") ¬
  110.                 buttons {okBtnText} default button okBtnText
  111.         end if
  112.     else if (the button returned of response1 is noBtnText) then
  113.         -- Make keyboard cycling inactive
  114.         tell application "Application Switcher" to set the keyboard cycling active to false
  115.     end if
  116. on error
  117.     display dialog errorString buttons {okBtnText} default button okBtnText with icon 0
  118. end try
  119.  
  120. on GetKeystrokeAsString()
  121.     set keystrokeString to ""
  122.     
  123.     tell application "Application Switcher"
  124.         set theKeystroke to the cycling keystroke
  125.         
  126.         set prefixString to ""
  127.         if (the modifiers of theKeystroke contains command down) then
  128.             set keystrokeString to keystrokeString & prefixString & cmdKeyText
  129.             set prefixString to "-"
  130.         end if
  131.         if (the modifiers of theKeystroke contains control down) then
  132.             set keystrokeString to keystrokeString & prefixString & cntrlKeyText
  133.             set prefixString to "-"
  134.         end if
  135.         if (the modifiers of theKeystroke contains option down) then
  136.             set keystrokeString to keystrokeString & prefixString & optionKeyText
  137.             set prefixString to "-"
  138.         end if
  139.         
  140.         set theKey to the key of theKeystroke
  141.         if (theKey is tab key) then set theKey to tabKeyText
  142.         set keystrokeString to keystrokeString & prefixString & theKey
  143.     end tell
  144.     
  145.     return keystrokeString
  146. end GetKeystrokeAsString