forked from onmyway133/FinderGo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFinderSync.swift
104 lines (76 loc) · 2.63 KB
/
FinderSync.swift
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//
// FinderSync.swift
// FinderSyncExtension
//
// Created by Khoa Pham on 13/03/2017.
// Copyright © 2017 Fantageek. All rights reserved.
//
import Cocoa
import FinderSync
class FinderSync: FIFinderSync, NSMenuDelegate {
override init() {
super.init()
NSLog("FinderSync() launched from %@", Bundle.main.bundlePath as NSString)
}
// MARK: - Primary Finder Sync protocol methods
override func beginObservingDirectory(at url: URL) {
// The user is now seeing the container's contents.
// If they see it in more than one view at a time, we're only told once.
NSLog("beginObservingDirectoryAtURL: %@", url.path as NSString)
}
override func endObservingDirectory(at url: URL) {
// The user is no longer seeing the container's contents.
NSLog("endObservingDirectoryAtURL: %@", url.path as NSString)
}
override func requestBadgeIdentifier(for url: URL) {
NSLog("requestBadgeIdentifierForURL: %@", url.path as NSString)
}
// MARK: - Menu and toolbar item support
override var toolbarItemName: String {
return "FinderGo"
}
override var toolbarItemToolTip: String {
return "FinderGo: Click the toolbar item for a menu."
}
override var toolbarItemImage: NSImage {
return NSImage(named: "barIcon")!
}
override func menu(for menuKind: FIMenuKind) -> NSMenu {
let menu = NSMenu(title: "")
menu.delegate = self
menu.addItem(withTitle: "iTerm", action: #selector(openiTerm(_:)), keyEquivalent: "")
menu.addItem(withTitle: "Terminal", action: #selector(openTerminal(_:)), keyEquivalent: "")
menu.addItem(withTitle: "Hyper", action: #selector(openHyper(_:)), keyEquivalent: "")
menu.addItem(withTitle: "code", action: #selector(openCode(_:)), keyEquivalent: "")
return menu
}
// MARK: - NSMenuDelegate
func menuWillOpen(_ menu: NSMenu) {
guard let targetedUrl = FIFinderSyncController.default().targetedURL() else {
return
}
let board = NSPasteboard.general
board.setString(targetedUrl.path, forType: NSPasteboard.PasteboardType.string)
}
// MARK: - Action
@IBAction func openiTerm(_ sender: AnyObject?) {
run(fileName: "iterm")
}
@IBAction func openTerminal(_ sender: AnyObject?) {
run(fileName: "terminal")
}
@IBAction func openHyper(_ sender: AnyObject?) {
run(fileName: "hyper")
}
@IBAction func openCode(_ sender: AnyObject?) {
run(fileName: "code")
}
// MARK: - Script
func run(fileName: String) {
guard let targetedUrl = FIFinderSyncController.default().targetedURL() else {
return
}
let worker = ExtensionWorker(path: targetedUrl.path, fileName: fileName)
worker.run()
}
}