-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathairdrop.go
56 lines (46 loc) · 1.05 KB
/
airdrop.go
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
package main
/*
#cgo CFLAGS: -x objective-c
#cgo LDFLAGS: -framework Foundation -framework Cocoa
#import <Cocoa/Cocoa.h>
#import "AirdropDelegate.h"
void run(char *url) {
@autoreleasepool {
NSApplication *application = [NSApplication sharedApplication];
AirdropDelegate *airdropDelegate = [[AirdropDelegate alloc] init];
[airdropDelegate setUrlName:[NSString stringWithCString:url encoding:NSUTF8StringEncoding]];
[application setDelegate:airdropDelegate];
[application run];
}
}
*/
import "C"
import (
"fmt"
"os"
"path/filepath"
"strings"
"unsafe"
)
func printHelp() string {
helpText := `
Usage: airdrop path
Share files located at path by using AirDrop (so you need Mac OSX (>= 10.08))
`
return strings.TrimSpace(helpText)
}
func main() {
if len(os.Args) != 2 {
fmt.Printf("%v\n", printHelp())
os.Exit(1)
}
path, err := filepath.Abs(os.Args[1])
if err != nil {
fmt.Printf("%v\n", printHelp())
os.Exit(1)
}
url := C.CString(fmt.Sprintf("file://%s", path))
defer C.free(unsafe.Pointer(url))
C.run(url)
os.Exit(0)
}