Skip to content
This repository was archived by the owner on Mar 30, 2019. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions textsender.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ def is_python(self):
def wrap_paste_magic_for_python(self, cmd):
if self.is_python():
cmd = cmd.rstrip("\n")
if len(re.findall("\n", cmd)) > 0:
cmd = "%cpaste -q\n" + cmd + "\n--"
# if len(re.findall("\n", cmd)) > 0:
# cmd = "%cpaste -q\n" + cmd + "\n--\n"
return cmd

def send_text(self, cmd):
Expand Down Expand Up @@ -82,6 +82,7 @@ def _dispatch_terminal(self, cmd):
'tell application "Terminal" to do script ' + cmd + ' in front window'])
subprocess.check_call(args)


@staticmethod
def iterm_version():
args = ['osascript', '-e', 'tell application "iTerm" to get version']
Expand All @@ -103,6 +104,14 @@ def _dispatch_iterm(self, cmd):
'to tell current session to write text '
])
elif self.iterm_version() >= (2, 9):
if self.is_python() and len(re.findall("\n", cmd)) > 0:
chunk = "%cpaste -q\n"
subprocess.check_call([
'osascript', '-e',
'tell application "iTerm" to tell the current window ' +
'to tell current session to write text "' +
self.escape_dquote(chunk) + '" without newline'
])
n = 1000
chunks = [cmd[i:i+n] for i in range(0, len(cmd), n)]
for chunk in chunks:
Expand All @@ -112,11 +121,20 @@ def _dispatch_iterm(self, cmd):
'to tell current session to write text "' +
self.escape_dquote(chunk) + '" without newline'
])
if self.is_python() and len(re.findall("\n", cmd)) > 0:
chunk = "\n--"
subprocess.check_call([
'osascript', '-e',
'tell application "iTerm" to tell the current window ' +
'to tell current session to write text "' +
self.escape_dquote(chunk) + '" without newline'
])
subprocess.check_call([
'osascript', '-e',
'tell application "iTerm" to tell the current window ' +
'to tell current session to write text ""'
])

else:
subprocess.check_call([
'osascript', '-e',
Expand Down