/
action.rb
executable file
·64 lines (57 loc) · 1.66 KB
/
action.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Dropzone Action Info
# Name: Open iTerm at Path
# Description: iTerm v2.9+ required. This action uses the new Applescript used in iTerm 2.9. Drop a file or folder on this action to open a new Terminal window at the files path. You can also drop a textual path. Slightly modified version of the original action for Terminal by Dennis Kuypers.
# Handles: Files, Text
# Creator: Sam Turner
# URL: http://www.digi.ltd.uk
# Events: Clicked, Dragged
# SkipConfig: No
# RunsSandboxed: No
# Version: 1.1
# MinDropzoneVersion: 3.0
def dragged
dir = false
case ENV['dragged_type']
when 'files'
# If it's a directory then cd to that directory, otherwise we will cd to the directory the file is in
if File.directory?($items[0])
dir = $items[0]
else
dir = File.dirname($items[0])
end
when 'text'
# Verify that this is a directory path
dir = $items[0] if File.directory?($items[0])
end
puts dir
# Launch iTerm in desired directory
if dir
puts `osascript -so <<END
tell application "iTerm"
activate
delay 0.2
set newWindow to (create window with default profile)
delay 0.2
tell current window
tell current session
write text "cd '#{dir}'"
end tell
end tell
end tell
END`
else
# Could not figure out what the user wants. Dump to console and notify user.
puts "Could not figure out what to do with data: #{$items.inspect}"
$dz.fail("Not a file or directory path")
end
$dz.url(false)
end
def clicked
puts `osascript -so <<END
tell application "iTerm"
delay 0.2
set newWindow to (create window with default profile )
end tell
END`
$dz.url(false)
end