Jump to content

iTerm 2 profiles workflow


Recommended Posts

I've done a little workflow for iTerm 2 users.  

 

iTerm is a great Terminal program which includes the concept of 'profiles' - a profile is a collection of terminal settings which can include things like background colour, initial command to be executed, etc.  As an example, I can open a new iTerm window which will ssh into my production web server, got to the main web directory, and has a red background to warn me I can do dangerous things here.

 

This workflow uses a Python script to extract a list of your iTerm profiles, and a bit of Applescript to tell iTerm to start up the selected one.

 

It's my first use of a script filter, and I couldn't really find any documentation, so suggestions, corrections etc are most welcome!

 

You can find the workflow here:

 

http://qandr.org/quentin/software/alfred_itp

 

Quentin

 

Link to comment

Hi,

 

great work. I had to add the "six.py" library and I had to rewrite the code slightly to get it to work:

import xml.etree.ElementTree as ET
import biplist
import os
import sys

q="{query}"

profile_file = os.path.join(
	os.environ["HOME"],
	"Library","Preferences","com.googlecode.iterm2.plist")
pl = biplist.readPlist(profile_file)
names = [nb.get('Name') for nb in pl['New Bookmarks']]
if len(q) > 1:
	names = [n for n in names if q.lower() in n.lower()]
names.sort(key=str.lower)
root = ET.Element('items')
for n in names:
	ie = ET.Element('item', valid="yes", arg=n)
	te = ET.Element('title')
	te.text = n
	ie.append(te)
	icon = ET.Element('icon')
	icon.text="icon.png"
	ie.append(icon)
	root.append(ie)
print '<?xml version="1.0"?>'
print ET.tostring(root)
print ""

And finally I also changed the AppleScript to open new tabs instead of new windows:

on alfred_script(q)
tell application "iTerm"
	activate
    set t to (last terminal)
    tell t
        launch session q
    end tell
end tell
end alfred_script

Maybe this helps others.

 

Cheers.

Edited by tolleiv
Link to comment

It didn't work for me either. In my case the problem was that Alfred is looking for python at /usr/bin/python instead of the brew's python which is at /usr/local/bin.

 

