Skip to content

Instantly share code, notes, and snippets.

Revisions

  1. @cowboy cowboy revised this gist Apr 14, 2011. 1 changed file with 20 additions and 14 deletions.
    34 changes: 20 additions & 14 deletions finder-open-iterm-here.scpt
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    (*
    * Finder Open iTerm Here - v1.0.1 - 4/7/2011
    * Finder Open iTerm Here - v1.0.2 - 4/14/2011
    * http://benalman.com/
    *
    * Copyright (c) 2011 "Cowboy" Ben Alman
    @@ -8,34 +8,40 @@
    *)

    tell application "Finder"
    if (count of (get selection as list)) is not 0 then
    set mypath to first item of (get selection as list) as alias
    set mySelected to get selection as list
    if (count of mySelected) is not 0 then
    set myItem to first item of mySelected
    if class of myItem is alias file then
    set myItem to original item of myItem
    end if
    if class of myItem is in {file, document file, internet location file} then
    set myItem to container of myItem
    end if
    else if the (count of window) is not 0 then
    set mypath to folder of the front window as string
    set myItem to folder of the front window
    else
    set mypath to path to desktop folder as string
    set myItem to path to desktop folder
    end if
    my open_iTerm(mypath)
    my open_iTerm(myItem)
    end tell

    on open these_items
    my open_iTerm((first item of these_items) as string)
    my open_iTerm(first item of these_items)
    end open

    on open_iTerm(mypath)
    set mypath to quoted form of POSIX path of mypath
    set mypath to quoted form of (do shell script "if [ -d " & mypath & " ]; then echo " & mypath & "; else echo $(dirname " & mypath & "); fi")
    on open_iTerm(myItem)
    set myPath to quoted form of POSIX path of (myItem as string)

    tell application "iTerm"
    activate
    if the (count of terminal) is 0 then
    set myterm to make new terminal
    set myTerm to make new terminal
    else
    set myterm to the current terminal
    set myTerm to the current terminal
    end if
    tell myterm
    tell myTerm
    launch session "Default Session"
    tell the last session to write text "cd " & mypath
    tell the last session to write text "cd " & myPath
    end tell
    end tell
    end open_iTerm
  2. @cowboy cowboy revised this gist Apr 7, 2011. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions finder-open-iterm-here.scpt
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    (*
    * Finder Open iTerm Here - v1.0 - 4/6/2011
    * Finder Open iTerm Here - v1.0.1 - 4/7/2011
    * http://benalman.com/
    *
    * Copyright (c) 2011 "Cowboy" Ben Alman
    @@ -24,7 +24,7 @@ end open

    on open_iTerm(mypath)
    set mypath to quoted form of POSIX path of mypath
    set mypath to do shell script "if [ -d " & mypath & " ]; then echo " & mypath & "; else echo $(dirname " & mypath & "); fi"
    set mypath to quoted form of (do shell script "if [ -d " & mypath & " ]; then echo " & mypath & "; else echo $(dirname " & mypath & "); fi")

    tell application "iTerm"
    activate
  3. @cowboy cowboy created this gist Apr 6, 2011.
    41 changes: 41 additions & 0 deletions finder-open-iterm-here.scpt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    (*
    * Finder Open iTerm Here - v1.0 - 4/6/2011
    * http://benalman.com/
    *
    * Copyright (c) 2011 "Cowboy" Ben Alman
    * Dual licensed under the MIT and GPL licenses.
    * http://benalman.com/about/license/
    *)

    tell application "Finder"
    if (count of (get selection as list)) is not 0 then
    set mypath to first item of (get selection as list) as alias
    else if the (count of window) is not 0 then
    set mypath to folder of the front window as string
    else
    set mypath to path to desktop folder as string
    end if
    my open_iTerm(mypath)
    end tell

    on open these_items
    my open_iTerm((first item of these_items) as string)
    end open

    on open_iTerm(mypath)
    set mypath to quoted form of POSIX path of mypath
    set mypath to do shell script "if [ -d " & mypath & " ]; then echo " & mypath & "; else echo $(dirname " & mypath & "); fi"

    tell application "iTerm"
    activate
    if the (count of terminal) is 0 then
    set myterm to make new terminal
    else
    set myterm to the current terminal
    end if
    tell myterm
    launch session "Default Session"
    tell the last session to write text "cd " & mypath
    end tell
    end tell
    end open_iTerm