-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
44 lines (37 loc) · 932 Bytes
/
main.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
package main
/*
#cgo CFLAGS: -x objective-c
#cgo LDFLAGS: -framework Foundation -framework Cocoa
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
void copyToClipboard(const char *text) {
NSString *s = [NSString stringWithUTF8String:text];
NSData *inputData = [s dataUsingEncoding:NSUTF8StringEncoding];
NSPasteboard* pasteboard = [NSPasteboard generalPasteboard];
[pasteboard clearContents];
[pasteboard setData: [@"" dataUsingEncoding:NSUTF8StringEncoding] forType: @"org.nspasteboard.ConcealedType"];
[pasteboard setData: inputData forType: @"NSStringPboardType"];
}
*/
import "C"
import (
"fmt"
"io"
"os"
"strings"
)
func run() error {
data, err := io.ReadAll(os.Stdin)
if err != nil {
return err
}
payload := strings.TrimRight(string(data), "\n")
C.copyToClipboard(C.CString(payload))
return nil
}
func main() {
if err := run(); err != nil {
fmt.Printf("ERROR: %s\n", err)
os.Exit(1)
}
}