AppleScript名:listの項目をフィルタリング(項目文字長) |
— Created 2014-11-21 by Takaaki Naganoya — 2014 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set aList to {"piyomaru", "Piyomaru Software", "Naganoya", "Takaaki", "MacBook Pro Retina mid 2012"} set bList to filterListUsingPredicate(aList, "length > 8") –文字列長が8文字より長い項目を返す –> {"MacBook Pro Retina mid 2012", "Piyomaru Software"} set cList to filterListUsingPredicate(aList, "SELF MATCHES ’.*e$’") –正規表現で末尾が"e" –> {"Piyomaru Software"} set dList to filterListUsingPredicate(aList, "SELF LIKE ’piyo*’") –> {"piyomaru"} set eList to filterListUsingPredicate(aList, "SELF LIKE[c] ’piyo*’") –> {"piyomaru", "Piyomaru Software"} set fList to filterListUsingPredicate(aList, "SELF CONTAINS[c] ’Piyo’") –> {"piyomaru", "Piyomaru Software"} on filterListUsingPredicate(aList as list, aPredicateStr as string) –ListからNSArrayへの型変換 set setKey to current application’s NSMutableSet’s setWithArray:aList –抽出 set aPredicate to current application’s NSPredicate’s predicateWithFormat:aPredicateStr set aRes to (setKey’s filteredSetUsingPredicate:aPredicate) set bRes to aRes’s allObjects() –NSArrayからListに型変換して返す set cRes to bRes as {list, list of string or string} return cRes end filterListUsingPredicate |
More from my site
(Visited 25 times, 1 visits today)