-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSketchKit-remote.coscript
More file actions
69 lines (58 loc) · 2.16 KB
/
SketchKit-remote.coscript
File metadata and controls
69 lines (58 loc) · 2.16 KB
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
// Check if we're in Sketch
if (!NSClassFromString("MSDocument")){
// launch Sketch with document then run this plugin
var currentScript = [COScript currentCOScript];
var scriptEnvironment = [currentScript env];
var scriptURL = scriptEnvironment["scriptURL"];
var scriptPath = [scriptURL path];
var projectFolder = [scriptPath stringByDeletingLastPathComponent];
var sketchDocumentsFolder = [projectFolder stringByAppendingPathComponent:"Sketch Documents"];
var shapeTestPath = [sketchDocumentsFolder stringByAppendingPathComponent:"SketchKit Shape Test.sketch"];
// Open Sketch document
[[NSWorkspace sharedWorkspace] openFile:shapeTestPath];
var url = [NSURL fileURLWithPath:scriptPath];
var app = [COScript app:"Sketch"];
var delegate = [app delegate];
[delegate runPluginAtURL:url];
}
else {
if (!NSClassFromString("CSKFileMonitor")) {
var currentScript = [COScript currentCOScript];
var scriptEnvironment = [currentScript env];
var scriptURL = scriptEnvironment["scriptURL"];
var scriptPath = [scriptURL path];
var projectFolder = [scriptPath stringByDeletingLastPathComponent];
var pluginFolder = [projectFolder stringByAppendingPathComponent:"SketchKit.sketchplugin"];
var bundlePath = [pluginFolder stringByAppendingPathComponent:"SketchKit.framework"];
var error = null;
if (!loadBundle(bundlePath)) {
log("error");
}
}
var testController = SKKTestController.sharedInstance();
testController.testWithContext(sketch);
}
function loadBundle(filePath) {
var bundleURL = NSURL.fileURLWithPath(filePath);
var bundle = [NSBundle bundleWithURL: bundleURL];
if (bundle == null) {
showNotification("Bundle missing!");
error = error;
return false;
}
var loaded = [bundle load];
if (!loaded) {
showNotification("Couldn't load SketchKit bundle.");
}
else {
// log("loaded bundle!")
}
return loaded;
}
function showNotification(message) {
var notification = [[NSUserNotification alloc] init];
notification.title = @"SketchKit";
notification.informativeText = message;
notification.soundName = NSUserNotificationDefaultSoundName;
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
}