Oli. Posted April 2, 2023 Share Posted April 2, 2023 (edited) I hunted around for how to do this and the only thing I could find was how to do it with iTerm. There is some talk about how to do it with Warp but the consensus was that you just can't because Warp "has no AppleScript support". There is actually a way to do it. (Though this is a workaround because you can't use AppleScript to script Warp) I found this on GitHub; most of the code is unnecessary unless you want to customize tab and window behavior. Here's a simplified version I made. GitHub gist here. on alfred_script(q) tell application "System Events" tell application "Warp" to activate set numWin to count (windows of process "Warp") if numWin < 1 then keystroke "n" using command down delay 0.5 keystroke q keystroke return end tell end alfred_script About the delay... If Warp is already running, you don't need the delay. If it's not already running, the minimum delay for it to work is 0.3 (at least on my machine). I don't know how to check if an app is running using AppleScript, but if I did, I would add an if statement before the activation to set the delay only if the app isn't running yet. If anyone knows how to do that we can save 0.3 precious seconds. Edited April 3, 2023 by Oli. Link to comment
vitor Posted April 2, 2023 Share Posted April 2, 2023 Welcome @Oli., 6 hours ago, Oli. said: the minimum delay for it to work is 0.3 (at least on my machine). That is exactly why the consensus is that there is no proper way to do it. What you’re doing is called GUI automation and is very error prone. It is the equivalent of automating a web browser to click certain parts of the interface instead of using an API. You can certainly get it to work, but it is finicky. For example, when you run that and your machine is under a bit more load, the delay will no longer work. Worse, you can end up sending your typing to the wrong application and pressing ↩. It may even be that part of your command is sent and executed, which can have bad results. Furthermore, you can’t rely on it working correctly on another’s machine. Finally, AppleScript is unreliable when sending keystrokes, e.g. with character that would necessitate a ⇧. The receiving app (Warp) needs to add automation capabilities for it to work properly. Like iTerm2 does. 6 hours ago, Oli. said: I don't know how to check if an app is running using AppleScript if application "Warp" is running then -- DO THINGS HERE end if Link to comment
Oli. Posted April 2, 2023 Author Share Posted April 2, 2023 38 minutes ago, vitor said: That is exactly why the consensus is that there is no proper way to do it. What you’re doing is called GUI automation and is very error prone. It is the equivalent of automating a web browser to click certain parts of the interface instead of using an API. You can certainly get it to work, but it is finicky. Thank you for the info! Sending keystrokes like that does seem a little hacky and your browser metaphor is dead on. Maybe Warp will add support for this at some point. I'm not sure how it would be possible for the keystrokes to be sent to the wrong application when it's within the 'tell process "Warp"' block. I'm (obviously) not super familiar with AppleScript, so I'll just trust you on this one. For now this seems to be working and, given I'll only ever be using this for very simple commands, I'm not super worried. 38 minutes ago, vitor said: if application "Warp" is running then Thank you for this. I'm sure if I use Alfred for 10 years straight those 0.3 seconds saved will add up to the time I spent working on this. Link to comment
pixelgeek Posted April 2, 2023 Share Posted April 2, 2023 2 hours ago, Oli. said: Maybe Warp will add support for this at some point. That is the downside to using Electron. I don't think it can and most devs don't seem to care that they are missing features like that. Link to comment
vitor Posted April 3, 2023 Share Posted April 3, 2023 18 hours ago, Oli. said: 'm not sure how it would be possible for the keystrokes to be sent to the wrong application when it's within the 'tell process "Warp"' block. What happens is that the process is telling macOS to type the characters. In other words, the block doesn’t mean “write these characters into this process’s window” it means “type this keys”. So if Warp has a setting to open without windows, or the window takes to long to come to the front, or another app steals the focus right after, the characters will still be pressed but affect whatever else is in focus. Link to comment
Oli. Posted April 3, 2023 Author Share Posted April 3, 2023 (edited) 8 hours ago, vitor said: What happens is that the process is telling macOS to type the characters. In other words, the block doesn’t mean “write these characters into this process’s window” it means “type this keys”. Ah ok. So does that mean that that block doesn't actually do anything? Like the same thing would happen if you only wrapped it in - tell application "System Events"? Edited April 3, 2023 by Oli. Link to comment
xilopaint Posted July 21, 2023 Share Posted July 21, 2023 Anyone interested on AppleScript support for Warp can give a 👍 in the original post of this issue: https://github.com/warpdotdev/Warp/issues/3364. It helps the team to prioritize it. raider7593 1 Link to comment
xilopaint Posted July 23, 2023 Share Posted July 23, 2023 (edited) Hey @vitor, a Warp team member said there’s a new URI scheme “for opening a new window/tab/launch configurations/etc” that has been used by Raycast. Would it be possible to use it to integrate Warp to Alfred? Edited July 23, 2023 by xilopaint Link to comment
vitor Posted July 23, 2023 Share Posted July 23, 2023 Alfred’s Terminal support can take arbitrary AppleScript. That’s how the iTerm support works. You can open arbitrary URLs using open location in AppleScript. Link to comment
xilopaint Posted July 23, 2023 Share Posted July 23, 2023 (edited) 1 hour ago, vitor said: Alfred’s Terminal support can take arbitrary AppleScript. That’s how the iTerm support works. You can open arbitrary URLs using open location in AppleScript. Yes, that’s what I thought. However, if I got this thread right, their URI scheme isn’t enough to have a reliable integration since we don’t have an option to send text as we can do in iTerm via the write command. Am I correct? Edited July 23, 2023 by xilopaint Link to comment
Jasondm007 Posted August 25, 2023 Share Posted August 25, 2023 Hi @xilopaint - Did you ever have any luck with the new Warp URI? It looks like it's only for opening new tabs and windows to specific file locations, but I might be missing something. Like yourself, I'd love to be able to run commands in new Warp windows/tabs via Alfred (i.e., without relying on some clunky GUI-based approach). Thanks for your help! Link to comment
xilopaint Posted August 25, 2023 Share Posted August 25, 2023 (edited) 37 minutes ago, Jasondm007 said: Hi @xilopaint - Did you ever have any luck with the new Warp URI? There are some plans for additional URI, but no ETA from Warp team. Edited August 25, 2023 by xilopaint Jasondm007 1 Link to comment
V2arK Posted January 24 Share Posted January 24 wrote a alfred workflow for it. Here it is: https://github.com/V2arK/alfred-warp-intergration/ Jasondm007 1 Link to comment
Jasondm007 Posted January 25 Share Posted January 25 Hi @V2arK - Thanks a ton for sharing your Warp workflow! I really appreciate it. The workflow is great, and I'm looking forward to using it more!! If you update it down the road, one minor recommendation: It'd be great if the workflow would create the hidden directory for users that don't already have it. When I first tried to use the workflow, I couldn't get it to work for that reason. Apparently, Warp doesn't create the directory unless the user has already created a launch config file in the past. It was easy enough to fix (e.g., I just created a temp one through the file menu). But others may run into this problem if they haven't already created launch config files, too. Thanks again for sharing the workflow!! Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now