This repository has been archived by the owner on Dec 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
baseDroplet.m
69 lines (56 loc) · 2.13 KB
/
baseDroplet.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//
// baseDroplet.m
// ShinyDroplets
//
// Created by Matteo Rattotti on 6/27/08.
// Copyright 2008 www.shinyfrog.net. All rights reserved.
//
#import "baseDroplet.h"
@implementation baseDroplet
- (void) awakeFromNib{
returnDescriptor = NULL;
[self setDropScript];
[self setActivateScript];
//NSLog(scriptDrop);
}
- (void) executeScript: (NSString *) theScript{
scriptObject = [[NSAppleScript alloc] initWithSource: theScript];
returnDescriptor = [scriptObject executeAndReturnError: &errorDict];
if (returnDescriptor == NULL)
{
// Handling errors
NSLog(@"Errors occured!");
NSLog(@"Errors: %@", errorDict);
}
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification{
[self executeScript:scriptActivate];
[NSApp terminate:self];
}
- (void)application:(NSApplication *)sender openFiles:(NSArray *)filePaths{
int i, n;
n = [filePaths count];
for(i=0; i<n; i++){
[self executeScript:[NSString stringWithFormat:scriptDrop,[self appName], [filePaths objectAtIndex:i]]];
}
[sender replyToOpenOrPrint:NSApplicationDelegateReplySuccess];
[sender performSelector:@selector(terminate:) withObject:self afterDelay:0.1];
}
- (BOOL)application:(NSApplication *)sender openFile:(NSString *)filename {
[self executeScript:[NSString stringWithFormat:scriptDrop,[self appName], filename]];
[sender performSelector:@selector(terminate:) withObject:self afterDelay:0.1];
return YES;
}
- (NSString *) appName{
return @"";
}
- (void) setDropScript{
scriptDrop = @"tell application \"%@\"\n activate \n open \"%@\"\n end tell";;
}
- (void) setActivateScript{
NSBundle *thisBundle = [NSBundle mainBundle];
scriptActivate = [[NSMutableString alloc]initWithContentsOfFile:[thisBundle pathForResource:@"scriptClick" ofType:@"scpt"] encoding:NSASCIIStringEncoding error:Nil];
//scriptActivate = [[scriptActivate stringByReplacingOccurrencesOfString:@"APP" withString:[self appName]]retain];
[scriptActivate replaceOccurrencesOfString:@"APP" withString:[self appName] options:nil range:NSMakeRange(0, [scriptActivate length])];
}
@end