Skip to content

Commit

Permalink
RunCommand: finish WarpTerminal support
Browse files Browse the repository at this point in the history
  • Loading branch information
pilotmoon committed Mar 28, 2024
1 parent cfb5d8d commit 8b0c52c
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 38 deletions.
Binary file modified extensions/RunCommand.popclipextz
Binary file not shown.
17 changes: 7 additions & 10 deletions source/RunCommand.popclipext/Config.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,12 @@
],
"applescript file": "terminal.applescript"
},
{
"requirements": [
"text",
"option-term=iTerm2"
],
"applescript file": "iterm2.applescript"
},
{
"requirements": [
"text",
"option-term=iTerm2 v2.9+"
],
"applescript file": "iterm2-3.applescript"
"applescript file": "iterm2.applescript"
},
{
"requirements": [
Expand All @@ -41,11 +34,15 @@
"values": [
"Terminal",
"iTerm2 v2.9+",
"Warp"
],
"valueLabels": [
"Terminal",
"iTerm2",
"Warp"
],
"identifier": "term"
}
],
"description": "Run the selected text as a terminal command. Supports both Terminal and iTerm2. (Now updated for iTerm2 v2.9.)"
}
"description": "Run the selected text as a terminal command. Supports Terminal, iTerm2 and Warp."
}
16 changes: 7 additions & 9 deletions source/RunCommand.popclipext/README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
RunCommand
==============
# RunCommand

Run Terminal Command extension for PopClip.

One can choose either Terminal or iTerm2.
Runs the selected text as a command in the current Terminal window.

One can choose either Terminal, iTerm2 or Warp Terminal.

2 Jun 2015: Separated the two sides into separate actions. Having both apps referenced in one script was causing problems.

19 Feb 2016: Added third config option to support iTerm2 v2.9 and above, which has breaking AppleScript changes.

28 Mar 2024: Added fourth config option to support Warp Terminal.

Credits
-------
Original extension and icon created by [James Smith](https://twitter.com/smithjw/status/244757999665700864).
28 Mar 2024: Removed the legacy iTerm option and added Warp Terminal.

iTerm option added by [honnix](https://github.com/honnix).
## Credits

Original extension and icon created by [James Smith](https://twitter.com/smithjw/status/244757999665700864). iTerm option added by [honnix](https://github.com/honnix). Warp support added by Oliver using script from [parterburn](https://gist.github.com/parterburn/e832b9090ee35eb830529de8bd978b82).
9 changes: 0 additions & 9 deletions source/RunCommand.popclipext/iterm2-3.applescript

This file was deleted.

3 changes: 2 additions & 1 deletion source/RunCommand.popclipext/iterm2.applescript
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
-- new version of script for iTerm2 v2.9+
tell application id "com.googlecode.iterm2"
activate
set _session to current session of current terminal
set _session to current session of current window
tell _session
set command to get the clipboard
write text "{popclip text}"
Expand Down
71 changes: 62 additions & 9 deletions source/RunCommand.popclipext/warp.applescript
Original file line number Diff line number Diff line change
@@ -1,9 +1,62 @@
tell application "Warp"
activate
-- If there are no open windows, open one.
if (count of windows) is less than 1 then
do script ""
end if
set theTab to selected tab in first window
do script "{popclip text}" in theTab
end tell
-- For the latest version:
-- https://gist.github.com/parterburn/e832b9090ee35eb830529de8bd978b82

-- Set this property to true to always open in a new window
property open_in_new_window : false

-- Set this property to false to reuse the current tab
property open_in_new_tab : false

-- Handlers
on new_window()
tell application "System Events"
tell process "Warp"
keystroke "n" using command down
end tell
end tell
end new_window

on new_tab()
tell application "System Events"
tell process "Warp"
keystroke "t" using command down
end tell
end tell
end new_tab

on call_forward()
tell application "Warp"
activate
tell application "System Events"
tell process "Warp"
set frontmost to true
end tell
end tell
end tell
end call_forward

on send_text(custom_text)
tell application "System Events"
tell process "Warp"
delay 0.5
keystroke custom_text
delay 0.5
key code 36
end tell
end tell
end send_text

-- Main

call_forward()

if open_in_new_window then
new_window()
else if open_in_new_tab then
new_tab()
else
-- Reuse the current tab
end if

call_forward()
send_text("{popclip text}")

0 comments on commit 8b0c52c

Please sign in to comment.