| AppleScript名:QuickTime Player X経由でムービー情報を取得 |
–QuickTime Player Xでムービーの情報を取得 tell application id "com.apple.QuickTimePlayerX" tell document 1 properties –> {size:59828718, volume:1.0, modified:false, current audio compression:missing value, name:"戦場の絆 17_07_31 17_09 リボー・コロニー(R) 4VS4 Aクラス.mp4", current microphone:missing value, output muted:false, duration:305.203077777778, current movie compression:missing value, current screen compression:missing value, data rate:196029, current camera:missing value, preview resolution:false, playing:true, class:document, file:file "Cherry:Users:me:Movies:戦場の絆 17_07_31 17_09 リボー・コロニー(R) 4VS4 Aクラス.mp4", natural dimensions:{1280, 720}, looping:false, time:1.6761711, rate:1.0} end tell end tell |
QuickTime Player Xで録音を開始する
| AppleScript名:QuickTime Player Xで録音を開始する |
| tell application id "com.apple.QuickTimePlayerX" set recSound to (new audio recording) tell recSound start end tell end tell |
QuickTimeムービーの縦横ドット数を取得する
| AppleScript名:QuickTimeムービーの縦横ドット数を取得する |
| tell application "QuickTime Player" tell document 1 set {aWidth, aHeight} to natural dimensions end tell end tell –>{640, 480} |
QT Playerでムービー再生位置を先頭に(巻き戻し)
| AppleScript名:QT Playerでムービー再生位置を先頭に(巻き戻し) |
| tell application "QuickTime Player" tell document 1 set current time to 0 end tell end tell |
オープン中のムービーのファイルにラベルを付ける
| AppleScript名:オープン中のムービーのファイルにラベルを付ける |
| — Created 2017-10-26 by Takaaki Naganoya — 2017 Piyomaru Software –http://piyocast.com/as/archives/4925 tell application "QuickTime Player" set aDocList to every document end tell repeat with i in aDocList tell application "QuickTime Player" tell i set aProp to properties set aFile to (file of aProp) as alias end tell end tell tell application "Finder" set label index of aFile to 5 end tell end repeat |
ムービー再生速度を変更する
| AppleScript名:ムービー再生速度を変更する |
| tell application "QuickTime Player" tell document 1 set rate to 2.0 end tell end tell |
QuickTime Playerの最前面のムービーの現在表示中のコマをデスクトップにJPEG画像で保存
| AppleScript名:QuickTIme Playerの最前面のムービーの現在表示中のコマをデスクトップにJPEG画像で保存 |
| — Created 2018-01-20 by Takaaki Naganoya — 2018 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "AppKit" –http://piyocast.com/as/archives/5123 property NSUUID : a reference to current application’s NSUUID property NSString : a reference to current application’s NSString property NSImage : a reference to current application’s NSImage property NSPasteboard : a reference to current application’s NSPasteboard property NSJPEGFileType : a reference to current application’s NSJPEGFileType property NSBitmapImageRep : a reference to current application’s NSBitmapImageRep set the clipboard to "" –Clear Clipboard (=Pasteboard) tell application "QuickTime Player" –No Document check if (count every document) < 1 then display dialog "No Document…" with icon 2 buttons {"OK"} default button 1 return end if –Audio Movie check if natural dimensions of front document = {0, 0} then display dialog "This is an audio file" with icon 2 buttons {"OK"} default button 1 return end if end tell repeat 100 times activate application "QuickTime Player" tell application "System Events" tell process "QuickTime Player" click menu item 5 of menu 1 of menu bar item 4 of menu bar 1 –Edit > Copy end tell end tell delay 0.1 set aRes to dataIsInClipboard for JPEG picture if aRes = true then exit repeat end repeat if aRes = false then return –クリップボードの内容をNSImageに set aNSIMage to my getClipboardASImage() –保存先とファイル名を求める set targFol to POSIX path of (path to desktop) set aUUID to NSUUID’s UUID()’s UUIDString() as text set outPath to targFol & aUUID & ".jpg" set aRes to saveNSImageAtPathAsJPG(aNSIMage, outPath, 1.0) of me — クリップボードの内容をNSImageとして取り出して返す on getClipboardASImage() set theNSPasteboard to NSPasteboard’s generalPasteboard() set imageArray to theNSPasteboard’s readObjectsForClasses:({NSImage}) options:(missing value) set targImage to imageArray’s objectAtIndex:0 return targImage end getClipboardASImage –NSImageを指定パスにJPEG形式で保存、qulityNumは0.0〜1.0。1.0は無圧縮 on saveNSImageAtPathAsJPG(anImage, outPath, qulityNum as real) set imageRep to anImage’s TIFFRepresentation() set aRawimg to NSBitmapImageRep’s imageRepWithData:imageRep set pathString to NSString’s stringWithString:outPath set newPath to pathString’s stringByExpandingTildeInPath() set myNewImageData to (aRawimg’s representationUsingType:(NSJPEGFileType) |properties|:{NSImageCompressionFactor:qulityNum}) return (myNewImageData’s writeToFile:newPath atomically:true) as boolean end saveNSImageAtPathAsJPG –http://ashplanning.blogspot.jp/2006/12/blog-post.html on dataIsInClipboard for dataType return (clipboard info for dataType) is not {} end dataIsInClipboard |
Numbersでセルのカラム幅を自動調整 v2
| AppleScript名:Numbersでセルのカラム幅を自動調整 v2 |
| — Created 2018-1-11 by Takaaki Naganoya — 2018 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" –http://piyocast.com/as/archives/5116 tell application "Numbers" tell front document tell sheet 1 set tCount to count every table if tCount = 0 then return tell table 1 set tableWidth to width set cCount to count every column set cWidth to width of every column set aWidth to width –table width set aveWidth to (aWidth – (first item of cWidth)) / (cCount – 1) tell columns 2 thru cCount set width to aveWidth end tell set wList to width of every column end tell if tCount = 1 then return set origCols to count every column of table 1 repeat with i from 2 to tCount if origCols is not equal to (count every column of table i) then display notification "Numbers: Column number is different in Table #" & (i as string) return end if end repeat repeat with i from 2 to tCount tell table i set width to tableWidth end tell set aCount to 1 tell table i repeat with ii from 1 to cCount tell column ii set width to (contents of item ii of wList) end tell end repeat end tell end repeat end tell end tell end tell |
Numbers書類からPDF書き出し v2
| AppleScript名:Numbers書類からPDF書き出し v2 |
| — Created 2017-03-28 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set tmpPath to (path to desktop) as string set aRes to exportNumbersDocToPDF(tmpPath) –Pages書類からPDF書き出し on exportNumbersDocToPDF(targFolderPath as string) tell application "Numbers" set dCount to count every document if dCount = 0 then return false end if set aPath to file of document 1 end tell set curPath to (current application’s NSString’s stringWithString:(POSIX path of aPath))’s lastPathComponent()’s stringByDeletingPathExtension()’s stringByAppendingString:".pdf" set outPath to (targFolderPath & curPath) tell application "Numbers" set anOpt to {class:export options, image quality:Best} export document 1 to file outPath as PDF with properties anOpt end tell end exportNumbersDocToPDF |
RGB色をHSBAに変換して色名称を計算 v2

