Use TopfieldUSBEcode for received values too.
[MacTF.git] / Scripting_Additions.m
blob5a3bdb4adc6dc9d2e2ac4c87691b48e8a489f3cc
1 //
2 //  Scripting_Additions.m
3 //  MacTF
4 //
5 //  Created by Nathan Oates on Fri Dec 31 2004.
6 //  Copyright (c) 2004 __MyCompanyName__. All rights reserved.
7 //
9 #import "Scripting_Additions.h"
10 #import "UIElements.h"
13 @implementation NSApplication(Scripting_Additions) 
15 // Applescript commands
16 - (id) handleUploadFileCommand:(NSScriptCommand *)command {
17         
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"];
22         
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"];
36         
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];
40         
41         UIElements *UI = [self delegate];
42         if (![UI isConnected])
43                 return [NSNumber numberWithBool:NO];
44         else {
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];
49         }
52 - (id)handleDeleteFileCommand:(NSScriptCommand *)command {
53         // ask the command to evaluate its arguments
54         NSDictionary *args = [command evaluatedArguments];
55         NSString *file = [args objectForKey:@"FileName"];
56         
57         // if we don't have a file argument, we're doomed!
58         if (!file || [file isEqualToString:@""]) return [NSNumber numberWithBool:NO];
59         
60         UIElements *UI = [self delegate];
61         if (![UI isConnected])
62                 return [NSNumber numberWithBool:NO];
63         else {
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];
69         }
72 - (id)handleConnectCommand:(NSScriptCommand *)command {
73         NSLog(@"Applescript app connect");
74         UIElements *uiEl = [self delegate];
75         [uiEl connect:nil];
76         return [uiEl isConnected];
79 - (id)handleDisconnectCommand:(NSScriptCommand *)command {
80         NSLog(@"Applescript disconnect");
81         UIElements *uiEl = [self delegate];
82         [uiEl connect:nil];
83         if ([uiEl isConnected])
84                 return [NSNumber numberWithBool:NO];
85         else
86                 return [NSNumber numberWithBool:YES];
89 @end