package clip import ( "strings" "git.wow.st/63l06ri5/clip/ns" ) var pb *ns.NSPasteboard const ( uriPrefix = "file://" uriPrefixLength = len(uriPrefix) ) func Clear() { if pb == nil { pb = ns.NSPasteboardGeneralPasteboard() } pb.ClearContents() } func Set(x string) bool { if pb == nil { pb = ns.NSPasteboardGeneralPasteboard() } pb.ClearContents() return pb.SetString(x) } func Get() string { if pb == nil { pb = ns.NSPasteboardGeneralPasteboard() } ret := pb.GetString() if ret.Ptr() == nil { return "" } else { return ret.String() } } func PasteFileList(filePaths []string) { if pb == nil { pb = ns.NSPasteboardGeneralPasteboard() } pb.ClearContents() pb.PasteFileList(filePaths) } func GetFileList() []string { if pb == nil { pb = ns.NSPasteboardGeneralPasteboard() } ret := pb.GetFileList() result := make([]string, 0) if ret.Ptr() == nil { return result } else { filesStr := ret.String() arr := strings.Split(filesStr, ns.FilesDelimeter) for _, item := range arr { if strings.HasPrefix(item, uriPrefix) { result = append(result, item[uriPrefixLength:]) } } return result } } func GetImage(pathToStore string) bool { if pb == nil { pb = ns.NSPasteboardGeneralPasteboard() } return pb.GetImage(pathToStore) }