使用中のコンピュータにインストールされているアラートサウンド(警告音)の名称を取得して、音を同時に鳴らすAppleScriptです。
NSArrayに入れたオブジェクトに対して一括でメッセージを送るという処理の実験でもあります。
AppleScript名:ASOCでSystemのアラートサウンド名称を取得して同時に鳴らす v2.2a(Array内のオブジェクトに一括指令) |
— Created 2015-11-06 by Takaaki Naganoya — Modified 2015-11-07 by Shane Stanley–Recovery the compatibility for OS X 10.10.x — Modified 2015-11-07 by Takaaki Naganoya–NSArrayからvalueForKeyで加工しつつ一気にArrayで値を返す内容を検証 — Modified 2015-11-07 by Shane Stanley–Cooler processing — 2015 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "AppKit" set nList to getSystemAlertSoundNames() of me –> {"Basso", "Blow", "Bottle", "Frog", "Funk", "Glass", "Hero", "Morse", "Ping", "Pop", "Purr", "Sosumi", "Submarine", "Tink"} set aArray to current application’s NSMutableArray’s new() repeat with i in nList (aArray’s addObject:(current application’s NSSound’s soundNamed:i)) end repeat aArray’s makeObjectsPerformSelector:"play" withObject:0 –同時に鳴らす –Get System Alert FileName List on getSystemAlertSoundNames() set aExt to "aiff" — no dot set aFol to "/System/Library/Sounds" set fList to getFileNameListFromPOSIXpath(aFol, aExt) of me return fList end getSystemAlertSoundNames –Get File Name List from POSIX path and file Extensions on getFileNameListFromPOSIXpath(aFol, aExt) set aFM to current application’s NSFileManager’s defaultManager() set aURL to current application’s |NSURL|’s fileURLWithPath:aFol set urlArray to aFM’s contentsOfDirectoryAtURL:aURL includingPropertiesForKeys:{} options:(current application’s NSDirectoryEnumerationSkipsHiddenFiles) |error|:(missing value) set thePred to current application’s NSPredicate’s predicateWithFormat:"pathExtension == [c]%@" argumentArray:{aExt} set anArray to urlArray’s filteredArrayUsingPredicate:thePred set bArray to (anArray’s valueForKeyPath:"lastPathComponent.stringByDeletingPathExtension") –Cool !! return bArray as list end getFileNameListFromPOSIXpath |
More from my site
(Visited 24 times, 1 visits today)