我认为标题准确地说明了我想要做什么。我想要一个快捷方式,甚至是 Finder 中的一个按钮,它可以启动一个新的 iTerm 选项卡并将位置更改为我在 Finder 中打开的位置。某种程度上open .
是相反的。
答案1
有一个在这里打开终端您应该能够修改 AppleScript 来调用 iTerm。这MacOSXHints 帖子也应该有帮助。
(我没有使用 Mac,否则我会测试它。)
答案2
这个 applescript 对我有用:
-- script was opened by click in toolbar
on run
tell application "Finder"
try
set currFolder to (folder of the front window as string)
on error
set currFolder to (path to desktop folder as string)
end try
end tell
CD_to(currFolder, false)
end run
-- script run by draging file/folder to icon
on open (theList)
set newWindow to false
repeat with thePath in theList
set thePath to thePath as string
if not (thePath ends with ":") then
set x to the offset of ":" in (the reverse of every character of thePath) as string
set thePath to (characters 1 thru -(x) of thePath) as string
end if
CD_to(thePath, newWindow)
set newWindow to true -- create window for any other files/folders
end repeat
return
end open
-- cd to the desired directory in iterm
on CD_to(theDir, newWindow)
set theDir to quoted form of POSIX path of theDir as string
tell application "iTerm"
activate
delay 1
-- talk to the first terminal
try
set myterm to the first terminal
on error
set myterm to (make new terminal)
end try
tell myterm
try
-- launch a default shell in a new tab in the same terminal
launch session "Default Session"
on error
display dialog "There was an error creating a new tab in iTerm." buttons {"OK"}
end try
tell the last session
try
-- cd to the finder window
write text "cd " & theDir
on error
display dialog "There was an error cding to the finder window." buttons {"OK"}
end try
end tell
end tell
end tell
end CD_to
答案3
使用此页面上的其他答案,我创建了一个可以拖入查找器任务栏的应用程序。
你可以在这里下载:https://github.com/rc1/iTermTo
答案4
我猜是因为 iTerm 的内部结构发生了变化,但是没有一个解决方案对我有用。以下代码起了作用:
tell application "Finder"
set cur_dir to POSIX path of ((the target of the front Finder window) as string)
end tell
tell application "iTerm"
tell (create window with default profile)
write current session text "cd " & quoted form of cur_dir
end tell
end tell
或者使用 Automator 作为查找服务:
on run {input, parameters}
tell application "Finder"
set cur_dir to POSIX path of (input as string)
end tell
tell application "iTerm"
tell (create window with default profile)
write current session text "cd " & quoted form of cur_dir
end tell
end tell
end run