Last active
December 5, 2022 17:19
-
-
Save hohonuuli/b99e930a53248dcd63b23ca37d8d9022 to your computer and use it in GitHub Desktop.
Script for CotEditor. Opens the parent directory of the currently edited file in Warp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
property showAlertDialog : true | |
-- get file path from CotEditor | |
tell application "CotEditor" | |
if not (exists front document) then return | |
set theFile to file of front document | |
end tell | |
-- end script if no file path is specified | |
if theFile is missing value then | |
if showAlertDialog then | |
beep | |
display alert "No file path is specified." message "Please save the file first." as warning | |
return | |
end if | |
return | |
end if | |
-- start Warp if needed | |
on call_forward() | |
tell application "Warp" to activate | |
end call_forward | |
-- Open a tab. Change keystroke to "n" to open in a new window instead | |
on new_tab() | |
tell application "System Events" | |
tell process "Warp" | |
keystroke "t" using command down | |
end tell | |
end tell | |
end new_tab | |
-- Send a command to warp. | |
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 | |
-- get directory path | |
set dirPath to do shell script "dirname " & quoted form of (theFile's POSIX path) | |
-- Build a cd command to send to warp | |
set cdCmd to "cd " & quoted form of dirPath | |
-- Do the magic | |
call_forward() | |
new_tab() | |
send_text(cdCmd) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment