Sunday, March 21, 2010

AppleScript에서 Search and Replace 하기

AppleScript에는 regular expression이 없지만, 다음과 같이 search and replace 할수 있다.
display dialog ( my searchAndReplace("my mommy", "my", "your") )

on searchAndReplace( txt, srch, rpl )
set oldtid to AppleScript's text item delimiters
set AppleScript's text item delimiters to {srch}
set temp to every text item of txt
set AppleScript's text item delimiters to {rpl}
set temp to (temp as string)
set AppleScript's text item delimiters to oldtid
return temp
end searchAndReplace

레퍼런스 :
Read and write text files with AppleScript

No comments:

Post a Comment