SOLVED Clipboard content for multiple glyphs

  • admin

    Make you own copy paste:


    import AppKit
    import json
    # get the pasteboard
    pasteBoard = AppKit.NSPasteboard.generalPasteboard()
    # get the font (maybe check if there is a font)
    font = CurrentFont()
    # create your pasteboard type
    bahmanPasteBoardType = "Bahman.special.copy.paste"
    # collect data
    data = []
    for glyphName in font.selectedGlyphNames:
        glyph = font[glyphName]    
        anchorData = [dict(, x=anchor.x, y=anchor.y, for anchor in glyph.anchors]        
    # write it to the pastboard
    pasteBoard.setString_forType_(json.dumps(data), bahmanPasteBoardType)


    import AppKit
    import json
    # get the pasteboard
    pasteBoard = AppKit.NSPasteboard.generalPasteboard()
    # print out all the availabe types
    # create your pasteboard type
    bahmanPasteBoardType = "Bahman.special.copy.paste"
    # get the paste board string for type
    data = pasteBoard.stringForType_(bahmanPasteBoardType)
    # its None when there no such paste board type
    if data:
        data = json.loads(data)
        # do something with this data    

    good luck!!

  • hello @bahman,

    the latest beta includes the new observers fontOverviewCopy and fontOverviewPaste, please give them a try…


  • Thank you this is much more useful. Now we can access the clipboard content much easier!

  • I came up with this idea to store the glyphs inside an extension key and when I run the paste script, I will retrieve the glyphs from there. There is a possible drawback here since the content of the extension key can't be saved into disk, it might cause failure and other extension keys will also not get saved. Is there a way to delete the key before RF is about to be closed? I couldn't find an observer for this. This is the observer that stores the glyphs:

    from import addObserver, removeObserver
    from import BaseWindowController
    from mojo.extensions import setExtensionDefault, getExtensionDefault, removeExtensionDefault
    EXTENSION_KEY = 'design.bahman.specialClipboard'
    class ClipboardGlyphs():
    	_glyphs = {}
    	def start(self):
    		addObserver(self, '_fontOverviewCopy', 'fontOverviewCopy')
    		addObserver(self, '_copy', 'copy')
    	def destroy(self, sender):
    		removeObserver(self, 'fontOverviewCopy')
    		removeObserver(self, 'copy')
    	def _fontOverviewCopy(self, info):
    		self._glyphs = {}
    		for g in info["glyphs"]:
    		setExtensionDefault(EXTENSION_KEY, self._glyphs)
    	def _copy(self, info):
    		self._glyphs = {}
    		setExtensionDefault(EXTENSION_KEY, self._glyphs)
    	def _addGlyphToClipboard(self, g):
    		if g.unicodes != ():
    			for v in g.unicodes:
    				self._glyphs[v] = g
    			self._glyphs[] = g
    if __name__ == '__main__':
    	ClipboardGlyphs = ClipboardGlyphs()
    	if debug:
    		from vanilla import FloatingWindow
    		class DebuggerWindow(BaseWindowController):
    			def __init__(self):
    				self.w = FloatingWindow((500, 500), f'ClipboardGlyphs debug!')
    				self.w.bind("close", ClipboardGlyphs.destroy)

  • admin

    Euhm dont store it in the defaults ;). If it should only be accessible while RF is running, you can store it anywhere in one of your objects.

  • I have a script that stores the glyphs when users hits copy and it runs on startup, another script runs when the user pastes.

    If I attach the glyphs to an object, I need to access that object in the paste script. And if I import the object that has the observer, it will be executed agian, adding up to previous observers. In short I don't know how to create this object you're saying, without adding another observers every time I run the paste script.

  • admin

    You'll need a controller, which is subscribed to both notifications.

    On copy you call you copy module/code, for paste the same and you provide the controller as storage for your copy glyphs.

    good luck!

  • Thanks! Finally I made this extension. Please give it a try and see if it works correctly.

  • admin

    the url doesnt work... looking forward!

  • Sorry, I just made it public.