Skip to content

Instantly share code, notes, and snippets.

@kkew3
Last active April 7, 2023 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kkew3/3802f198e8bbd82c40e456bbd1400daf to your computer and use it in GitHub Desktop.
Save kkew3/3802f198e8bbd82c40e456bbd1400daf to your computer and use it in GitHub Desktop.
Setting Alfred Terminal to iTerm2 without wrangling around current iTerm2 window.
# Paste this script to "Alfred Preference > Advanced > Terminal",
# selecting "Application" to "Custom".
#
# In addition, create an iTerm2 profile with string "Alfred" in its Name,
# for example, "Working with Alfred".
#
# The script below will open the first iTerm2 session with such profile,
# or create a new window with that profile if not found. The command
# will be executed there.
on alfred_script(q)
tell application "iTerm"
set theAlfredSession to null
repeat with aWindow in windows
tell aWindow
if (profile name of current session) contains "Alfred" then
set theAlfredSession to (current session)
exit repeat
end if
end tell
end repeat
if theAlfredSession is null then
set newWindow to (create window with profile "Working with Alfred")
set theAlfredSession to current session of newWindow
end if
tell theAlfredSession to write text q
# or add a space before `q` to prevent it from going into history:
#tell theAlfredSession to write text (space & q)
end tell
end alfred_script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment