Python AppKit.NSStringPboardType() Examples
The following are 6
code examples of AppKit.NSStringPboardType().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
AppKit
, or try the search function
.
Example #1
Source File: __init__.py From gist-alfred with MIT License | 6 votes |
def init_osx_pyobjc_clipboard(): def copy_osx_pyobjc(text): '''Copy string argument to clipboard''' text = _stringifyText(text) # Converts non-str values to str. newStr = Foundation.NSString.stringWithString_(text).nsstring() newData = newStr.dataUsingEncoding_(Foundation.NSUTF8StringEncoding) board = AppKit.NSPasteboard.generalPasteboard() board.declareTypes_owner_([AppKit.NSStringPboardType], None) board.setData_forType_(newData, AppKit.NSStringPboardType) def paste_osx_pyobjc(): "Returns contents of clipboard" board = AppKit.NSPasteboard.generalPasteboard() content = board.stringForType_(AppKit.NSStringPboardType) return content return copy_osx_pyobjc, paste_osx_pyobjc
Example #2
Source File: HT_LetterSpacer_script.py From HTLetterspacer with GNU General Public License v3.0 | 6 votes |
def setClipboard( self, myText ): """ Sets the contents of the clipboard to myText. Returns True if successful, False if unsuccessful. """ from AppKit import NSPasteboard, NSStringPboardType try: myClipboard = NSPasteboard.generalPasteboard() myClipboard.declareTypes_owner_( [NSStringPboardType], None ) myClipboard.setString_forType_( myText, NSStringPboardType ) return True except Exception as e: import traceback print(traceback.format_exc()) print() print(e) return False
Example #3
Source File: Pyperclip.py From MIA-Japanese-Add-on with GNU General Public License v3.0 | 6 votes |
def init_osx_pyobjc_clipboard(): def copy_osx_pyobjc(text): '''Copy string argument to clipboard''' text = _stringifyText(text) # Converts non-str values to str. newStr = Foundation.NSString.stringWithString_(text).nsstring() newData = newStr.dataUsingEncoding_(Foundation.NSUTF8StringEncoding) board = AppKit.NSPasteboard.generalPasteboard() board.declareTypes_owner_([AppKit.NSStringPboardType], None) board.setData_forType_(newData, AppKit.NSStringPboardType) def paste_osx_pyobjc(): "Returns contents of clipboard" board = AppKit.NSPasteboard.generalPasteboard() content = board.stringForType_(AppKit.NSStringPboardType) return content return copy_osx_pyobjc, paste_osx_pyobjc
Example #4
Source File: Pyperclip.py From MIA-Dictionary-Addon with GNU General Public License v3.0 | 6 votes |
def init_osx_pyobjc_clipboard(): def copy_osx_pyobjc(text): '''Copy string argument to clipboard''' text = _stringifyText(text) # Converts non-str values to str. newStr = Foundation.NSString.stringWithString_(text).nsstring() newData = newStr.dataUsingEncoding_(Foundation.NSUTF8StringEncoding) board = AppKit.NSPasteboard.generalPasteboard() board.declareTypes_owner_([AppKit.NSStringPboardType], None) board.setData_forType_(newData, AppKit.NSStringPboardType) def paste_osx_pyobjc(): "Returns contents of clipboard" board = AppKit.NSPasteboard.generalPasteboard() content = board.stringForType_(AppKit.NSStringPboardType) return content return copy_osx_pyobjc, paste_osx_pyobjc
Example #5
Source File: clipboard.py From EvilOSX with GNU General Public License v3.0 | 5 votes |
def run(options): elapsed_time = 0 monitor_time = int(options["monitor_time"]) output_file = options["output_file"] previous = "" while elapsed_time <= monitor_time: try: pasteboard = NSPasteboard.generalPasteboard() pasteboard_string = pasteboard.stringForType_(NSStringPboardType) if pasteboard_string != previous: if output_file: with open(output_file, "a+") as out: out.write(pasteboard_string + "\n") else: st = datetime.fromtimestamp(time()).strftime("%H:%M:%S") print("[clipboard] " + st + " - '%s'" % str(pasteboard_string).encode("utf-8")) previous = pasteboard_string sleep(1) elapsed_time += 1 except Exception as ex: print(str(ex)) if output_file: print("Clipboard written to: " + output_file)
Example #6
Source File: clipboard.py From EmPyre with BSD 3-Clause "New" or "Revised" License | 4 votes |
def generate(self): outFile = self.options['OutFile']['Value'] monitorTime = self.options['MonitorTime']['Value'] # the Python script itself, with the command to invoke # for execution appended to the end. Scripts should output # everything to the pipeline for proper parsing. # # the script should be stripped of comments, with a link to any # original reference script included in the comments. script = """ def func(monitortime=0): from AppKit import NSPasteboard, NSStringPboardType import time import datetime import sys sleeptime = 0 last = '' outFile = '%s' while sleeptime <= monitortime: try: pb = NSPasteboard.generalPasteboard() pbstring = pb.stringForType_(NSStringPboardType) if pbstring != last: if outFile != "": f = file(outFile, 'a+') f.write(pbstring) f.close() print "clipboard written to",outFile else: ts = time.time() st = datetime.datetime.fromtimestamp(ts).strftime('%%Y-%%m-%%d %%H:%%M:%%S') print st + ": %%s".encode("utf-8") %% repr(pbstring) last = pbstring time.sleep(1) sleeptime += 1 except Exception as e: print e func(monitortime=%s)""" % (outFile,monitorTime) return script