I fixed it by making links pointing /usr/bin/python to /usr/local/bin/python  (just in case I did as well /usr/bin/python-config point to /usr/local/bin/python-config which may not be needed, I don`t know too much about python and it was for free ;) )

 

BTW, nice workflow!

Link to comment

Essentially took quentin's code and re-did it a bit as well as incorporating tolleiv's modification to open it in a tab.

 

Also imported in the alp library to help with a lot of the little stuff, it's also a modified alp library so if you try to replace it with the latest from source, it'll probably break. 

 

Includes all the necessary python files for importing so it SHOULD work without needing to install anything extra but of course it'd be nice if someone could test it. 

 

https://github.com/congalong/alfred-iterm2profiles/blob/master/iTerm2_Profiles_Modified.alfredworkflow

 

Edited by soulesschild
Link to comment

Hey guys.  Looks like we're all doing terminal control work in parallel.  I wasn't sure if this workflow was being updated, and I'd had a couple requests, so I added iTerm2 support to my own ruby-based workflow.  Mostly mirrors the Apple Terminal control stuff, and I think does everything this workflow does.

 

Terminal Control Workflow

http://www.alfredforum.com/topic/2334-terminal-control-workflow/

 

Thanks to quentinsf for the general approach, and this thread for inspiring me to go ahead and add alternate terminal emulator support.

 

One note on a script above, you probably want "current terminal" and not "last terminal" for opening in a new tab.  If the current isn't the most recently opened terminal, it'll have surprising effects.

 

I'd love input from regular iTerm2 users (I'm an Apple Terminal guy myself) on what features would be helpful.  I'm more than happy to extend my workflow to encompass other common workflow patterns just for iTerm2 users.

Link to comment

Hey guys.  Looks like we're all doing terminal control work in parallel.  I wasn't sure if this workflow was being updated, and I'd had a couple requests, so I added iTerm2 support to my own ruby-based workflow.  Mostly mirrors the Apple Terminal control stuff, and I think does everything this workflow does.

 

Terminal Control Workflow

http://www.alfredforum.com/topic/2334-terminal-control-workflow/

 

Thanks to quentinsf for the general approach, and this thread for inspiring me to go ahead and add alternate terminal emulator support.

 

One note on a script above, you probably want "current terminal" and not "last terminal" for opening in a new tab.  If the current isn't the most recently opened terminal, it'll have surprising effects.

 

I'd love input from regular iTerm2 users (I'm an Apple Terminal guy myself) on what features would be helpful.  I'm more than happy to extend my workflow to encompass other common workflow patterns just for iTerm2 users.

 

Nice! I'll check it out.

Link to comment
  • 2 months later...
  • 6 months later...

GFE, check out this link:

http://rottmann.net/2013/03/launch-iterm-2-on-startup-without-opening-a-terminal-window/

 

I ran into this issue with my own Terminal Workflow:

http://www.alfredforum.com/topic/2334-terminal-control-workflow/

and that seems like the best solution outside of kludgy hacks in the applescript.

 

 

Hi,

I use your workflow quite some time now. One thing. When I lunch a profile via alfred, it always opens 2 windows (or tabs). One with the default command line and one with my selected profile. Is this a config issue? If yes, how can I disable it :).

Link to comment
  • 1 year later...

Hi, since the last alfred update some days ago the workflow stoped working. The profiles are still extracted, but when I click on one, nothing happens.

 

I don't know if it is because of the new alfred version (currently using 2.7 (385)) or the latest iterm version (2.0.0.20150412).

Link to comment

Hi, since the last alfred update some days ago the workflow stoped working. The profiles are still extracted, but when I click on one, nothing happens.

 

I don't know if it is because of the new alfred version (currently using 2.7 (385)) or the latest iterm version (2.0.0.20150412).

 

GFE, it's unclear which workflow you are talking about here.  I've tested my Terminal Control Workflow with the latest iTerm and Alfred (same versions you cited) and it's working okay for me.  If it's my workflow that's giving you problems, I'm willing to take a look, but need a bit more info.

Link to comment

Sorry, I thought it was clear because I posted it in this thread :). I'm using the itermProfiles (itp) workflow by quentin

 

Edit:

Today alfred released a new version. I installed the latest version (2.7.1 (387)) and now its working again. Seems like it was an alfred bug.

Thanks for the help.

Edited by GFEMajor
Link to comment
  • 8 months later...

Hi!

 

Check this: https://github.com/miromannino/alfred-new-terminal-window

 

It opens a new Terminal/iTerm window in the current space. 

Holding the alt key, the new window is also opened opened in the current frontmost Finder folder.

 

It is really faster compared to others, really important for me since I use the terminal for almost everything! :)

 

Hope it helps!

Edited by miromann
Link to comment
  • 2 months later...

If anyone lands here, please know that iTerm2 now has something called Automatic Profile Switching to show let you enter some pattern that could be found in the connection string that will trigger the selection of a profile. So no need for scripting if it was just for choosing a profile.

Link to comment
  • 2 months later...

Hi guys:)

 

I'm heavily using this workflow as I have to connect to several servers per ssh a day. 

 

I recently reinstalled my mac to improve development workflows etc. and so I reinstalled Alfred and iTerm. I'm using iTerm Build 2.9.20160426 and Alfred 2.8.4 (437).

 

When I select a profile with alfred iTerm opens up, but just opens the last active tab and does nothing.

 

Do you have any suggestions?

 

I'm using this suggestion here to use iTerm as default Terminal in Alfred.

http://www.alfredforum.com/topic/7138-custom-terminal-script-integrate-iterm-with-alfred-iterm-v3-beta-supported-updated-december-14-2015/

 

Really appreciate any help:)

Thank you

Link to comment
  • 1 month later...

For those of you having problems with iTerm 3.0.0+, be aware that the iTerm developers changed the way AppleScript works in the latest major revision, so pretty much all AppleScript controls (including those that are used to manage iTerm from Alfred workflows) need to be updated.

 

I've updated my own Terminal Control workflow, it was pretty straightforward.  Hopefully Quentin can update this one without any trouble, for those who prefer it.

 

 

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...