2006-04-25

실습 - 데스크탑 파일 정리

애플포럼에서 바탕화면 정리용 스크립트, Tidy-It라는 글을 읽고서, 비슷한 것을 만들어보고 싶어졌습니다. 따라서 만든 것이기 때문에 독창성을 주장할 여지는 없어보입니다. 이번 실습 역시 이런 것이 이런 식으로 가능하다는 것을 보이는 데에 의의가 있습니다.
각각의 확장자들의 목록을 먼저 만듭니다. 변수에 대해서 설명할 때 나왔지만, property로 선언한 변수는 스크립트 전체에서 어디에서 불러낼 수 있는, 가장 범위가 넓은 전역 변수입니다. Finder의 애플스크립트에 대해서는 아직 강좌를 구성하지 못했는데 자꾸 나오고 있습니다만, 이해하는 데에 큰 어려움은 없을 것 같습니다.
on open으로 시작하는 스크립트를 응용프로그램으로 저장하면 drag & drop으로 실행되는 droplet이 됩니다. 개별 파일들의 저장 경로를 확인해서 없으면 해당 폴더를 만듭니다. 경로는 취향대로 바꿀 수 있습니다.
property imageExtensions : {"jpg", "jpeg", "gif", "png", "tiff", "bmp", "pic", "pict"}
property multimediaExtensions : {"mp3", "m4a", "aac", "mov", "avi", "mpg", "mpeg"}
property documentExtensions : {"txt", "doc", "pdf"}
property compressExtensions : {"zip", "sit", "sitx", "rar", "tar", "gz"}
-- 필요한 확장자를 추가할 수 있습니다.

property myPath : alias (((path to desktop folder) as string) & "iPotato:")
property imagePath : (myPath as string) & "image:" as alias
property multimediaPath : (myPath as string) & "multimedia:" as alias
property documentPath : (myPath as string) & "document:" as alias
property compressPath : (myPath as string) & "compress:" as alias
-- 저장 경로는 임의대로 바꿀 수 있습니다.

on open theseFiles
-- droplet으로 만들기 위해 on open으로 시작했습니다.
try
tell application "Finder"
if myPath exists then
if imagePath exists then
else
make new folder at myPath with properties {name:"image"}
end if

if multimediaPath exists then
else
make new folder at myPath with properties {name:"multimedia"}
end if

if documentPath exists then
else
make new folder at myPath with properties {name:"document"}
end if

if compressPath exists then
else
make new folder at myPath with properties {name:"compress"}
end if
else
make new folder with properties {name:"iPotato", path:path to desktop folder}
end if

repeat with thisFile in theseFiles
set thisExtension to name extension of (info for thisFile)
-- 확장자만 가져옵니다.

-- 각각의 리스트에 일치하는 확장자가 있는지 검사한 후, 있다면 지정된 폴더로 옮깁니다.
if thisExtension is in the imageExtensions then
move thisFile to imagePath
else if thisExtension is in the multimediaExtensions then
move thisFile to multimediaPath
else if thisExtension is in the documentExtensions then
move thisFile to documentPath
else if thisExtension is in the compressExtensions then
move thisFile to compressPath
end if
end repeat
end tell
on error errMsg
display dialog errMsg
end try
end open

0 Comments:

댓글 쓰기

<< Home