stuartcryan 22 Posted August 11, 2015 (edited) Custom Terminal AppleScripts to Integrate iTerm and Alfred iTerm version 3 beta: The iTerm 3 beta version is the same version we have had for quite some time, which is also known as 2.9. Therefore the v2.9 branch of the script will work just fine with the v3 (aka 2.9) beta and v3 when it is released (any major changes to iTerm's applescript not withstanding). In a blog post released recently (19th August 2015) Vero (Alfred's Mum ) has announced that as of the next version of Alfred, these custom terminal scripts will be the available mechanism for integrating Alfred and iTerm: "With the upcoming release of Alfred 2.7.2, the default iTerm integration has been replaced by the "Custom" scripts option. This allows for a more up-to-date and more flexible way to handle the iTerm integration, using scripts created by one of our fantastic users, Stuart Ryan." I would like to thank Vítor for helping to clean up the applescripts and submitting some great pull requests . There are two versions of the script available: iTerm 2 Branch (tested up to 2.1.1) - view the v2.1 script on Github - updated December 14, 2015 iTerm 2.9 Branch (tested up to 2.9.20150626) - view the v2.9 script on Github - Updated December 14, 2015 Each of these can be inserted into Alfred by following these steps: Load the Alfred control panel Click the Features Button/Tab Click on the "Terminal/Shell" menu on the left hand side Select "Custom" under application, and replace the text in the new box that appears with the code as per the version of iTerm you are running. Alternatively, check out the official YouTube video on how to set them up: iTerm 2.1 Branch Custom Terminal Script Features: The 2.1 branch script is very basic and just corrects the opening of iTerm and creating a new session properly. Change Log: V0.4 Release - Vítor's submitted pull request for simplifying the check for if iTerm is already running. - December 14, 2015 (apologies for the delay in merging) V0.3 Release - Added version number and Vítor has done some great work standardising the scripts. No functionality changes in this release - August 14, 2015 Remove Trailing Whitespace (Vítor Galvão) - August 10, 2015 Initial Release - July 31, 2015 iTerm 2.9 Branch Custom Terminal Script Features: The 2.9 Branch goes a bit further to utilise some of the new features of iTerm 2.9 (which is in beta at the moment and can be downloaded if you are feeling adventurous from the iTerm download page). The script has been designed to achieve the following: Open the correct iTerm binary under /Applications/iTerm.app regardless of if another iterm/iTerm binary exists on the system Always create a new tab/session, unless iTerm is not running, in which case use the default session. If the user has selected to not create a default session on iTerm startup, detect and create a default session. Change Log V0.6 Release - Vítor's submitted pull request for simplifying the check for if iTerm is already running. - December 14, 2015 (apologies for the delay in merging) V0.5 Release - Added version number and Vítor has done some great work standardising the scripts. No functionality changes in this release - August 14, 2015 Removed bug introduced in last update (quotes around parameter) - August 12, 2015 Fix Whitespace (Vítor Galvão) + Fixed Search for iTerm/iTerm 2 Running (Stuart Ryan) - August 10, 2015 Updated to Fix Multiple iTerm Binaries - August 6, 2015 Initial Release - July 31, 2015 Donations If you love the scripts, and get use out of them every day, if you would like to donate as a thank you to buy me more caffeine giving Diet Coke, some Cake, or to put towards a shiny new gadget you can donate to me via Paypal. Future Updates: As new versions come out of the 2.9 branch I will keep the scripts up to date, if anyone finds issues with the 2.1 branch please let me know and I will test things out. If there are any changes to the scripts, I will post an update in this thread to let everyone know. If you would like to look at/contribute to the official repository please check it out on Github --> https://github.com/stuartcryan/custom-iterm-applescripts-for-alfred. As always, I welcome ideas/thoughts/feedback etc. Cheers, Stuart Edited March 4, 2016 by stuartcryan Quote Share this post Link to post
stuartcryan 22 Posted August 11, 2015 Hi All, Minor update to the 2.9 branch to remove a bug introduced in the last update (my bad), I forgot to remove quotes around one of the parameters. This had the effect that when iTerm was already running, you would get a 'q' rather than the command you opted to run. Cheers, Stuart Quote Share this post Link to post
stuartcryan 22 Posted August 14, 2015 Hi All, Some minor modifications to the scripts, Vítor has done some great work standardising the scripts and a version number has now been added for ease of future tracking. There are no functionality changes in this release, only code cleanup and some additional comments. Cheers, Stuart Quote Share this post Link to post
stuartcryan 22 Posted August 18, 2015 Howdy all In case you don't follow the Alfred blog (which if you don't you are missing out ), the AlfredApp team have today announced that: "With the upcoming release of Alfred 2.7.2, the default iTerm integration has been replaced by the "Custom" scripts option. This allows for a more up-to-date and more flexible way to handle the iTerm integration, using scripts created by one of our fantastic users, Stuart Ryan." So, I will be on hand to give as much support as I can during the transition, I am hoping there won't be too many issues as I know there are quite a few users out there already using the custom terminal scripts. You can switch over to the custom terminal scripts now and you will have a seamless transition when Alfred 2.7.2 comes out. If you have any questions about the scripts please do not hesitate to holler. Cheers, Stuart Quote Share this post Link to post
mondopiccolo 0 Posted August 25, 2015 Hello! very nice script! I had a small issue though, this is the timeline of the events: - iterm 2.1.1 is running (with my usual tons of tabs) - upgraded Alfred to the new version - configured Alfred to use your custom script > at this point whenever I type a command (e.g: ls), iTerm opens a new tab but nothing is actually executed Stopping iTerm and launching it again made everything work again. Quote Share this post Link to post
stuartcryan 22 Posted August 25, 2015 Hello! very nice script! I had a small issue though, this is the timeline of the events: - iterm 2.1.1 is running (with my usual tons of tabs) - upgraded Alfred to the new version - configured Alfred to use your custom script > at this point whenever I type a command (e.g: ls), iTerm opens a new tab but nothing is actually executed Stopping iTerm and launching it again made everything work again. OOOH that is a conundrum. Has it all been working OK since then (or you need to manually open iTerm each time for it to work properly?) Also when you say tons of tabs, may I ask how many on average (as I did not test the script with more than about five so might need to test more). After I have the extra info I will have a deeper squiz for you (and thank you for reporting the issue). Cheers, Stuart Quote Share this post Link to post
mondopiccolo 0 Posted August 26, 2015 No, since then it is working perfectly. Only the first time did not work correctly. I think I had about 15 opened tabs at the time. I tried just now to open tons of them and the problem also did not reappear. OOOH that is a conundrum. Has it all been working OK since then (or you need to manually open iTerm each time for it to work properly?) Also when you say tons of tabs, may I ask how many on average (as I did not test the script with more than about five so might need to test more). After I have the extra info I will have a deeper squiz for you (and thank you for reporting the issue). Cheers, Stuart Quote Share this post Link to post
stuartcryan 22 Posted August 26, 2015 No, since then it is working perfectly. Only the first time did not work correctly. I think I had about 15 opened tabs at the time. I tried just now to open tons of them and the problem also did not reappear. Awesome good to know, I will keep an eye on it, may have just been a glitch in the matrix but if I get another report I will take a closer squiz. Cheers, Stuart Quote Share this post Link to post
Maddog 2 Posted August 26, 2015 I'm using iTerm's "quake window" feature (I have a specific half-screen sized window,that drops when I hit the `~` (tilda) button). This opens a new tab in that profile, but doesn't activate the actual window. It may be related to this bug I previously opened for iTerm, which is sort-of related to activating the "hotkey profile". I would also be interesting to be able to choose whether the script ( opens a new tab / reuses one tab *it opened* / opens a window / reuses one window it opened ). Don't know if that's feasible, but I would definitely choose a reused tab/window instead of a new one every time. Thanks! Quote Share this post Link to post
stuartcryan 22 Posted August 26, 2015 I'm using iTerm's "quake window" feature (I have a specific half-screen sized window,that drops when I hit the `~` (tilda) button). This opens a new tab in that profile, but doesn't activate the actual window. It may be related to this bug I previously opened for iTerm, which is sort-of related to activating the "hotkey profile". I would also be interesting to be able to choose whether the script ( opens a new tab / reuses one tab *it opened* / opens a window / reuses one window it opened ). Don't know if that's feasible, but I would definitely choose a reused tab/window instead of a new one every time. Thanks! Hi Maddog, Can I please ask, what version of iTerm are you running? I will have to have a look as that may require some additional logic (I will have to play with the feature as I have not used it before). Also with regards to the new feature, that is possible but it would be on an all or nothing basis, i.e. it can't really be set at run time. So are you looking for a set one off to change how the script as a whole runs or are you looking for something you can change each time it runs depending on what behaviour you would like at that time (just wanting to clarify, as the latter is not really possible). Cheers, Stuart Quote Share this post Link to post
Maddog 2 Posted August 26, 2015 (edited) @stuartcryan - I'm on the bleeding edge of iTerm I think (Build 2.9.20150812-nightly) As for the new feature - would it be like a boolean you configure at the top of the script? Or actually a different script? I want to understand what "all or nothing" means, I don't mind if it's not configurable in a UI, but would love a way to be able to quickly change it in the custom script code. Also, this is funny, but I'm actually experiencing different results whether I'm cmd+tabbing away from that hotkey window or if I'm hiding it with the hotkey itself (I get a new tab in a new window vs. new tab in the hotkey profile window). This actually is related to the iTerm bug I posted, haha Thanks. Edited August 26, 2015 by Maddog Quote Share this post Link to post
stuartcryan 22 Posted August 26, 2015 @stuartcryan - I'm on the bleeding edge of iTerm I think (Build 2.9.20150812-nightly) As for the new feature - would it be like a boolean you configure at the top of the script? Or actually a different script? I want to understand what "all or nothing" means, I don't mind if it's not configurable in a UI, but would love a way to be able to quickly change it in the custom script code. Also, this is funny, but I'm actually experiencing different results whether I'm cmd+tabbing away from that hotkey window or if I'm hiding it with the hotkey itself (I get a new tab in a new window vs. new tab in the hotkey profile window). This actually is related to the iTerm bug I posted, haha Thanks. Good to know on the version I will have a squiz and see what I can come up with. I was actually thinking along the lines of a boolean in the script itself (rather than a separate script). So I think that would suit exactly what you are looking for. And that is strangeeeee I might have a play and see if I need to ask for some extra applescript additions in iTerm to help get around it even in the long term. Cheers, Stuart Quote Share this post Link to post
stuartcryan 22 Posted August 26, 2015 @stuartcryan - All righty, I have logged two issues on github for you: 1. https://github.com/stuartcryan/custom-iterm-applescripts-for-alfred/issues/7- Feature request 2. https://github.com/stuartcryan/custom-iterm-applescripts-for-alfred/issues/6- Investigate bug relating to iTerm behaviour Cheers, Stuart Quote Share this post Link to post
stuartcryan 22 Posted September 11, 2015 @stuartcryan - I'm on the bleeding edge of iTerm I think (Build 2.9.20150812-nightly) As for the new feature - would it be like a boolean you configure at the top of the script? Or actually a different script? I want to understand what "all or nothing" means, I don't mind if it's not configurable in a UI, but would love a way to be able to quickly change it in the custom script code. Also, this is funny, but I'm actually experiencing different results whether I'm cmd+tabbing away from that hotkey window or if I'm hiding it with the hotkey itself (I get a new tab in a new window vs. new tab in the hotkey profile window). This actually is related to the iTerm bug I posted, haha Thanks. Howdy my good man, Any chance you could do a screen recording of the issue (and upload to youtube as private? or alternatively I can set up an SFTP location for you). Just want to get a better idea of how it all works as I haven't used the quake feature before. Cheers, Stuart Quote Share this post Link to post
Maddog 2 Posted September 11, 2015 The actual problem is a bug with iterm (described below in more detail), so I don't really think you can fix it from outside. But FWIW, here's how I setup the "quake window" feature. I have a special profile called "hotkey window" which is configured in the bottom left corner of the screenshot. In the profile setting, it's configured to show up at "top of screen". That's the entire story I use the ~ (tilda) button to show/hide it. The thing is, it's a little buggy (I opened a bug in iterm), when I toggle it off with the hotkey, it's impossible to use cmd+tab to get back to the window. A similar problem happens here, where if it's hidden with the hotkey, it probably cannot be detected so it opens a new iterm window. Note that when it happened to me, I only had the "hotkey window" open, no other iterm windows. Quote Share this post Link to post
stuartcryan 22 Posted September 18, 2015 The actual problem is a bug with iterm (described below in more detail), so I don't really think you can fix it from outside. But FWIW, here's how I setup the "quake window" feature. ... That's the entire story I use the ~ (tilda) button to show/hide it. The thing is, it's a little buggy (I opened a bug in iterm), when I toggle it off with the hotkey, it's impossible to use cmd+tab to get back to the window. A similar problem happens here, where if it's hidden with the hotkey, it probably cannot be detected so it opens a new iterm window. Note that when it happened to me, I only had the "hotkey window" open, no other iterm windows. Boo that is a shame, something I won't be able to fix for the time being. Hopefully they can resolve that soon in the iTerm binary. If there are any changes as a result after the fix I can look at making those in the AppleScript. Cheers, Stuart Quote Share this post Link to post
stuartcryan 22 Posted December 13, 2015 Howdy all, Vitor has done some awesome work and closed out a couple of tasks, I apologise for the delay in merging them but I have been unwell. All back to normal now and new version of the scripts have been released, so I suggest you get your hands on the latest version from: iTerm 2 Branch (tested up to 2.1.1) - view the v2.1 script on Github - updated December 14, 2015 iTerm 2.9 Branch (tested up to 2.9.20150626) - view the v2.9 script on Github - Updated December 14, 2015 Thank you Vitor for your efforts, you rule! Cheers, Stuart Quote Share this post Link to post
stuartcryan 22 Posted March 4, 2016 Howdy everyone, Just to clarify for you (as a few people have asked, and I myself had a bit of confusion surrounding this). The iTerm 3 beta version is the same version we have had for quite some time, which is also known as 2.9. Therefore the v2.9 branch of the script will work just fine with the v3 (aka 2.9) beta and v3 when it is released (any major changes to iTerm's applescript not withstanding). As always if you have any issues please log a request over at Github. I am hoping to get some time to work on these scripts soon. Cheers, Stuart Quote Share this post Link to post
seanboramlee 2 Posted January 24, 2017 Hi Stuart, Any chance you could provide some guidance on writing an integration for Hyper? Thanks! Sean 2 joeynotjoe and chrisWhite reacted to this Quote Share this post Link to post
joeynotjoe 2 Posted May 5, 2017 I would love an integration with Hyper, too! 1 chrisWhite reacted to this Quote Share this post Link to post
mrchow19910319 1 Posted October 15, 2018 (edited) may I know that how do I modify this to make alfred to open a new iterm window (even there are existing windows in the background) everytime I enter something after `>` ? Edited October 15, 2018 by mrchow19910319 Quote Share this post Link to post