2 // Scripting_Additions.m
5 // Created by Nathan Oates on Fri Dec 31 2004.
6 // Copyright (c) 2004 __MyCompanyName__. All rights reserved.
9 #import "Scripting_Additions.h"
10 #import "UIElements.h"
13 @implementation NSApplication(Scripting_Additions)
15 // Applescript commands
16 - (id) handleUploadFileCommand:(NSScriptCommand *)command {
18 // ask the command to evaluate its arguments
19 NSDictionary *args = [command evaluatedArguments];
20 NSString *file = [args objectForKey:@"FileName"];
21 NSString *dest = [args objectForKey:@"Destination"];
23 // if we don't have a file argument, we're doomed!
24 if (!file || [file isEqualToString:@""]) return [NSNumber numberWithBool:NO];
25 if (!dest || [dest isEqualToString:@""]) return [NSNumber numberWithBool:NO];
26 NSLog(@"Applescript upload: %@ to %@", file, dest);
27 [[self delegate]uploadPath:file toPath:dest];
28 return [NSNumber numberWithBool:YES];
31 - (id)handleDownloadFileCommand:(NSScriptCommand *)command {
32 // ask the command to evaluate its arguments
33 NSDictionary *args = [command evaluatedArguments];
34 NSString *file = [args objectForKey:@"FileName"];
35 NSString *dest = [args objectForKey:@"Destination"];
37 // if we don't have a file argument, we're doomed!
38 if (!file || [file isEqualToString:@""]) return [NSNumber numberWithBool:NO];
39 if (!dest || [dest isEqualToString:@""]) return [NSNumber numberWithBool:NO];
41 UIElements *UI = [self delegate];
42 if (![UI isConnected])
43 return [NSNumber numberWithBool:NO];
45 NSLog(@"Applescript download: %@ to %@", file, dest);
46 NSDictionary* fileInfo = [NSDictionary dictionaryWithObjectsAndKeys:[file lastPathComponent], @"name", [NSNumber numberWithInt:0], @"fileSize", [NSCalendarDate calendarDate], @"date", nil];
47 [[UI getTfusbc] getFile:fileInfo forPath:[file stringByDeletingLastPathComponent] toSaveTo:dest beginAtOffset:0 withLooping:YES existingTime:0];
48 return [NSNumber numberWithBool:YES];
52 - (id)handleDeleteFileCommand:(NSScriptCommand *)command {
53 // ask the command to evaluate its arguments
54 NSDictionary *args = [command evaluatedArguments];
55 NSString *file = [args objectForKey:@"FileName"];
57 // if we don't have a file argument, we're doomed!
58 if (!file || [file isEqualToString:@""]) return [NSNumber numberWithBool:NO];
60 UIElements *UI = [self delegate];
61 if (![UI isConnected])
62 return [NSNumber numberWithBool:NO];
64 NSLog(@"Applescript delete: %@", file);
65 NSDictionary* fileInfo = [NSDictionary dictionaryWithObjectsAndKeys:[file lastPathComponent], @"name", [NSNumber numberWithInt:0], @"fileSize", [NSCalendarDate calendarDate], @"date", nil];
66 // NSLog([fileInfo description]);
67 [[UI getTfusbc] deleteFile:fileInfo fromPath:[file stringByDeletingLastPathComponent]];
68 return [NSNumber numberWithBool:YES];
72 - (id)handleConnectCommand:(NSScriptCommand *)command {
73 NSLog(@"Applescript app connect");
74 UIElements *uiEl = [self delegate];
76 return [uiEl isConnected];
79 - (id)handleDisconnectCommand:(NSScriptCommand *)command {
80 NSLog(@"Applescript disconnect");
81 UIElements *uiEl = [self delegate];
83 if ([uiEl isConnected])
84 return [NSNumber numberWithBool:NO];
86 return [NSNumber numberWithBool:YES];