601d54ba0e81110a289d168ea718a92a4bc9b0ab
compute/osx-open-iterm-here.md
| ... | ... | @@ -4,11 +4,15 @@ Modified from [Deep-blue](https://hohonuuli.blogspot.com/2016/02/iterm2-version- |
| 4 | 4 | Open ScriptEditor from Launchpad and paste this in: |
| 5 | 5 | ``` |
| 6 | 6 | (* |
| 7 | - Open Terminal Here |
|
| 8 | - Written by Brian Schlining originally |
|
| 7 | + Open Terminal Here |
|
| 8 | + |
|
| 9 | + A toolbar script for Mac OS X 10.3/10.4 |
|
| 10 | + |
|
| 11 | + Written by Brian Schlining |
|
| 12 | + |
|
| 13 | + Modified by David Stark |
|
| 9 | 14 | *) |
| 10 | 15 | |
| 11 | - |
|
| 12 | 16 | property debug : false |
| 13 | 17 | |
| 14 | 18 | -- when the toolbar script icon is clicked |
| ... | ... | @@ -20,9 +24,7 @@ on run |
| 20 | 24 | on error |
| 21 | 25 | set this_folder to startup disk |
| 22 | 26 | end try |
| 23 | - |
|
| 24 | 27 | my process_item(this_folder) |
| 25 | - |
|
| 26 | 28 | end tell |
| 27 | 29 | end run |
| 28 | 30 | |
| ... | ... | @@ -37,26 +39,27 @@ end open |
| 37 | 39 | |
| 38 | 40 | -- this subroutine processes does the actual work |
| 39 | 41 | -- this version can handle this weirdo case: a folder named "te'st"ö te%s`t" |
| 42 | + |
|
| 40 | 43 | on process_item(this_item) |
| 41 | - |
|
| 42 | 44 | set thePath to quoted form of POSIX path of this_item |
| 43 | 45 | set theCmd to "cd " & thePath & ";clear;" |
| 44 | - |
|
| 45 | - tell application "iTerm" |
|
| 46 | - activate |
|
| 47 | - -- just open a terminal and cd to thePath |
|
| 48 | - --set newWindow to (create window with default profile) |
|
| 49 | - |
|
| 50 | - set aWindow to current window |
|
| 51 | - |
|
| 52 | - set aWindow to (create window with default profile) |
|
| 53 | - |
|
| 54 | - tell current session of aWindow |
|
| 55 | - write text "cd " & thePath & ";clear;" |
|
| 46 | + if application "iTerm" is running then |
|
| 47 | + tell application "iTerm" |
|
| 48 | + activate |
|
| 49 | + set aWindow to (create window with default profile) |
|
| 50 | + tell current session of aWindow |
|
| 51 | + write text "cd " & thePath & ";clear;" |
|
| 52 | + end tell |
|
| 56 | 53 | end tell |
| 57 | - |
|
| 58 | - end tell |
|
| 59 | - |
|
| 54 | + else |
|
| 55 | + tell application "iTerm" |
|
| 56 | + activate |
|
| 57 | + set aWindow to current window |
|
| 58 | + tell current session of aWindow |
|
| 59 | + write text "cd " & thePath & ";clear;" |
|
| 60 | + end tell |
|
| 61 | + end tell |
|
| 62 | + end if |
|
| 60 | 63 | end process_item |
| 61 | 64 | ``` |
| 62 | 65 |