| AppleScript名:RGB色をHSBAに変換して色名称を計算 v2 |
| — Created 2018-01-08 by Takaaki Naganoya — 2018 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "AppKit" property NSColor : a reference to current application’s NSColor set {rCol, gCol, bCol} to choose color set cName to retColorDomainName(rCol, gCol, bCol, 65535) of me on retColorDomainName(rCol as integer, gCol as integer, bCol as integer, aColorMax) set aCol to makeNSColorFromRGBAval(rCol, gCol, bCol, aColorMax, aColorMax) of me set hueVal to aCol’s hueComponent() set satVal to aCol’s saturationComponent() set brightVal to aCol’s brightnessComponent() if satVal ≤ 0.01 then set satVal to 0.0 set colName to "" if satVal = 0.0 then if brightVal ≤ 0.2 then set colName to "black" else if (brightVal > 0.95) then set colName to "white" else set colName to "gray" end if else if hueVal ≤ (15.0 / 360) or hueVal ≥ (330 / 360) then set colName to "red" else if hueVal ≤ (45.0 / 360) then set colName to "orange" else if hueVal < (70.0 / 360) then set colName to "yellow" else if hueVal < (150.0 / 360) then set colName to "green" else if hueVal < (190.0 / 360) then set colName to "cyan" else if (hueVal < 250.0 / 360.0) then set colName to "blue" else if (hueVal < 290.0 / 360.0) then set colName to "purple" else set colName to "magenta" end if end if return colName end retColorDomainName on makeNSColorFromRGBAval(redValue as integer, greenValue as integer, blueValue as integer, alphaValue as integer, aMaxVal as integer) set aRedCocoa to (redValue / aMaxVal) as real set aGreenCocoa to (greenValue / aMaxVal) as real set aBlueCocoa to (blueValue / aMaxVal) as real set aAlphaCocoa to (alphaValue / aMaxVal) as real set aColor to NSColor’s colorWithCalibratedRed:aRedCocoa green:aGreenCocoa blue:aBlueCocoa alpha:aAlphaCocoa return aColor end makeNSColorFromRGBAval |
16進数文字列とNumberの相互変換 v2.2
| AppleScript名:16進数文字列とNumberの相互変換 v2.2 |
| — Created 2018-01-20 by Takaaki Naganoya — 2018 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" repeat with i from 0 to 65535 set aRes to numToHexl(i) of hexKit set bRes to hextoNum(aRes) of hexKit if i ≠ bRes then display dialog "Not equal to " & (i as string) & " —> " & aRes & " —> " & bRes end repeat script hexKit property hexList : {missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, missing value, 10, 11, 12, 13, 14, 15} property stringSetList : {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"} –16進数文字列からNumberに変換 on hextoNum(hexText as string) set hList to characters of hexText set rhList to reverse of hList set digitNum to 0 set sumNum to 0 repeat with i in rhList set j to id of contents of i if j > 102 then return false set ofN to contents of item j of hexList of me if ofN = missing value then return false set sumNum to sumNum + (16 ^ digitNum) * (ofN) set digitNum to digitNum + 1 end repeat return sumNum as integer end hextoNum –数値を16進数文字列に変換 on numToHexl(origNum) if origNum = 0 then return "0" set resString to {} repeat if origNum ≤ 0 then exit repeat set resNum to (origNum mod 16) set resText to contents of item (resNum + 1) of stringSetList set resString to resText & resString set origNum to origNum div 16 end repeat return (resString as string) end numToHexl end script |
デスクトップ上のRetina解像度のスクリーンショット画像でICNS以外のものを検索
| AppleScript名:デスクトップ上のRetina解像度のスクリーンショット画像でICNS以外のものを検索 |
| — Created 2017-09-23 by Takaaki Naganoya — Modified 2017-12-01 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use mdLib : script "Metadata Lib" version "1.0.0" –https://www.macosxautomation.com/applescript/apps/Script_Libs.html#Metadata_Lib set theFolder to path to desktop set fRes to mdLib’s searchFolders:{theFolder} searchString:"kMDItemResolutionHeightDPI == %@ && kMDItemResolutionWidthDPI == %@ && kMDItemIsScreenCapture == %@ && NOT (kMDItemContentTypeTree contains %@)" searchArgs:{144, 144, true, "com.apple.icns"} –> {"/Users/me/Desktop/FromDesktop/スクリーンショット 2015-12-18 13.02.14.png", "/Users/me/Desktop/FromDesktop/スクリーンショット 2015-08-14 18.08.41.png"} |
指定日時以降に作成されたファイルをSpotlight検索 v3
| AppleScript名:指定日時以降に作成されたファイルをSpotlight検索 v3 |
| — Created 2017-09-21 by Takaaki Naganoya — Modified 2017-09-22 by Shane Stanley — 2017 Piyomaru Software use AppleScript version "2.5" use scripting additions use framework "Foundation" use mdLib : script "Metadata Lib" version "1.0.0" –http://piyocast.com/as/archives/4841 property NSTimeZone : a reference to current application’s NSTimeZone property NSCalendar : a reference to current application’s NSCalendar set aDate to getDateInternationalYMDhms(2017, 10, 22, 0, 0, 0) of me –> (NSDate) 2017-09-21 14:02:00 +0000 set thePath to POSIX path of (path to desktop) –> "/Users/me/Desktop/" set theFiles to mdLib’s searchFolders:{thePath} searchString:("kMDItemFSCreationDate >= %@") searchArgs:{aDate} –> returns POSIX path list on getDateInternationalYMDhms(aYear, aMonth, aDay, anHour, aMinute, aSecond) set theNSCalendar to NSCalendar’s currentCalendar() set theDate to theNSCalendar’s dateWithEra:1 |year|:aYear |month|:aMonth |day|:aDay hour:anHour minute:aMinute |second|:aSecond nanosecond:0 return theDate end getDateInternationalYMDhms |
指定フォルダ内のラベル(Yellow, Red, Orange)のファイル一覧を取得
| AppleScript名:指定フォルダ内のラベル(Yellow, Red, Orange)のファイル一覧を取得 |
| — Created 2017-12-05 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use mdLib : script "Metadata Lib" version "1.0.0" –https://www.macosxautomation.com/applescript/apps/Script_Libs.html#Metadata_Lib set aLabelList to {5, 6, 7} –Yellow, Red, Orange –0: No Label, 1: Gray, 2: Green, 3: Purple, 4: Blue, 5: Yellow, 6: Red, 7: Orange set thePath to POSIX path of (path to desktop) set aRes to spotlightFindByLabels(aLabelList, thePath) of me –> list of POSIX path on spotlightFindByLabels(aLabelList as list, thePath as string) set aList to makeRepeatinglList(length of aLabelList, "kMDItemFSLabel == %@") set aStr to retStrFromArrayWithDelimiter(aList, " OR ") of me set fRes to mdLib’s searchFolders:{thePath} searchString:aStr searchArgs:aLabelList return fRes end spotlightFindByLabels –リストを指定デリミタをはさんでテキスト化 on retStrFromArrayWithDelimiter(aList as list, aDelim as string) set anArray to current application’s NSArray’s arrayWithArray:aList return (anArray’s componentsJoinedByString:aDelim) as string end retStrFromArrayWithDelimiter –指定回数、指定アイテムを連結したリストを作成 on makeRepeatinglList(hitNum as integer, hitItem as string) set outList to {} repeat hitNum times set the end of outList to hitItem end repeat return outList end makeRepeatinglList |
Maps.appで開始地点と到着地点の住所を指定して経路表示 v3
| AppleScript名:Maps.appで開始地点と到着地点の住所を指定して経路表示 v3 |
| — Created 2017-01-17 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set aURL to "http://maps.apple.com/" set aRec to {saddr:"中村橋駅", daddr:"よみうりホール"} –経路表示 set bURL to retURLwithParams(aURL as string, aRec as record) open location bURL on retURLwithParams(aBaseURL as string, aRec as record) set aDic to current application’s NSMutableDictionary’s dictionaryWithDictionary:aRec set aKeyList to (aDic’s allKeys()) as list set aValList to (aDic’s allValues()) as list set aLen to length of aKeyList set bLen to length of aValList if aLen is not equal to bLen then return false set qList to {} repeat with i from 1 to aLen set aName to (contents of item i of aKeyList) as string set aVal to (contents of item i of aValList) as string set the end of qList to (current application’s NSURLQueryItem’s queryItemWithName:aName value:aVal) end repeat set aComp to current application’s NSURLComponents’s alloc()’s initWithString:aBaseURL aComp’s setQueryItems:qList set aURL to (aComp’s |URL|()’s absoluteString()) as text return aURL end retURLwithParams |
com.apple.Maps
Maps.appで住所検索表示 v4
| AppleScript名:Map.appで住所検索表示 v4 |
| use AppleScript version "2.4" use scripting additions use framework "Foundation" set aBaseURL to "http://maps.apple.com/" set aParam to "東京都港区六本木6丁目10番1号" –Apple Japanの住所 set aRec to {q:aParam} set cURL to retURLwithParams(aBaseURL, aRec) of me tell application "Maps" open location cURL end tell on retURLwithParams(aBaseURL as string, aRec as record) set aDic to current application’s NSMutableDictionary’s dictionaryWithDictionary:aRec set aKeyList to (aDic’s allKeys()) as list set aValList to (aDic’s allValues()) as list set aLen to length of aKeyList set bLen to length of aValList if aLen is not equal to bLen then return false set qList to {} repeat with i from 1 to aLen set aName to (contents of item i of aKeyList) as string set aVal to (contents of item i of aValList) as string set the end of qList to (current application’s NSURLQueryItem’s queryItemWithName:aName value:aVal) end repeat set aComp to current application’s NSURLComponents’s alloc()’s initWithString:aBaseURL aComp’s setQueryItems:qList set aURL to (aComp’s |URL|()’s absoluteString()) as text return aURL end retURLwithParams |
com.apple.Maps
Maps.appで緯度経度指定表示 v3
| AppleScript名:Map.appで緯度経度指定表示 v3 |
| use AppleScript version "2.4" use scripting additions use framework "Foundation" set aURL to "http://maps.apple.com/?ll=41.82459,140.7174504&t=m" –ラウンドワンスタジアム函館 open location aURL |
com.apple.Maps
iTunesでAirPlayデバイスを指定
| AppleScript名:iTunesでAirPlayデバイスを指定 |
| tell application "iTunes" set aList to properties of every AirPlay device –> {{class:AirPlay device, id:27, index:1, name:"コンピュータ", persistent ID:"0000000000000000", active:false, available:true, kind:computer, protected:false, selected:true, supports audio:true, supports video:true, sound volume:100}, {class:AirPlay device, id:58366, index:2, name:"Apple TV", persistent ID:"00005855CA413D01", active:false, available:true, kind:Apple TV, network address:"58:55:ca:41:3d:01", protected:false, selected:false, supports audio:true, supports video:true, sound volume:100}} set current AirPlay devices to AirPlay device "コンピュータ" end tell |
iTunesライブラリの曲のアーティスト名を集計
| AppleScript名:iTunesライブラリの曲のアーティスト名を集計 |
| — Created 2017-01-07 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "iTunesLibrary" set library to current application’s ITLibrary’s libraryWithAPIVersion:"1.0" |error|:(missing value) if library is equal to missing value then return set allTracks to library’s allMediaItems() set allCount to allTracks’s |count|() set anEnu to allTracks’s objectEnumerator() set newArray to current application’s NSMutableArray’s alloc()’s init() repeat set aPL to anEnu’s nextObject() if aPL = missing value then exit repeat try set aKind to (aPL’s mediaKind) as integer if (aKind as integer) is equal to 2 then –Music, Song set plName to aPL’s artist’s |name| as string set pl2Name to (my changeThis:" " toThat:"" inString:plName) –日本語アーティスト名で姓と名の間にスペースが入っているものがある(表記ゆらぎ)ので対策 newArray’s addObject:(pl2Name) end if on error set aLoc to (aPL’s location’s |path|()) as string log aLoc end try end repeat set aRes to countItemsByItsAppearance(newArray) of me –> {{theName:"浜田省吾", numberOfTimes:442}, {theName:"B’z", numberOfTimes:379}, {theName:"渡辺岳夫・松山祐士", numberOfTimes:199}, {theName:"VariousArtists", numberOfTimes:192}, {theName:"菅野よう子", numberOfTimes:108}, {theName:"布袋寅泰", numberOfTimes:100}, {theName:"三枝成彰", numberOfTimes:95}, {theName:"宇多田ヒカル", numberOfTimes:94}, {theName:"宮川泰", numberOfTimes:81}, {theName:"MichaelJackson", numberOfTimes:78}, {theName:"稲葉浩志", numberOfTimes:73}, … –出現回数で集計 on countItemsByItsAppearance(aList) set aSet to current application’s NSCountedSet’s alloc()’s initWithArray:aList set bArray to current application’s NSMutableArray’s array() set theEnumerator to aSet’s objectEnumerator() repeat set aValue to theEnumerator’s nextObject() if aValue is missing value then exit repeat bArray’s addObject:(current application’s NSDictionary’s dictionaryWithObjects:{aValue, (aSet’s countForObject:aValue)} forKeys:{"theName", "numberOfTimes"}) end repeat –出現回数(numberOfTimes)で降順ソート set theDesc to current application’s NSSortDescriptor’s sortDescriptorWithKey:"numberOfTimes" ascending:false bArray’s sortUsingDescriptors:{theDesc} return bArray as list end countItemsByItsAppearance on changeThis:findString toThat:repString inString:someText set theString to current application’s NSString’s stringWithString:someText set theString to theString’s stringByReplacingOccurrencesOfString:findString withString:repString options:(current application’s NSRegularExpressionSearch) range:{location:0, |length|:length of someText} return theString as text end changeThis:toThat:inString: |
iTunesライブラリのファイル種別集計
| AppleScript名:iTunesライブラリのファイル種別集計 |
| — Created 2016-11-02 by Takaaki Naganoya — 2016 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "iTunesLibrary" –http://piyocast.com/as/archives/4301 set library to current application’s ITLibrary’s libraryWithAPIVersion:"1.0" |error|:(missing value) if library is equal to missing value then return set playLists to library’s allPlaylists() set gArray to library’s allMediaItems()’s |kind| set aRes to countItemsByItsAppearance(gArray) of me –> {{theName:"AAC オーディオファイル", numberOfTimes:3273}, {theName:"MPEG オーディオファイル", numberOfTimes:1768}, {theName:"購入した AAC オーディオファイル", numberOfTimes:1299}, {theName:"保護された AAC オーディオファイル", numberOfTimes:1102}, {theName:missing value, numberOfTimes:331}, {theName:"保護された MPEG-4 オーディオストリーム", numberOfTimes:183}, {theName:"MPEG オーディオストリーム", numberOfTimes:71}, {theName:"Apple ロスレス・オーディオファイル", numberOfTimes:36}, {theName:"QuickTime ムービーファイル", numberOfTimes:35}, {theName:"保護されたブック", numberOfTimes:28}, {theName:"AIFF オーディオファイル", numberOfTimes:21}, {theName:"MPEG-4 ビデオファイル", numberOfTimes:17}, {theName:"着信音", numberOfTimes:17}, {theName:"保護された MPEG-4 ビデオファイル", numberOfTimes:14}, {theName:"PDF 書類", numberOfTimes:11}, {theName:"ブック", numberOfTimes:8}, {theName:"購入したブック", numberOfTimes:6}, {theName:"iPhone/iPod touch/iPad App", numberOfTimes:5}, {theName:"購入した MPEG-4 ビデオファイル", numberOfTimes:5}, {theName:"インターネットオーディオストリーム", numberOfTimes:3}, {theName:"WAV オーディオファイル", numberOfTimes:2}, {theName:"iTunes Extras", numberOfTimes:2}, {theName:"iPhone/iPod touch App", numberOfTimes:1}, {theName:"QuickTime ムービー URL", numberOfTimes:1}, {theName:"Purchased AAC audio file", numberOfTimes:1}} –出現回数で集計 on countItemsByItsAppearance(aList) set aSet to current application’s NSCountedSet’s alloc()’s initWithArray:aList set bArray to current application’s NSMutableArray’s array() set theEnumerator to aSet’s objectEnumerator() repeat set aValue to theEnumerator’s nextObject() if aValue is missing value then exit repeat bArray’s addObject:(current application’s NSDictionary’s dictionaryWithObjects:{aValue, (aSet’s countForObject:aValue)} forKeys:{"theName", "numberOfTimes"}) end repeat –出現回数(numberOfTimes)で降順ソート set theDesc to current application’s NSSortDescriptor’s sortDescriptorWithKey:"numberOfTimes" ascending:false bArray’s sortUsingDescriptors:{theDesc} return bArray as list end countItemsByItsAppearance |






