/core/externals/update-engine/externals/google-toolbox-for-mac/Foundation/GTMNSAppleScript+Handler.h

http://macfuse.googlecode.com/ · C++ Header · 132 lines · 34 code · 17 blank · 81 comment · 0 complexity · 7bbcd406d5523b294e8ba275a1659007 MD5 · raw file

  1. //
  2. // GTMNSAppleScript+Handler.h
  3. //
  4. // Copyright 2008 Google Inc.
  5. //
  6. // Licensed under the Apache License, Version 2.0 (the "License"); you may not
  7. // use this file except in compliance with the License. You may obtain a copy
  8. // of the License at
  9. //
  10. // http://www.apache.org/licenses/LICENSE-2.0
  11. //
  12. // Unless required by applicable law or agreed to in writing, software
  13. // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  14. // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  15. // License for the specific language governing permissions and limitations under
  16. // the License.
  17. //
  18. #import <Foundation/Foundation.h>
  19. #import "GTMDefines.h"
  20. // A category for calling handlers in NSAppleScript
  21. enum {
  22. // Data type is OSAID. These will generally be representing
  23. // scripts.
  24. typeGTMOSAID = 'GTMO'
  25. };
  26. @interface NSAppleScript(GTMAppleScriptHandlerAdditions)
  27. // Allows us to call a specific handler in an AppleScript.
  28. // parameters are passed in left-right order 0-n.
  29. //
  30. // Args:
  31. // handler - name of the handler to call in the Applescript
  32. // params - the parameters to pass to the handler
  33. // error - in non-nil returns any error that may have occurred.
  34. //
  35. // Returns:
  36. // The result of the handler being called. nil on failure.
  37. - (NSAppleEventDescriptor*)gtm_executePositionalHandler:(NSString*)handler
  38. parameters:(NSArray*)params
  39. error:(NSDictionary**)error;
  40. // Allows us to call a specific labeled handler in an AppleScript.
  41. // Parameters for a labeled handler can be in any order, as long as the
  42. // order of the params array corresponds to the order of the labels array
  43. // such that labels are associated with their correct parameter values.
  44. //
  45. // Args:
  46. // handler - name of the handler to call in the Applescript
  47. // labels - the labels to associate with the parameters
  48. // params - the parameters to pass to the handler
  49. // count - number of labels/parameters
  50. // error - in non-nil returns any error that may have occurred.
  51. //
  52. // Returns:
  53. // The result of the handler being called. nil on failure.
  54. - (NSAppleEventDescriptor*)gtm_executeLabeledHandler:(NSString*)handler
  55. labels:(AEKeyword*)labels
  56. parameters:(id*)params
  57. count:(NSUInteger)count
  58. error:(NSDictionary **)error;
  59. // Same as executeAppleEvent:error: except that it handles return values of
  60. // script correctly. Return values containing scripts will have the
  61. // typeGTMOSAID. Calling gtm_objectValue on a NSAppleEventDescriptor of
  62. // typeGTMOSAID will resolve correctly to a script value. We don't use
  63. // typeScript because that actually copies the script instead of returning the
  64. // actual value. Therefore if you called executeAppleEvent:error: (instead of
  65. // the GTM version) to execute an event that returns a script, you will
  66. // get a completely new Applescript, instead of the actual script you wanted. If
  67. // you are working with script information, use gtm_executeAppleEvent:error
  68. // instead of executeAppleEvent:error: to avoid the problem.
  69. - (NSAppleEventDescriptor *)gtm_executeAppleEvent:(NSAppleEventDescriptor *)event
  70. error:(NSDictionary **)error;
  71. // The set of all handlers that are defined in this script and its parents.
  72. // Remember that handlers that are defined in an sdef will have their
  73. // eventclass/eventid as their handler instead of the name seen in the script.
  74. // So:
  75. // on open(a)
  76. // blah
  77. // end open
  78. // won't be "open" it will be "aevtodoc".
  79. - (NSSet*)gtm_handlers;
  80. // The set of all properties that are defined in this script and its parents.
  81. // Note that properties can be strings or GTMNSFourCharCodes, so expect both
  82. // coming back in the set.
  83. - (NSSet*)gtm_properties;
  84. // Return a value for a property. Will look up the inheritence tree.
  85. // Property must be an NSString or a GTMFourCharCode.
  86. - (id)gtm_valueForProperty:(id)property;
  87. // Return a value for a property by type (eg pASParent). Will look up the
  88. // inheritence tree
  89. - (id)gtm_valueForPropertyEnum:(DescType)property;
  90. // Set a script property value. Returns YES/NO on success/failure.
  91. // Property must be of kind NSString or GTMFourCharCode.
  92. // If addingDefinition is YES, it will add a definition to the script
  93. // if the value doesn't exist in the script or one of it's parents.
  94. - (BOOL)gtm_setValue:(id)value
  95. forProperty:(id)property
  96. addingDefinition:(BOOL)adding;
  97. // Set a value for a property by type (eg pASParent). See note above
  98. // for gtm_setValue:forProperty.
  99. - (BOOL)gtm_setValue:(id)value
  100. forPropertyEnum:(DescType)property
  101. addingDefinition:(BOOL)adding;
  102. // Return YES if the script has an open documents (odoc) handler
  103. // Does not require script compilation, so it's a fast check.
  104. - (BOOL)gtm_hasOpenDocumentsHandler;
  105. @end
  106. // Error keys that we may return in the error dictionary on top of the standard
  107. // NSAppleScriptError* keys.
  108. extern NSString const* GTMNSAppleScriptErrorPartialResult; // id
  109. extern NSString const* GTMNSAppleScriptErrorOffendingObject; // id
  110. extern NSString const* GTMNSAppleScriptErrorExpectedType; // GTMFourCharCode
  111. @interface NSAppleEventDescriptor (GTMAppleEventDescriptorOSAAdditions)
  112. // Returns an NSValue containing an NSRange of script source when an error
  113. // occurs while compiling and/or executing a script.
  114. - (id)gtm_OSAErrorRangeValue;
  115. @end