def _to_clipboard(s): 'Mac only' from AppKit import NSPasteboard, NSArray pb = NSPasteboard.generalPasteboard() pb.clearContents() a = NSArray.arrayWithObject_(s) pb.writeObjects_(a)
def copy_ip(item): """Copies IP to clipboard""" from AppKit import NSPasteboard, NSArray pb = NSPasteboard.generalPasteboard() pb.clearContents() a = NSArray.arrayWithObject_(item) pb.writeObjects_(a)
def copyToClipboard(): try: word = b64decode(alfred.argv(2)) pb = NSPasteboard.generalPasteboard() pb.clearContents() a = NSArray.arrayWithObject_(word) pb.writeObjects_(a) alfred.exit('已拷贝地址到剪切板') except Exception, e: alfred.log(e) alfred.exit('出错啦')
def _macosx(self, text): # # taken from: http://stackoverflow.com/a/3555675 # from AppKit import NSPasteboard, NSArray pb = NSPasteboard.generalPasteboard() pb.clearContents() a = NSArray.arrayWithObject_(text) pb.writeObjects_(a) def clearit(): pb.clearContents() return clearit
def _copy_to_clipboard(arg): arg = str(globals().get(arg) or arg) if sys.platform == 'darwin': pb = NSPasteboard.generalPasteboard() pb.clearContents() a = NSArray.arrayWithObject_(arg) pb.writeObjects_(a) elif sys.platform.startswith('linux'): p = Popen(['xsel', '-pi'], stdin=PIPE) p.communicate(input=arg) print 'Copied to clipboard!'
def launchAppByBundlePath(bundlePath, arguments=[]): """ launchAppByBundlePath - Launch app with a given bundle path Return True if succeed """ bundleUrl = NSURL.URLWithString_(bundlePath) workspace = AppKit.NSWorkspace.sharedWorkspace() arguments_strings = map(lambda a: NSString.stringWithString_(str(a)), arguments) arguments = NSDictionary.dictionaryWithDictionary_( {AppKit.NSWorkspaceLaunchConfigurationArguments: NSArray.arrayWithArray_(arguments_strings)} ) return workspace.launchApplicationAtURL_options_configuration_error_( bundleUrl, AppKit.NSWorkspaceLaunchAllowingClassicStartup, arguments, None )
def share_path(path, access_token): api_client = client.DropboxClient(access_token) try: url = api_client.share(path)['url'] pb = NSPasteboard.generalPasteboard() pb.clearContents() a = NSArray.arrayWithObject_(url) pb.writeObjects_(a) print 'Link copied to clipboard' except rest.ErrorResponse, e: print e.user_error_msg or str(e)
def write_text(text, paste=False): '''send text formatted exactly as written to active window. will use pbpaste clipboard to paste the text instead of typing it.''' logging.debug("text = %s paste = %s" % (text, paste)) if text: # get current clipboard contents pb = NSPasteboard.generalPasteboard() classes = NSArray.arrayWithObject_(objc.lookUpClass('NSString')) options = NSDictionary.dictionary() items = NSArray(pb.readObjectsForClasses_options_(classes, options)) # copy our text to clipboard a = NSArray.arrayWithObject_(text) pb.clearContents() pb.writeObjects_(a) # paste key_press('v', 'super') pause(500) # return original text to clipboard pb.clearContents() pb.writeObjects_(items)
def launchAppByBundlePath(bundlePath, arguments=[]): ''' launchAppByBundlePath - Launch app with a given bundle path Return True if succeed ''' bundleUrl = NSURL.fileURLWithPath_(bundlePath) workspace = AppKit.NSWorkspace.sharedWorkspace() arguments_strings = map(lambda a: NSString.stringWithString_(str(a)), arguments) arguments = NSDictionary.dictionaryWithDictionary_({ AppKit.NSWorkspaceLaunchConfigurationArguments: NSArray.arrayWithArray_(arguments_strings) }) return workspace.launchApplicationAtURL_options_configuration_error_( bundleUrl, AppKit.NSWorkspaceLaunchAllowingClassicStartup, arguments, None)
def copy_result(self, sender): from string import strip from AppKit import NSPasteboard, NSArray s = u"" results = self.w.font_list.getSelection() for i in results: s += self.w.font_list.get()[i]["Font"] + "\n\n" s += self.w.font_list.get()[i]["Result"] + "\n\n\n" pb = NSPasteboard.generalPasteboard() pb.clearContents() a = NSArray.arrayWithObject_(s.strip("\n")) pb.writeObjects_(a)
def save_image_to_clipboard(self, url): pb = NSPasteboard.generalPasteboard() pb.clearContents() if url.startswith('http'): img = Image.open(urllib.request.urlopen(url)) else: img = Image.open(url) img_bytes = io.BytesIO() img.save(img_bytes, format='PNG') imgNsData = NSData.alloc().initWithBytes_length_( img_bytes.getvalue(), img_bytes.tell()) imgNsImage = NSImage.alloc().initWithData_(imgNsData) array = NSArray.arrayWithObject_(imgNsImage) pb.writeObjects_(array) return
def copy_(self, sender): text = None selection = self.selectedRowIndexes() item = selection.firstIndex() if item != NSNotFound: object = self.itemAtRow_(item) if isinstance(object, BlinkContact): text = '%s <%s>' % ( object.name, object.uri) if object.name != object.uri else object.uri elif isinstance(object, BlinkGroup): text = '%s' % object.name if text: pb = NSPasteboard.generalPasteboard() pb.declareTypes_owner_( NSArray.arrayWithObject_(NSStringPboardType), self) pb.setString_forType_(text, NSStringPboardType)
def _copy_to_clipboard(arg): import sys if sys.platform == 'darwin': from AppKit import NSPasteboard, NSArray elif sys.platform.startswith('linux'): from subprocess import Popen, PIPE else: raise ImportError("Clip magic only works on osx or linux!") arg = str(globals().get(arg) or arg) if sys.platform == 'darwin': pb = NSPasteboard.generalPasteboard() pb.clearContents() a = NSArray.arrayWithObject_(arg) pb.writeObjects_(a) elif sys.platform.startswith('linux'): p = Popen(['xsel', '-pi'], stdin=PIPE) p.communicate(input=arg) print('Copied to clipboard!')
def copy_to_clipboard(text): from AppKit import NSPasteboard, NSArray pb = NSPasteboard.generalPasteboard() pb.clearContents() a = NSArray.arrayWithObject_(text) pb.writeObjects_(a)
def put_text(self, text): self.pasteboard.clearContents() self.pasteboard.writeObjects_(NSArray.arrayWithObject_(text))
import base64 import sys from AppKit import NSPasteboard, NSArray pb = NSPasteboard.generalPasteboard() pb.clearContents() encoded = base64.urlsafe_b64encode(str(sys.argv[1])) pb.writeObjects_(NSArray.arrayWithObject_(encoded))
def clipboard(link): pb = NSPasteboard.generalPasteboard() pb.clearContents() array = NSArray.arrayWithObject_(link) pb.writeObjects_(array)
def set_clipboard(url_list): pb = NSPasteboard.generalPasteboard() pb.clearContents() for url in url_list: a = NSArray.arrayWithObject_(url) pb.writeObjects_(a)
f = CurrentFont() sets = [] features = "" for g in f.keys(): if "." in g: if "ss" in g.split(".")[1] and g.split(".")[1] not in sets: sets.append(g.split(".")[1]) sets.sort() for set in sets: features += "feature %s {\n" % set for g in f: if set in g.name: base = g.name.split(".")[0] suffix = g.name.split(".")[1] features += "sub %s by %s;\n" % (base, g.name) features += "} %s;\n\n" % set if features != "": p = NSPasteboard.generalPasteboard() p.clearContents() a = NSArray.arrayWithObject_(features) p.writeObjects_(a) mojo.UI.Message('Stylistic sets features copied to your clipboard') if features == "": mojo.UI.Message("Could not find properly named glyphs.")
def sendToClipboard(content): pb = NSPasteboard.generalPasteboard() pb.clearContents() c = NSArray.arrayWithObject_(content) pb.writeObjects_(c)
def save_text_to_clipboard(self, text): pb = NSPasteboard.generalPasteboard() pb.clearContents() a = NSArray.arrayWithObject_(text) pb.writeObjects_(a) return
help="Specify whether to use special characters", default=False, action='store_true') (options, args) = parser.parse_args() strSpecial = '!@#$%^&*()' char_set = string.ascii_uppercase + string.ascii_lowercase + string.digits def f_pwGen(size=8, chars=char_set): return ''.join(random.choice(chars) for x in range(int(options.pwLength))) def f_pwGenSpecial(size=8, chars=char_set + strSpecial): return ''.join(random.choice(chars) for x in range(int(options.pwLength))) print 'Password length: ', options.pwLength print 'Special Characters?: ', options.pwSpecial print 'Generated Password: ' if (options.pwSpecial): myPass = f_pwGenSpecial(int(options.pwLength), ) a = NSArray.arrayWithObject_(myPass) print myPass pb.writeObjects_(a) else: myPass = f_pwGen(int(options.pwLength), ) a = NSArray.arrayWithObject_(myPass) print myPass pb.writeObjects_(a)