Skip to content

Instantly share code, notes, and snippets.

@kkew3
Last active April 7, 2023 14:08
Show Gist options
  • Select an option

  • Save kkew3/3802f198e8bbd82c40e456bbd1400daf to your computer and use it in GitHub Desktop.

Select an option

Save kkew3/3802f198e8bbd82c40e456bbd1400daf to your computer and use it in GitHub Desktop.

Revisions

  1. kkew3 revised this gist Apr 7, 2023. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions custom.applescript
    Original file line number Diff line number Diff line change
    @@ -24,5 +24,7 @@ on alfred_script(q)
    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
  2. kkew3 created this gist Apr 7, 2023.
    28 changes: 28 additions & 0 deletions custom.applescript
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    # 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
    end tell
    end alfred_script