Mac OS에는 예전부터 애플스크립트라는 게 있었습니다. 이름에서 알 수 있듯이 애플 Mac OS에서 쓸 수 있는 간단한 스크립트 언어입니다.

옛날 도스의 배치 파일, 윈도우즈의 VBA나 VBScript, 유닉스의 셸 스크립트 등하고 비슷하다고 보면 되는데, 제가 지금까지 경험해 본 언어가 그리 많진 않지만, 그래도 그 중에서 가장 자연 언어에 가까운 언어인 것 같습니다. 물론 우리말이 아니라 영어에 가까운 게 탈이긴 하지만요...

예를 들어 Mail이라는 애플리케이션에서 현재 선택된 항목(들)을 my_selection이라는 변수에 저장하고 싶다면 다음과 같은 식으로 하면 됩니다.

tell application "Mail"
set my_selection to the selection
end tell

여기에서 the 같은 관사는 넣어도 되고 안 넣어도 됩니다. 그냥 영어 문장 같은 느낌이 많이 들죠.

애플스크립트를 써먹어야 되겠다는 생각이 든 건 이메일 때문이었는데, 제가 지금 머물고 있는 곳이 네트워크 설정이 좀 빡세서, pop3로 이메일 긁어오는 것도 그냥은 안 되고 pop3 전용 프록시를 써야 합니다. 숙소에 있을 때는 그냥 보통 하듯이 해야 하니깐 결국 왔다 갔다 할 때마다 설정을 바꿔줘야 하는 거죠. 그냥 pop3를 프록시만 거는 게 아니고, 받는 메일 서버를 ****로 설정을 하고, 사용자 아이디를 아이디@원래서버명 이런 식으로 설정을 해야 합니다. pop3로 긁어오는 메일 서버가 하나만 있으면 그냥 편하게 할 텐데, 한 네 개 정도를 매일 아침에 출근해서 한 번, 저녁에 집에 가서 한 번씩 설정을 바꿔야 하니 시간이야 한 2-3분이면 된다고 쳐도 여간 귀찮은 게 아닙니다.

프로그래머의 가장 큰 미덕이라고 하는 귀차니즘(?) 때문에, 간단하게 마우스 클릭만 하면, 또는 명령어 하나만 치면 설정을 바꿀 수 있도록 하고 싶었는데, Mail 애플리케이션(윈도우의 아웃룩 익스프레스 비슷하다고 보면 됩니다.)에서 팝 서버 설정 내역을 어디에 어떤 식으로 저장하는지 잘 모르겠더군요... 그래서 셸 스크립트는 패스... 결국 인터넷을 마구마구 뒤져서 애플스크립트를 공부해서 간단한 스크립트를 만들었습니다. 언어 자체가 워낙 자연어에 가깝고, dictionary라는, 특정 애플리케이션별 API 비스무레한 거에 대한 설명이 꽤 잘 돼 있어서 그리 어렵지 않게 만들 수 있었습니다.


스크립트 메뉴에서 원하는 스크립트를 실행시키면 이 그림처럼 창이 뜹니다. 위치를 더블클릭하기만 하면 알아서 설정을 바꿔줍니다.


tell application "Mail"
set the list_of_accounts to every pop account
set the locations_list to {"거기", "Outside 거기"}
copy (choose from list locations_list with prompt "Choose the current location.") to dialog1
if dialog1 is not false then
set current_location to item 1 of dialog1
if current_location is "거기" then
repeat with i from 1 to number of items in list_of_accounts
set this_account to item i of list_of_accounts
if (the name of this_account is not "거기" and the server name of this_account is not "팝3프록시주소") then
set current_server_name to the server name of this_account
set the server name of this_account to "팝3프록시주소"
set the user name of this_account to user name of this_account & "@" & current_server_name
set the smtp server of this_account to smtp server "거기보내는메일서버주소"
end if
end repeat
set the include when getting new mail of account "거기메일서버" to true
set the include when getting new mail of account "Teramail" to false
else if the current_location is "Outside 거기" then
repeat with i from 1 to number of items in list_of_accounts
set this_account to item i of list_of_accounts
if (the name of this_account is not "거기" and the server name of this_account is "팝3프록시주소") then
set current_user_name to the user name of this_account
set AppleScript's text item delimiters to the "@"
set the item_list to every text item of the current_user_name
set AppleScript's text item delimiters to ""
set the user name of this_account to the item 1 of item_list as string
set the server name of this_account to the item 2 of item_list as string
set the smtp server of this_account to smtp server "밖에서쓰는보내는메일서버주소"
end if
end repeat
set the include when getting new mail of account "거기" to false
set the include when getting new mail of account "Teramail" to true
end if
end if
end tell


아마 대강 보시면 무슨 뜻인지 감이 올 겁니다... :)

제가 앞으로 여기서 지낼 날이 대강 150일 정도 남아 있는데, 그러면 하루에 두 번씩 2분씩 설정을 바꾸는 데 시간을 투자한다고 하면 대강 600분을 설정 바꾸는 데 쓰게 될 겁니다. 대강 10시간 정도 되는군요... 다행히 저 스크립트 완성하는 데까지 애플스크립트에 대해 알아보고 하는 데 걸린 시간이 10시간은 걸리지 않지만, 그래도 손익분기점 가까스로 넘겼습니다...
어쨌든 시간도 시간이지만 메일 설정 한 번 바꿀 때마다 마우스를 대략 20번 쯤 클릭해야 하고 키를 100번 정도 눌러야 하는 걸 감안하면 그 귀찮은 작업을 이제 안 해도 된다는 게 정말 좋습니다.

저것 말고도 다른 프로그램에서 여러 폰트들을 선택한 다음 객체들의 폰트를 일괄적으로 특정 폰트로 바꿔주는 스크립트도 짰으니, 그리 손해 본 장사는 아닌 듯 합니다...

+ Recent posts