compute/osx-open-iterm-here.md
... ...
@@ -0,0 +1,65 @@
1
+# Open iTerm at a finder window's path
2
+Modified from [Deep-blue](https://hohonuuli.blogspot.com/2016/02/iterm2-version-3-open-iterm-here-script.html)'s version. I don't use tabs in shells, so this version always opens a new iTerm window.
3
+
4
+Open ScriptEditor from Launchpad and paste this in:
5
+```
6
+(*
7
+ Open Terminal Here
8
+ Written by Brian Schlining originally
9
+ *)
10
+
11
+
12
+property debug : false
13
+
14
+-- when the toolbar script icon is clicked
15
+--
16
+on run
17
+ tell application "Finder"
18
+ try
19
+ set this_folder to (the target of the front window) as alias
20
+ on error
21
+ set this_folder to startup disk
22
+ end try
23
+
24
+ my process_item(this_folder)
25
+
26
+ end tell
27
+end run
28
+
29
+-- This handler processes folders dropped onto the toolbar script icon
30
+--
31
+on open these_items
32
+ repeat with i from 1 to the count of these_items
33
+ set this_item to item i of these_items
34
+ my process_item(this_item)
35
+ end repeat
36
+end open
37
+
38
+-- this subroutine processes does the actual work
39
+-- this version can handle this weirdo case: a folder named "te'st"ö te%s`t"
40
+on process_item(this_item)
41
+
42
+ set thePath to quoted form of POSIX path of this_item
43
+ 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;"
56
+ end tell
57
+
58
+ end tell
59
+
60
+end process_item
61
+```
62
+
63
+Export it as an Application, then drag the application icon up to the Finder toolbar while holding down `option` ans `command'.
64
+
65
+Then you can click the icon in the Finder toolbar and iTerm will open at that folder.