예전(작년 말?)에 만든건데 깃허브에서 본 걸 내 입맛대로 커스터마이징 했고, 현재 디렉토리 열기는 직접 만들었다.

(참고로 원본 소스는 iTerm이 아닌 기본 터미널을 사용함)


버전 상의 이유로 제대로 동작하는 코드가 넷상에는 흔치 않은데


혼자만 가지고 있는 것 보다 다른 사람이랑 공유하는 것이 여러모로 좋겠다 싶어서 공유를 하기로 했다.




만들게 된 계기는 친구가 오토메이터로 특정 단어 수를 찾는 스크립트를 만들었는데


어떻게 만들었는지 알아보다가 오토메이터를 사용해서 만드는게 그리 어렵지않아서


내가 진짜 필요하다고 생각하는 기능을 문법 찾아보면서 직접 만들게 되었다.

(애플스크립트 문법인데 이젠 기억이 안난다..)



윈도우의 '현재 위치에서 터미널 열기' 와 같은 기능이라고 보면 된다. 



터미널을 애용 & 활용하는 사람들에겐  상당히 도움이 많이되는 스크립트임에 분명하고


최신 맥 OS에서 지금도 잘 활용하고 있으니 코드 상의 문제는 없을 것이다.



우선 처음 오토메이터를 생성 작업은 다음과 같다.



1. '서비스' 선택



2. AppleScript 실행을 더블클릭하면 창이 생성된다.





- iTerm2로 파일 열기


: 자주 사용하는 기능 중 하나다.


오토메이터 생성 시 다음과 같은 형식을 가진다.




-- Adapted from these sources:


-- http://peterdowns.com/posts/open-iterm-finder-service.html


-- https://gist.github.com/cowboy/905546


-- 


-- Modified to work with files as well, cd-ing to their container folder

property debug : false



on run {input, parameters}


tell application "Finder"


set my_file to first item of input


set is_folder to (do shell script "file -b " & quoted form of (POSIX path of my_file))


if is_folder ends with "directory" then


set dir_path to quoted form of (POSIX path of my_file)


else


set dir_path to quoted form of (POSIX path of (container of my_file as string))


end if


end tell


CD_to(dir_path)


end run




on CD_to(theDir)


tell application "iTerm"


activate


set go_dir to "cd " & theDir & "; clear; ll"


try


set newWindow to last window


on error


set newWindow to (create window with default profile)


end try


tell newWindow


tell current session of (create tab with default profile)


write text go_dir


end tell


end tell


end tell


end CD_to



- iTerm2로 현재 위치 열기


: 위의 기능이 막강해서 잘 사용하지는 않지만 가끔 쓴다. 가장 앞에 있는 창의 디렉토리 위치를 터미널로 연다.


오토메이터 생성 시 다음과 같은 형식을 가진다.




on run {input, parameters}

tell application "Finder"

try

set now_win to last window

set dir_path to (POSIX path of (target of now_win as alias))

on error

set dir_path to (POSIX path of (path to desktop folder as string))

end try

end tell

CD_to(dir_path)

end run


on CD_to(theDir)

tell application "iTerm"

activate

set go_dir to "cd \"" & theDir & "\"; clear; l"

try

set newWindow to last window

on error

set newWindow to (create window with default profile)

end try

tell newWindow

tell current session of (create tab with default profile)

write text go_dir

end tell

end tell

end tell

end CD_to



문법은 그리 어렵지 않으니 한번쯤 공부하는것도 나쁘진 않을 듯 하다.



등록 방법은 우선 만든 스크립트를


/Users/사용자이름/Library/Services


에 저장하고 설정-키보드-단축키 탭 - 서비스에서 단축키를 지정하면 끝.


참고로 스크립트의 이름을 단순하게 짓지말고 필자와 비슷한 식으로 저장을 해야 충돌이 안난다.

(만약 서비스 항목에 뜨지않는다면 재부팅을 해볼 것. 필자도 이 부분에서 꽤나 고생했다.)





완료 후 지정한 단축키를 눌러서 실행하면 된다.



정상적으로 완료시 위와 같이 서비스 항목에서 등록되므로 확인.


삭제는 /Users/사용자이름/Library/Services 에서 제거하고 재부팅 후 키보드-단축키 탭-서비스 다시 확인해보세용