Skip to content

Instantly share code, notes, and snippets.

@tapsu01
Forked from pdanford/README.md
Created December 2, 2020 16:18
Show Gist options
  • Select an option

  • Save tapsu01/7bada347251cf0f2ff4265febb55b872 to your computer and use it in GitHub Desktop.

Select an option

Save tapsu01/7bada347251cf0f2ff4265febb55b872 to your computer and use it in GitHub Desktop.

Revisions

  1. @pdanford pdanford revised this gist Apr 30, 2020. 1 changed file with 35 additions and 36 deletions.
    71 changes: 35 additions & 36 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -19,7 +19,7 @@ This is only active when a folder is currently selected in a Finder window that
    1. Run Automator, `File -> New` and choose **Quick Action**.
    2. Click `Library -> Utilities` and double click **Run AppleScript**.
    3. Workflow receives **Automatic (Nothing)** in **any application**.
    4. Paste the script from [Applescript](#applescript) section below.
    4. Paste the script from [AppleScript](#AppleScript) section below.
    5. Save; if Automator tries to save to iCloud drive, better to save locally - save as **iTermOpenHereScript.workflow** to the Desktop and then move it to **~/Library/Services**.
    6. Add the keyboard shortcut under `System Preferences -> Keyboard -> Shortcuts -> Services` under the `General` section. Check **iTermOpenHereScript** and Add Shortcut. Note that the first time you launch there may be a security popup saying iTermOpenHereScript wants access... Click OK to all.
    7. To prevent two windows from opening when you use the keyboard Shortcut when iTerm2 is not already running, set iTerm2's `Preferences -> General -> Startup` to **Only Restore Hotkey Window** for the Window restoration policy.
    @@ -34,49 +34,48 @@ The Desktop having focus isn't really the intended use case, but for completenes
    ### From the working directory of a Finder window - via Finder toolbar icon
    1. Run Automator, `File -> New` and choose **Application**.
    2. Click `Library -> Utilities` and double click **Run AppleScript**.
    3. Paste the script from [Applescript](#applescript) section below.
    3. Paste the script from [AppleScript](#AppleScript) section below.
    4. Save; if Automator tries to save to iCloud drive, better to save locally - save as **iTermOpenHereScript.app** to the Desktop and then move it to **~/Library/Services**.
    5. Drag and drop iTermOpenHereScript.app onto the Finder toolbar while holding down the <kbd>option</kbd>+<kbd>command</kbd> keys to place a toolbar launch icon. Note that the first time you launch there may be a security popup saying iTermOpenHereScript wants access... Click OK to all.
    6. Right click on the spot on the toolbar and select **Icon Only**. To replace the generic Automator app icon with the iTerm2 icon, <kbd>command</kbd>+<kbd>i</kbd> on the original iTerm.app file, select the application icon in the top left corner of the window and <kbd>command</kbd>+<kbd>c</kbd>. Then do <kbd>command</kbd>+<kbd>i</kbd> to iTermOpenHereScript.app file, select the application icon in the top left corner of the window and <kbd>command</kbd>+<kbd>v</kbd>.
    7. To prevent two windows from opening when you click the toolbar launch icon when iTerm2 is not already running, set iTerm2's `Preferences -> General -> Startup` to **Only Restore Hotkey Window** for the Window restoration policy.
    8. To make windows open a bit faster, in iTerm2's `Preferences -> General -> Closing` uncheck **Quit when all windows are closed**.

    ---
    ### Applescript
    ```
    on run {input, parameters}
    set frontApp to (path to frontmost application as Unicode text)
    if (frontApp does not contain "Finder.app") then
    -- Finder does not have focus.
    return
    end if
    tell application "Finder"
    set listSize to count of (every window)
    if listSize is equal to 0 then
    -- The Finder desktop has focus and no windows anywhere else. default to home dir.
    set dir_path to "~"
    else
    try
    set dir_path to quoted form of (POSIX path of (folder of the front window as alias))
    on error errMsg
    -- This is a special dir (e.g. Network or "machine name"). default to home dir.
    set dir_path to "~"
    end try
    ### AppleScript

    on run {input, parameters}
    set frontApp to (path to frontmost application as Unicode text)
    if (frontApp does not contain "Finder.app") then
    -- Finder does not have focus.
    return
    end if
    end tell
    CD_to(dir_path)
    end run
    on CD_to(theDir)
    tell application "iTerm"
    set term_window to (create window with default profile)
    set sesh to (current session of term_window)
    tell sesh to write text "cd " & theDir & ";clear"
    end tell
    end CD_to
    ```

    tell application "Finder"
    set listSize to count of (every window)
    if listSize is equal to 0 then
    -- The Finder desktop has focus and no windows anywhere else. default to home dir.
    set dir_path to "~"
    else
    try
    set dir_path to quoted form of (POSIX path of (folder of the front window as alias))
    on error errMsg
    -- This is a special dir (e.g. Network or "machine name"). default to home dir.
    set dir_path to "~"
    end try
    end if
    end tell

    CD_to(dir_path)
    end run

    on CD_to(theDir)
    tell application "iTerm"
    set term_window to (create window with default profile)
    set sesh to (current session of term_window)
    tell sesh to write text "cd " & theDir & ";clear"
    end tell
    end CD_to

    ---
    :scroll: [MIT License](https://github.com/pdanford/Launching-iTerm2-from-macOS-Finder/blob/master/README.license)
  2. @pdanford pdanford revised this gist Apr 18, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -79,4 +79,4 @@ end CD_to
    ```

    ---
    :scroll: [MIT License](https://github.com/pdanford/Launching-iTerm2-from-macOS-Finder/blob/master/LICENSE)
    :scroll: [MIT License](https://github.com/pdanford/Launching-iTerm2-from-macOS-Finder/blob/master/README.license)
  3. @pdanford pdanford revised this gist Apr 18, 2020. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -5,6 +5,8 @@ Launching iTerm2 from macOS Finder

    The following three ways to launch an iTerm2 window from Finder have been tested on iTerm2 version 3+ running on macOS Mojave+.

    pdanford - April 2020

    ---
    ### From a selected directory in a Finder window - via keyboard Shortcut
    Starting sometime with iTerm2 version 3.x, it puts **New iTerm2 Window Here** in `System Preferences -> Keyboard -> Shortcuts -> Services` under the `Files and Folders section`. You just have to check it and `Add Shortcut`.
    @@ -75,6 +77,6 @@ on CD_to(theDir)
    end tell
    end CD_to
    ```

    ---
    pdanford - April 2020<br>
    :scroll: [MIT License](https://github.com/pdanford/Launching-iTerm2-from-macOS-Finder/blob/master/LICENSE)
  4. @pdanford pdanford revised this gist Apr 17, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -77,4 +77,4 @@ end CD_to
    ```
    ---
    pdanford - April 2020<br>
    :scroll: [MIT License](LICENSE)
    :scroll: [MIT License](https://github.com/pdanford/Launching-iTerm2-from-macOS-Finder/blob/master/LICENSE)
  5. @pdanford pdanford revised this gist Apr 17, 2020. 1 changed file with 20 additions and 9 deletions.
    29 changes: 20 additions & 9 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,16 @@
    # Launching iTerm2 from macOS Finder
    (Based on info from [Peter Downs' gitub](https://github.com/peterldowns/iterm2-finder-tools) but with modified behavior to open a new terminal window for each invocation instead of reusing an already open window.)
    Launching iTerm2 from macOS Finder
    ==================================

    Note that sometimes macOS doesn’t register a new keyboard Shortcut assignment immediately and may even require an OS restart to get it working. But also make sure the keyboard Shortcut is unique and not already assigned somewhere else.
    (Based on info from [Peter Downs' gitub](https://github.com/peterldowns/iterm2-finder-tools) but with modified behavior to open a new terminal window for each invocation instead of reusing an already open window.)

    The following three ways to launch an iTerm2 window from Finder have been tested on iTerm2 version 3+ running on macOS Mojave+.

    ---
    ### From a selected directory in a Finder window - via keyboard Shortcut
    Starting sometime with iTerm2 version 3.x, it puts **New iTerm2 Window Here** in `System Preferences -> Keyboard -> Shortcuts -> Services` under the `Files and Folders section`. You just have to check it and `Add Shortcut`.

    Note that sometimes macOS doesn’t register a new keyboard Shortcut assignment immediately and may even require an OS restart to get it working. But also make sure the keyboard Shortcut is unique and not already assigned somewhere else.

    This is only active when a folder is currently selected in a Finder window that has focus.

    ### From the working directory of a Finder window - via keyboard Shortcut
    @@ -19,6 +21,9 @@ This is only active when a folder is currently selected in a Finder window that
    5. Save; if Automator tries to save to iCloud drive, better to save locally - save as **iTermOpenHereScript.workflow** to the Desktop and then move it to **~/Library/Services**.
    6. Add the keyboard shortcut under `System Preferences -> Keyboard -> Shortcuts -> Services` under the `General` section. Check **iTermOpenHereScript** and Add Shortcut. Note that the first time you launch there may be a security popup saying iTermOpenHereScript wants access... Click OK to all.
    7. To prevent two windows from opening when you use the keyboard Shortcut when iTerm2 is not already running, set iTerm2's `Preferences -> General -> Startup` to **Only Restore Hotkey Window** for the Window restoration policy.
    8. To make windows open a bit faster, in iTerm2's `Preferences -> General -> Closing` uncheck **Quit when all windows are closed**.

    Note that sometimes macOS doesn’t register a new keyboard Shortcut assignment immediately and may even require an OS restart to get it working. But also make sure the keyboard Shortcut is unique and not already assigned somewhere else.

    This is only active when a Finder window (or the Desktop itself) has focus (and ignores any selected Finder directory).

    @@ -32,24 +37,30 @@ The Desktop having focus isn't really the intended use case, but for completenes
    5. Drag and drop iTermOpenHereScript.app onto the Finder toolbar while holding down the <kbd>option</kbd>+<kbd>command</kbd> keys to place a toolbar launch icon. Note that the first time you launch there may be a security popup saying iTermOpenHereScript wants access... Click OK to all.
    6. Right click on the spot on the toolbar and select **Icon Only**. To replace the generic Automator app icon with the iTerm2 icon, <kbd>command</kbd>+<kbd>i</kbd> on the original iTerm.app file, select the application icon in the top left corner of the window and <kbd>command</kbd>+<kbd>c</kbd>. Then do <kbd>command</kbd>+<kbd>i</kbd> to iTermOpenHereScript.app file, select the application icon in the top left corner of the window and <kbd>command</kbd>+<kbd>v</kbd>.
    7. To prevent two windows from opening when you click the toolbar launch icon when iTerm2 is not already running, set iTerm2's `Preferences -> General -> Startup` to **Only Restore Hotkey Window** for the Window restoration policy.
    8. To make windows open a bit faster, in iTerm2's `Preferences -> General -> Closing` uncheck **Quit when all windows are closed**.

    ---
    ### Applescript
    ```
    on run {input, parameters}
    set frontApp to (path to frontmost application as Unicode text)
    if (frontApp does not contain "Finder.app") then
    -- Finder does not have focus
    -- Finder does not have focus.
    return
    end if
    tell application "Finder"
    set listSize to count of (every window)
    if listSize is equal to 0 then
    -- the Finder desktop has focus and no windows anywhere else
    -- The Finder desktop has focus and no windows anywhere else. default to home dir.
    set dir_path to "~"
    else
    set dir_path to quoted form of (POSIX path of (folder of the front window as alias))
    try
    set dir_path to quoted form of (POSIX path of (folder of the front window as alias))
    on error errMsg
    -- This is a special dir (e.g. Network or "machine name"). default to home dir.
    set dir_path to "~"
    end try
    end if
    end tell
    @@ -58,12 +69,12 @@ end run
    on CD_to(theDir)
    tell application "iTerm"
    activate
    set term_window to (create window with default profile)
    set sesh to (current session of term_window)
    tell sesh to write text "cd " & theDir & ";clear"
    end tell
    end CD_to
    ```

    pdanford - Apr 2020. MIT License, etc.
    ---
    pdanford - April 2020<br>
    :scroll: [MIT License](LICENSE)
  6. @pdanford pdanford revised this gist Apr 2, 2020. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    # Launching iTerm2 from macOS Finder
    (Based on info from Peter Downs' [gitub](https://github.com/peterldowns/iterm2-finder-tools) but with modified behavior to open a new terminal window for each invocation instead of reusing an already open window.)
    (Based on info from [Peter Downs' gitub](https://github.com/peterldowns/iterm2-finder-tools) but with modified behavior to open a new terminal window for each invocation instead of reusing an already open window.)

    Note that sometimes macOS doesn’t register a new keyboard Shortcut assignment immediately and may even require an OS restart to get it working. But also make sure the keyboard Shortcut is unique and not already assigned somewhere else.

    @@ -17,10 +17,10 @@ This is only active when a folder is currently selected in a Finder window that
    3. Workflow receives **Automatic (Nothing)** in **any application**.
    4. Paste the script from [Applescript](#applescript) section below.
    5. Save; if Automator tries to save to iCloud drive, better to save locally - save as **iTermOpenHereScript.workflow** to the Desktop and then move it to **~/Library/Services**.
    6. Add the keyboard shortcut under `System Preferences -> Keyboard -> Shortcuts -> Services` under the `General` section. Check **iTermOpenHereScrip** and Add Shortcut. Note that the first time you launch there may be a security popup saying iTermOpenHereScript wants access... Click OK to all.
    6. Add the keyboard shortcut under `System Preferences -> Keyboard -> Shortcuts -> Services` under the `General` section. Check **iTermOpenHereScript** and Add Shortcut. Note that the first time you launch there may be a security popup saying iTermOpenHereScript wants access... Click OK to all.
    7. To prevent two windows from opening when you use the keyboard Shortcut when iTerm2 is not already running, set iTerm2's `Preferences -> General -> Startup` to **Only Restore Hotkey Window** for the Window restoration policy.

    This is only active when a Finder window (or the Desktop itself) has focus.
    This is only active when a Finder window (or the Desktop itself) has focus (and ignores any selected Finder directory).

    The Desktop having focus isn't really the intended use case, but for completeness, if it's the Desktop that has focus the working directory of its last focused still-open Finder window is used. If the current Desktop does not have any Finder windows, it's a bit indeterministic, but a working directory from a Finder window in other Space is used. If there are no Finder windows open in any other Spaces, it will default to the user's home directory.

    @@ -66,4 +66,4 @@ on CD_to(theDir)
    end CD_to
    ```

    pdanford - Mar 2020. MIT License, etc.
    pdanford - Apr 2020. MIT License, etc.
  7. @pdanford pdanford revised this gist Mar 31, 2020. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -18,6 +18,7 @@ This is only active when a folder is currently selected in a Finder window that
    4. Paste the script from [Applescript](#applescript) section below.
    5. Save; if Automator tries to save to iCloud drive, better to save locally - save as **iTermOpenHereScript.workflow** to the Desktop and then move it to **~/Library/Services**.
    6. Add the keyboard shortcut under `System Preferences -> Keyboard -> Shortcuts -> Services` under the `General` section. Check **iTermOpenHereScrip** and Add Shortcut. Note that the first time you launch there may be a security popup saying iTermOpenHereScript wants access... Click OK to all.
    7. To prevent two windows from opening when you use the keyboard Shortcut when iTerm2 is not already running, set iTerm2's `Preferences -> General -> Startup` to **Only Restore Hotkey Window** for the Window restoration policy.

    This is only active when a Finder window (or the Desktop itself) has focus.

  8. @pdanford pdanford revised this gist Mar 31, 2020. 1 changed file with 63 additions and 35 deletions.
    98 changes: 63 additions & 35 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,40 +1,68 @@
    To launch an iTerm2 window from macOS Finder via Finder toolbar icon
    ================================================================================
    # Launching iTerm2 from macOS Finder
    (Based on info from Peter Downs' [gitub](https://github.com/peterldowns/iterm2-finder-tools) but with modified behavior to open a new terminal window for each invocation instead of reusing an already open window.)

    The following has been tested on iTerm2 version 3+ running on macOS Mojave+.
    Note that sometimes macOS doesn’t register a new keyboard Shortcut assignment immediately and may even require an OS restart to get it working. But also make sure the keyboard Shortcut is unique and not already assigned somewhere else.

    To open an iTerm2 window at the current Finder directory by clicking an icon that resides on Finder's toolbar
    --------------------------------------------------------------------------------
    The following three ways to launch an iTerm2 window from Finder have been tested on iTerm2 version 3+ running on macOS Mojave+.

    1. Run Automator, ```File -> New``` and choose **Application**.
    2. Click ```Lirary -> Utilities``` and double click **Run AppleScript**.
    3. Paste script:
    ```
    on run {input, parameters}
    tell application "Finder"
    ---
    ### From a selected directory in a Finder window - via keyboard Shortcut
    Starting sometime with iTerm2 version 3.x, it puts **New iTerm2 Window Here** in `System Preferences -> Keyboard -> Shortcuts -> Services` under the `Files and Folders section`. You just have to check it and `Add Shortcut`.

    This is only active when a folder is currently selected in a Finder window that has focus.

    ### From the working directory of a Finder window - via keyboard Shortcut
    1. Run Automator, `File -> New` and choose **Quick Action**.
    2. Click `Library -> Utilities` and double click **Run AppleScript**.
    3. Workflow receives **Automatic (Nothing)** in **any application**.
    4. Paste the script from [Applescript](#applescript) section below.
    5. Save; if Automator tries to save to iCloud drive, better to save locally - save as **iTermOpenHereScript.workflow** to the Desktop and then move it to **~/Library/Services**.
    6. Add the keyboard shortcut under `System Preferences -> Keyboard -> Shortcuts -> Services` under the `General` section. Check **iTermOpenHereScrip** and Add Shortcut. Note that the first time you launch there may be a security popup saying iTermOpenHereScript wants access... Click OK to all.

    This is only active when a Finder window (or the Desktop itself) has focus.

    The Desktop having focus isn't really the intended use case, but for completeness, if it's the Desktop that has focus the working directory of its last focused still-open Finder window is used. If the current Desktop does not have any Finder windows, it's a bit indeterministic, but a working directory from a Finder window in other Space is used. If there are no Finder windows open in any other Spaces, it will default to the user's home directory.

    ### From the working directory of a Finder window - via Finder toolbar icon
    1. Run Automator, `File -> New` and choose **Application**.
    2. Click `Library -> Utilities` and double click **Run AppleScript**.
    3. Paste the script from [Applescript](#applescript) section below.
    4. Save; if Automator tries to save to iCloud drive, better to save locally - save as **iTermOpenHereScript.app** to the Desktop and then move it to **~/Library/Services**.
    5. Drag and drop iTermOpenHereScript.app onto the Finder toolbar while holding down the <kbd>option</kbd>+<kbd>command</kbd> keys to place a toolbar launch icon. Note that the first time you launch there may be a security popup saying iTermOpenHereScript wants access... Click OK to all.
    6. Right click on the spot on the toolbar and select **Icon Only**. To replace the generic Automator app icon with the iTerm2 icon, <kbd>command</kbd>+<kbd>i</kbd> on the original iTerm.app file, select the application icon in the top left corner of the window and <kbd>command</kbd>+<kbd>c</kbd>. Then do <kbd>command</kbd>+<kbd>i</kbd> to iTermOpenHereScript.app file, select the application icon in the top left corner of the window and <kbd>command</kbd>+<kbd>v</kbd>.
    7. To prevent two windows from opening when you click the toolbar launch icon when iTerm2 is not already running, set iTerm2's `Preferences -> General -> Startup` to **Only Restore Hotkey Window** for the Window restoration policy.

    ---
    ### Applescript
    ```
    on run {input, parameters}
    set frontApp to (path to frontmost application as Unicode text)
    if (frontApp does not contain "Finder.app") then
    -- Finder does not have focus
    return
    end if
    tell application "Finder"
    set listSize to count of (every window)
    if listSize is equal to 0 then
    -- the Finder desktop has focus and no windows anywhere else
    set dir_path to "~"
    else
    set dir_path to quoted form of (POSIX path of (folder of the front window as alias))
    end tell
    CD_to(dir_path)
    end run
    on CD_to(theDir)
    tell application "iTerm"
    activate
    set win to (create window with default profile)
    set sesh to (current session of win)
    tell sesh to write text "cd " & theDir & ";clear"
    end tell
    end CD_to
    ```
    4. If Automator tries to save to iCloud drive, better to save locally - save as **iTermOpenHereScript.app** to the Desktop and then move to **~/Library/Services**.
    5. Drag and drop iTermOpenHereScript.app onto the Finder toolbar while holding down the **\<option-command\>** keys to place a toolbar launch icon. Note that the first time you launch from the toolbar there may be a security popup saying iTermOpenHereScript.app wants access... Click OK to all.
    6. Right click on the spot on the toolbar and select **Icon Only**. To replace the generic Automator app icon with the iTerm2 icon, **\<command-i\>** on the original iTerm.app file, select the application icon in the top left corner of the window and **\<command-c\>**. Then do **\<command-i\>** to iTermOpenHereScript.app file, select the application icon in the top left corner of the window and **\<command-v\>**.
    7. To prevent two windows from opening when you click the toolbar launch icon when iTerm2 is not already running, set iTerm2's ```Preferences -> General -> Startup``` to **Only Restore Hotkey Window** for the Window restoration policy.
    To launch an iTerm2 window at a folder currently selected in finder
    --------------------------------------------------------------------------------
    Starting sometime with iTerm2 version 3.x, it puts **New iTerm2 Window Here** in ```System Preferences -> Keyboard -> Shortcuts -> Services``` under the ```Files and Folders section```. You just have to check it and assign a shortcut key sequence.
    Note that sometimes macOS doesn’t register the keyboard shortcut assignment immediately and may even require an OS restart to get it working. But also make sure the shortcut is not already assigned somewhere else.
    end if
    end tell
    CD_to(dir_path)
    end run
    on CD_to(theDir)
    tell application "iTerm"
    activate
    set term_window to (create window with default profile)
    set sesh to (current session of term_window)
    tell sesh to write text "cd " & theDir & ";clear"
    end tell
    end CD_to
    ```

    pdanford - Mar 2020. MIT License, etc.
  9. @pdanford pdanford revised this gist Mar 30, 2020. 1 changed file with 18 additions and 35 deletions.
    53 changes: 18 additions & 35 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,36 +1,14 @@
    Description
    -------------------------------------------------------
    Based on info from http://peterdowns.com/posts/open-iterm-finder-service.html but with modified behavior and fixed to work with iTerm2 version 3 or later. It will not work with older versions of iTerm. The modified behavior is to open a new terminal window for each invocation instead of reusing an already open window. Update - The original author released a build script for the newer iTerm2 versions at https://github.com/peterldowns/iterm2-finder-tools that keeps the original behavior of reusing an open iTerm2 window.
    To launch an iTerm2 window from macOS Finder via Finder toolbar icon
    ================================================================================
    (Based on info from Peter Downs' [gitub](https://github.com/peterldowns/iterm2-finder-tools) but with modified behavior to open a new terminal window for each invocation instead of reusing an already open window.)

    To open iTerm2 at selected folder with keyboard shortcut
    --------------------------------------------------------
    1. Run Automator, select a new Service
    2. Select Utilities -> Double click ‘Run AppleScript’
    3. Service receives selected 'folders' in 'finder.app'
    4. Paste script:
    ```
    on run {input, parameters}
    tell application "Finder" to set dir_path to quoted form of (POSIX path of (first item of (get selection as alias list) as alias))
    CD_to(dir_path)
    end run
    The following has been tested on iTerm2 version 3+ running on macOS Mojave+.

    on CD_to(theDir)
    tell application "iTerm"
    activate
    set win to (create window with default profile)
    set sesh to (current session of win)
    tell sesh to write text "cd " & theDir & ";clear"
    end tell
    end CD_to
    ```
    5. Save as 'Open iTerm at Folder'
    6. Open Keyboard in System Preferences. Under Shortcuts -> Services -> Files and Folders check 'Open iTerm at Folder' (with desired keyboard shortcut - e.g. control-option-command-T, making sure it's not already in use by another app). Note that sometimes macOS doesn’t register the keyboard shortcut and may require an OS restart to get it working.
    7. To prevent two windows from opening when you use the shortcut keys on a selected Finder folder when iTerm2 is not already running, set iTerm2 -> Preferences -> Startup to "Don't Open Any Windows"
    To open an iTerm2 window at the current Finder directory by clicking an icon that resides on Finder's toolbar
    --------------------------------------------------------------------------------

    To make an Automator App that can reside on the Finder toolbar to open an iTerm2 window at the current directory
    ----------------------------------------------------------------------------------------------------------------
    1. Run Automator, select new Application
    2. Select Utilities -> Double click ‘Run AppleScript’
    1. Run Automator, ```File -> New``` and choose **Application**.
    2. Click ```Lirary -> Utilities``` and double click **Run AppleScript**.
    3. Paste script:
    ```
    on run {input, parameters}
    @@ -49,9 +27,14 @@ To make an Automator App that can reside on the Finder toolbar to open an iTerm2
    end tell
    end CD_to
    ```
    4. Save as 'iTermOpenScript.app' somewhere out of the way
    5. Drag and drop the 'iTermOpenScript.app' onto the Finder toolbar while holding down the Option and Command keys to place the launch icon on Finder
    6. To prevent two windows from opening when you click the launch icon when iTerm2 is not already running, set iTerm2 -> Preferences -> Startup to "Don't Open Any Windows"
    7. If you want to replace the generic Automator icon, copy an image you want with \<Cmd\>\<C\>, then \<Cmd\>\<I\> on iTermOpenScript.app, select the application icon in the top left corner of the window and \<Cmd\>\<V\>.
    4. If Automator tries to save to iCloud drive, better to save locally - save as **iTermOpenHereScript.app** to the Desktop and then move to **~/Library/Services**.
    5. Drag and drop iTermOpenHereScript.app onto the Finder toolbar while holding down the **\<option-command\>** keys to place a toolbar launch icon. Note that the first time you launch from the toolbar there may be a security popup saying iTermOpenHereScript.app wants access... Click OK to all.
    6. Right click on the spot on the toolbar and select **Icon Only**. To replace the generic Automator app icon with the iTerm2 icon, **\<command-i\>** on the original iTerm.app file, select the application icon in the top left corner of the window and **\<command-c\>**. Then do **\<command-i\>** to iTermOpenHereScript.app file, select the application icon in the top left corner of the window and **\<command-v\>**.
    7. To prevent two windows from opening when you click the toolbar launch icon when iTerm2 is not already running, set iTerm2's ```Preferences -> General -> Startup``` to **Only Restore Hotkey Window** for the Window restoration policy.
    To launch an iTerm2 window at a folder currently selected in finder
    --------------------------------------------------------------------------------
    Starting sometime with iTerm2 version 3.x, it puts **New iTerm2 Window Here** in ```System Preferences -> Keyboard -> Shortcuts -> Services``` under the ```Files and Folders section```. You just have to check it and assign a shortcut key sequence.
    pdanford - Jan 2017. MIT License, etc.
    Note that sometimes macOS doesn’t register the keyboard shortcut assignment immediately and may even require an OS restart to get it working. But also make sure the shortcut is not already assigned somewhere else.
  10. @pdanford pdanford revised this gist Feb 5, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -52,6 +52,6 @@ To make an Automator App that can reside on the Finder toolbar to open an iTerm2
    4. Save as 'iTermOpenScript.app' somewhere out of the way
    5. Drag and drop the 'iTermOpenScript.app' onto the Finder toolbar while holding down the Option and Command keys to place the launch icon on Finder
    6. To prevent two windows from opening when you click the launch icon when iTerm2 is not already running, set iTerm2 -> Preferences -> Startup to "Don't Open Any Windows"
    7. If you want to replace the generic Automator icon, copy an image you want with <Cmd><C>, then <Cmd><I> on iTermOpenScript.app, select the application icon in the top left corner of the window and <Cmd><V>.
    7. If you want to replace the generic Automator icon, copy an image you want with \<Cmd\>\<C\>, then \<Cmd\>\<I\> on iTermOpenScript.app, select the application icon in the top left corner of the window and \<Cmd\>\<V\>.
    pdanford - Jan 2017. MIT License, etc.
  11. @pdanford pdanford revised this gist Feb 5, 2017. 1 changed file with 5 additions and 4 deletions.
    9 changes: 5 additions & 4 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ Based on info from http://peterdowns.com/posts/open-iterm-finder-service.html bu
    To open iTerm2 at selected folder with keyboard shortcut
    --------------------------------------------------------
    1. Run Automator, select a new Service
    2. Select Utilities -> Run AppleScript
    2. Select Utilities -> Double click ‘Run AppleScript
    3. Service receives selected 'folders' in 'finder.app'
    4. Paste script:
    ```
    @@ -24,13 +24,13 @@ To open iTerm2 at selected folder with keyboard shortcut
    end CD_to
    ```
    5. Save as 'Open iTerm at Folder'
    6. Open Keyboard in System Preferences. Under Shortcuts -> Services -> Files and Folders check 'Open iTerm at Folder' (with desired keyboard shortcut - e.g. control-option-command-T, making sure it's not already in use by another app)
    6. Open Keyboard in System Preferences. Under Shortcuts -> Services -> Files and Folders check 'Open iTerm at Folder' (with desired keyboard shortcut - e.g. control-option-command-T, making sure it's not already in use by another app). Note that sometimes macOS doesn’t register the keyboard shortcut and may require an OS restart to get it working.
    7. To prevent two windows from opening when you use the shortcut keys on a selected Finder folder when iTerm2 is not already running, set iTerm2 -> Preferences -> Startup to "Don't Open Any Windows"
    To make an Automator App that can reside on the Finder toolbar to open an iTerm2 window at the current directory
    ----------------------------------------------------------------------------------------------------------------
    1. Run Automator, select new Application
    2. Select Utilities -> Run AppleScript
    2. Select Utilities -> Double click ‘Run AppleScript
    3. Paste script:
    ```
    on run {input, parameters}
    @@ -52,5 +52,6 @@ To make an Automator App that can reside on the Finder toolbar to open an iTerm2
    4. Save as 'iTermOpenScript.app' somewhere out of the way
    5. Drag and drop the 'iTermOpenScript.app' onto the Finder toolbar while holding down the Option and Command keys to place the launch icon on Finder
    6. To prevent two windows from opening when you click the launch icon when iTerm2 is not already running, set iTerm2 -> Preferences -> Startup to "Don't Open Any Windows"
    7. If you want to replace the generic Automator icon, copy an image you want with <Cmd><C>, then <Cmd><I> on iTermOpenScript.app, select the application icon in the top left corner of the window and <Cmd><V>.
    pdanford - Jul 2016. MIT License, etc.
    pdanford - Jan 2017. MIT License, etc.
  12. @pdanford pdanford revised this gist Aug 16, 2016. 1 changed file with 9 additions and 7 deletions.
    16 changes: 9 additions & 7 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,9 @@
    Description
    -------------------------------------------------------
    Based on info from http://peterdowns.com/posts/open-iterm-finder-service.html but with modified behavior and fixed to work with iTerm2 Version 3 or later. It will not work with older versions of iTerm. The modified behavior is to open a new terminal window for each invocation instead of reusing an already open window.
    Based on info from http://peterdowns.com/posts/open-iterm-finder-service.html but with modified behavior and fixed to work with iTerm2 version 3 or later. It will not work with older versions of iTerm. The modified behavior is to open a new terminal window for each invocation instead of reusing an already open window. Update - The original author released a build script for the newer iTerm2 versions at https://github.com/peterldowns/iterm2-finder-tools that keeps the original behavior of reusing an open iTerm2 window.

    To open iTerm at selected folder with keyboard shortcut
    -------------------------------------------------------
    To open iTerm2 at selected folder with keyboard shortcut
    --------------------------------------------------------
    1. Run Automator, select a new Service
    2. Select Utilities -> Run AppleScript
    3. Service receives selected 'folders' in 'finder.app'
    @@ -24,10 +24,11 @@ To open iTerm at selected folder with keyboard shortcut
    end CD_to
    ```
    5. Save as 'Open iTerm at Folder'
    6. Open Keyboard in System Preferences. Under Shortcuts -> Services -> Files and Folders check 'Open iTerm at Folder' (with desired keyboard shortcut - e.g. control-option-command-T)
    6. Open Keyboard in System Preferences. Under Shortcuts -> Services -> Files and Folders check 'Open iTerm at Folder' (with desired keyboard shortcut - e.g. control-option-command-T, making sure it's not already in use by another app)
    7. To prevent two windows from opening when you use the shortcut keys on a selected Finder folder when iTerm2 is not already running, set iTerm2 -> Preferences -> Startup to "Don't Open Any Windows"
    To make an Automator App that can reside on the Finder toolbar to open an iTerm window at the current directory
    ---------------------------------------------------------------------------------------------------------------
    To make an Automator App that can reside on the Finder toolbar to open an iTerm2 window at the current directory
    ----------------------------------------------------------------------------------------------------------------
    1. Run Automator, select new Application
    2. Select Utilities -> Run AppleScript
    3. Paste script:
    @@ -49,6 +50,7 @@ To make an Automator App that can reside on the Finder toolbar to open an iTerm
    end CD_to
    ```
    4. Save as 'iTermOpenScript.app' somewhere out of the way
    5. Drag and drop the 'iTermOpenScript.app' onto the Finder toolbar while holding down the Option and Command keys
    5. Drag and drop the 'iTermOpenScript.app' onto the Finder toolbar while holding down the Option and Command keys to place the launch icon on Finder
    6. To prevent two windows from opening when you click the launch icon when iTerm2 is not already running, set iTerm2 -> Preferences -> Startup to "Don't Open Any Windows"
    pdanford - Jul 2016. MIT License, etc.
  13. @pdanford pdanford revised this gist Jul 16, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    Description
    -------------------------------------------------------
    Based on info from http://peterdowns.com/posts/open-iterm-finder-service.html but with modified behavior and fixed to work with iTerm2 Version 3+. It will not work with older versions of iTerm. The modified behavior is to open a new terminal window for each invocation instead of reusing an already open window.
    Based on info from http://peterdowns.com/posts/open-iterm-finder-service.html but with modified behavior and fixed to work with iTerm2 Version 3 or later. It will not work with older versions of iTerm. The modified behavior is to open a new terminal window for each invocation instead of reusing an already open window.

    To open iTerm at selected folder with keyboard shortcut
    -------------------------------------------------------
    @@ -51,4 +51,4 @@ To make an Automator App that can reside on the Finder toolbar to open an iTerm
    4. Save as 'iTermOpenScript.app' somewhere out of the way
    5. Drag and drop the 'iTermOpenScript.app' onto the Finder toolbar while holding down the Option and Command keys
    pdanford - Jul 2016
    pdanford - Jul 2016. MIT License, etc.
  14. @pdanford pdanford created this gist Jul 16, 2016.
    54 changes: 54 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,54 @@
    Description
    -------------------------------------------------------
    Based on info from http://peterdowns.com/posts/open-iterm-finder-service.html but with modified behavior and fixed to work with iTerm2 Version 3+. It will not work with older versions of iTerm. The modified behavior is to open a new terminal window for each invocation instead of reusing an already open window.

    To open iTerm at selected folder with keyboard shortcut
    -------------------------------------------------------
    1. Run Automator, select a new Service
    2. Select Utilities -> Run AppleScript
    3. Service receives selected 'folders' in 'finder.app'
    4. Paste script:
    ```
    on run {input, parameters}
    tell application "Finder" to set dir_path to quoted form of (POSIX path of (first item of (get selection as alias list) as alias))
    CD_to(dir_path)
    end run
    on CD_to(theDir)
    tell application "iTerm"
    activate
    set win to (create window with default profile)
    set sesh to (current session of win)
    tell sesh to write text "cd " & theDir & ";clear"
    end tell
    end CD_to
    ```
    5. Save as 'Open iTerm at Folder'
    6. Open Keyboard in System Preferences. Under Shortcuts -> Services -> Files and Folders check 'Open iTerm at Folder' (with desired keyboard shortcut - e.g. control-option-command-T)
    To make an Automator App that can reside on the Finder toolbar to open an iTerm window at the current directory
    ---------------------------------------------------------------------------------------------------------------
    1. Run Automator, select new Application
    2. Select Utilities -> Run AppleScript
    3. Paste script:
    ```
    on run {input, parameters}
    tell application "Finder"
    set dir_path to quoted form of (POSIX path of (folder of the front window as alias))
    end tell
    CD_to(dir_path)
    end run
    on CD_to(theDir)
    tell application "iTerm"
    activate
    set win to (create window with default profile)
    set sesh to (current session of win)
    tell sesh to write text "cd " & theDir & ";clear"
    end tell
    end CD_to
    ```
    4. Save as 'iTermOpenScript.app' somewhere out of the way
    5. Drag and drop the 'iTermOpenScript.app' onto the Finder toolbar while holding down the Option and Command keys
    pdanford - Jul 2016