Copying and Pasting from one app (Sublime Text) to another (X11 window) using Automator and AppleScript?

Hi everyone,


I'd like to have the following workflow: I will select and copy a line of script from the text editor Sublime Text, go to another application (which is an X11 output running under XQuartz), paste whatever I copied and press Enter.


I have never written any AppleScript before, and I have no idea how to go about writing this (or even how I can assign this to a keyboard shortcut universally). Any tips and help would be great! (I'm hoping that someone already worked on this in the past!).


Thanks!


N

MacBook Pro, iOS 10.2

Posted on Apr 15, 2017 1:20 PM

Reply
5 replies

Apr 22, 2017 5:44 PM in response to sadatnfs

Previously, I tried copying/pasting between Sublime Text 3 and just an Xterm running under XQuartz. That didn't work.


Just now, I opened Python code in both the Textastic, and Sublime Text 3 editors, and copied it to the OS X clipboard. I then launched inkscape (an X Window System application), created a text box, and was able to paste from the OS X 10.11.6 clipboard into Inkscape using its Edit : Paste.


Here is my XQuartz Preference panel for Pasteboard that allows sharing of the OS X/X Window System pasteboard that worked for me:

User uploaded fileUser uploaded file

Apr 22, 2017 7:27 PM in response to sadatnfs

Does any of this work?

Option 1

  • Copy text in Sublime Text
  • Go to Xquartx type pbpaste & hit return


Sublime text copies into the Mac pasteboard.

pbpaste will insert that at the Xquartz Terminal.


If you want to execute the content of the clipboard wrap it in back ticks or $() e.g.

`pbpaste`

$(pbpaste)


I suggest making an alias in your bash_profile to allow you to do this quickly.

It isn't Applescript & it isn't automatic but I can't see how Apple script can solve it unless there is a scriptable X11 interface, GUI scripting may work but it just drives me crazy - good luck with that 🙂


Obviously pbpaste is a local command so I'm assuming you are running a local X11 session, otherwise all bets are off.


Option 2

Ask Sublime Text to 'shove some stuff into a file?!'…


  • Get the 'tty; in Xquartz
    • $ tty
    • /dev/ttys002
  • From another Terminal

    $ echo "whatever you selected in sublime" > /dev/ttys002

Wrap in backticks to cause execution.


My point here is that Sublime Text has some kind of 'process my selection via a command'. So I presume you can concoct a command to handle all of this from within Sublime Text (or other code editors that run shell commands, like Textmate, bbedit…). The only issue is see is the tty changes, so you may need to set a shell variable or setup a way for sublime to prompt that (I have no idea how to do that TextMate 2 is my preferred editor). I don't use X11 much either so maybe this is all impossible?


*nix = everything is a file

Apr 15, 2017 1:40 PM in response to sadatnfs

Sublime Text [3] was not written with an AppleScript scripting dictionary, and neither was XQuartz. Using GUI scripting to tell System Events to simulate select all, and copy content from Sublime Text — never puts anything on the OS X clipboard.


Although there are optional OS X Pasteboard synchronization options in the XQuartz Preferences — in practice they do not work when manually copying Sublime Text content to the OS X clipboard. The Edit : Paste menu option never appears in XQuartz.


I don't believe your workflow aspirations are going to work between Sublime Text and XQuartz.

Apr 23, 2017 5:23 AM in response to Drew Reece

Drew,


Applications (Cocoa, Tcl/Tk) run from the Xterm command-line present the same user interface as they do when XQuartz is not running. This includes regular AppleScripts, and those containing AppleScript/Objective-C when initiated by osascript.


The pbpaste/pbcopy commands work as they normally do, whether in Terminal, or Xterm.


The OP is encouraged to look at the various installable packages available for Sublime Text 3 that may facilitate a solution. Provided that the package manager from this site is installed within Sublime Text 3, any of these STL3 compatible packages are searchable, and installable from within the editor.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Copying and Pasting from one app (Sublime Text) to another (X11 window) using Automator and AppleScript?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.