-
Notifications
You must be signed in to change notification settings - Fork 1
/
OpenTerminalHere3.applescript
48 lines (45 loc) · 1.37 KB
/
OpenTerminalHere3.applescript
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
on open dropedItems
repeat with anItem in dropedItems
set aDirectory to get POSIX path of anItem
if not isDirectory(anItem) then -- anItemがディレクトリでない時それを含むディレクトリを指定する
tell application "Finder"
set aParentFolder to (container of anItem) as alias
set aDirectory to get POSIX path of aParentFolder
end tell
end if
openDirectoryOnTerminal(aDirectory)
end repeat
end open
on run
tell application "Finder"
try
tell Finder window 1
set aTarget to target
set aFolder to aTarget as alias
end tell
on error number errorNumber
display alert "対象となるFinderウィンドウが見つからないので、デスクトップをTerminalのカレントディレクトリとします。"
set aFolder to (path to desktop folder)
end try
end tell
set aDirectory to get POSIX path of aFolder
openDirectoryOnTerminal(aDirectory)
end run
on isDirectory(anItem)
set isFolder to (folder of (info for anItem))
set isPackageFolder to (package folder of (info for anItem))
if isFolder and not isPackageFolder then return true
return false
end isDirectory
on openDirectoryOnTerminal(aDirectory)
tell application "Terminal"
do script with command "cd "" & aDirectory & ""; clear; pwd"
activate me
tell application "System Events"
set aProcess to get process "Terminal"
end tell
tell aProcess
set frontmost to true
end tell
end tell
end openDirectoryOnTerminal