source: releases/Pester/1.1a3/Source/NDAppleScript/NSAppleEventDescriptor+NDAppleScriptObject.m@ 632

Last change on this file since 632 was 35, checked in by Nicholas Riley, 22 years ago

Nathan Day's NDAppleScript and related classes, somewhat modified.
Still need to commit Nathan's changes to NDResourceFork.

File size: 5.3 KB
Line 
1/*
2 * NSAppleEventDescriptor+NDAppleScriptObject.m
3 * AppleScriptObjectProject
4 *
5 * Created by Nathan Day on Fri Dec 14 2001.
6 * Copyright (c) 2001 Nathan Day. All rights reserved.
7 */
8
9#import "NSAppleEventDescriptor+NDAppleScriptObject.h"
10#import "NSURL+NDCarbonUtilities.h"
11
12@implementation NSAppleEventDescriptor (NDAppleScriptObject)
13
14/*
15 * + appleEventDescriptorWithString:
16 */
17
18+ (NSAppleEventDescriptor *)appleEventDescriptorWithString:(NSString *)aString
19{
20 return [self descriptorWithDescriptorType:typeChar data:[aString dataUsingEncoding:NSMacOSRomanStringEncoding]];
21}
22
23/*
24 * + aliasListDescriptorWithArray:
25 */
26+ (NSAppleEventDescriptor *)aliasListDescriptorWithArray:(NSArray *)aArray
27{
28 NSAppleEventDescriptor * theEventList = nil;
29 unsigned int theIndex,
30 theNumOfParam;
31
32 theNumOfParam = [aArray count];
33
34 if( theNumOfParam > 0)
35 {
36 theEventList = [self listDescriptor];
37
38 for( theIndex = 0; theIndex < theNumOfParam; theIndex++ )
39 {
40 id theObject;
41 theObject = [aArray objectAtIndex:theIndex];
42
43 if( [theObject isKindOfClass:[NSString class]] )
44 theObject = [NSURL fileURLWithPath:theObject];
45
46 [theEventList insertDescriptor:[self aliasDescriptorWithURL:theObject] atIndex:theIndex+1];
47 }
48 }
49
50 return theEventList;
51}
52
53/*
54 * + appleEventDescriptorWithURL:
55 */
56+ (NSAppleEventDescriptor *)appleEventDescriptorWithURL:(NSURL *)aURL
57{
58 return [self descriptorWithDescriptorType:typeFileURL data:[NSData dataWithBytes:(void *)aURL length:sizeof(NSURL)]];
59}
60
61/*
62 * + aliasDescriptorWithURL:
63 */
64+ (NSAppleEventDescriptor *)aliasDescriptorWithURL:(NSURL *)aURL
65{
66 AliasHandle theAliasHandle;
67 FSRef theReference;
68 NSAppleEventDescriptor * theAppleEventDescriptor = nil;
69
70 if( [aURL getFSRef:&theReference] == YES && FSNewAliasMinimal( &theReference, &theAliasHandle ) == noErr )
71 {
72 HLock((Handle)theAliasHandle);
73 theAppleEventDescriptor = [self descriptorWithDescriptorType:typeAlias data:[NSData dataWithBytes:*theAliasHandle length:GetHandleSize((Handle) theAliasHandle)]];
74 HUnlock((Handle)theAliasHandle);
75 DisposeHandle((Handle)theAliasHandle);
76 }
77
78 return theAppleEventDescriptor;
79}
80
81// typeBoolean
82+ (NSAppleEventDescriptor *)appleEventDescriptorWithBOOL:(BOOL)aValue
83{
84 return [self descriptorWithDescriptorType:typeBoolean data:[NSData dataWithBytes:&aValue length: sizeof(aValue)]];
85}
86// typeTrue
87+ (NSAppleEventDescriptor *)trueBoolDescriptor
88{
89 return [self descriptorWithDescriptorType:typeTrue data:[NSData data]];
90}
91// typeFalse
92+ (NSAppleEventDescriptor *)falseBoolDescriptor
93{
94 return [self descriptorWithDescriptorType:typeFalse data:[NSData data]];
95}
96// typeShortInteger
97+ (NSAppleEventDescriptor *)appleEventDescriptorWithShort:(short int)aValue
98{
99 return [self descriptorWithDescriptorType:typeShortInteger data:[NSData dataWithBytes:&aValue length: sizeof(aValue)]];
100}
101// typeLongInteger
102+ (NSAppleEventDescriptor *)appleEventDescriptorWithLong:(long int)aValue
103{
104 return [self descriptorWithDescriptorType:typeLongInteger data:[NSData dataWithBytes:&aValue length: sizeof(aValue)]];
105}
106// typeInteger
107+ (NSAppleEventDescriptor *)appleEventDescriptorWithInt:(int)aValue
108{
109 return [self descriptorWithDescriptorType:typeInteger data:[NSData dataWithBytes:&aValue length: sizeof(aValue)]];
110}
111// typeShortFloat
112+ (NSAppleEventDescriptor *)appleEventDescriptorWithFloat:(float)aValue
113{
114 return [self descriptorWithDescriptorType:typeShortFloat data:[NSData dataWithBytes:&aValue length: sizeof(aValue)]];
115}
116// typeLongFloat
117+ (NSAppleEventDescriptor *)appleEventDescriptorWithDouble:(double)aValue
118{
119 return [self descriptorWithDescriptorType:typeLongFloat data:[NSData dataWithBytes:&aValue length: sizeof(aValue)]];
120}
121// typeMagnitude
122+ (NSAppleEventDescriptor *)appleEventDescriptorWithUnsignedInt:(unsigned int)aValue
123{
124 return [self descriptorWithDescriptorType:typeMagnitude data:[NSData dataWithBytes:&aValue length: sizeof(aValue)]];
125}
126
127/*
128 * targetProcessSerialNumber
129 */
130- (ProcessSerialNumber)targetProcessSerialNumber
131{
132 NSAppleEventDescriptor * theTarget;
133 ProcessSerialNumber theProcessSerialNumber = { 0, 0 };
134
135 theTarget = [self attributeDescriptorForKeyword:keyAddressAttr];
136
137 if( theTarget )
138 {
139 if( [theTarget descriptorType] != typeProcessSerialNumber )
140 theTarget = [theTarget coerceToDescriptorType:typeProcessSerialNumber];
141
142 [[theTarget data] getBytes:&theProcessSerialNumber length:sizeof(ProcessSerialNumber)];
143 }
144 return theProcessSerialNumber;
145}
146
147/*
148 * targetCreator
149 */
150- (OSType)targetCreator
151{
152 NSAppleEventDescriptor * theTarget;
153 OSType theCreator = 0;
154
155 theTarget = [self attributeDescriptorForKeyword:keyAddressAttr];
156
157 if( theTarget )
158 {
159 if( [theTarget descriptorType] != typeApplSignature )
160 theTarget = [theTarget coerceToDescriptorType:typeApplSignature];
161
162 [[theTarget data] getBytes:&theCreator length:sizeof(OSType)];
163 }
164 return theCreator;
165}
166
167/*
168 * isTargetCurrentProcess
169 */
170- (BOOL)isTargetCurrentProcess
171{
172 ProcessSerialNumber theProcessSerialNumber;
173
174 theProcessSerialNumber = [self targetProcessSerialNumber];
175
176 return theProcessSerialNumber.highLongOfPSN == 0 && theProcessSerialNumber.lowLongOfPSN == kCurrentProcess;
177}
178
179@end
Note: See TracBrowser for help on using the repository browser.