AppleScript名:serializeされたlistのrecordからKeynoteで新規ドキュメントを作成してグラフを作成 |
— Created 2016-10-31 by Takaaki Naganoya — 2016 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set selData to retSerializedData() of me set aList to (deserializeToPlistString(selData) of me) as list set aLen to length of aList if aLen > 10 then set bList to items 1 thru 10 of aList else copy aList to bList end if makeKeynoteGraph(bList, "自分のiTunesライブラリ中のジャンル内訳") of me on makeKeynoteGraph(bList, aTitle) set labelList to {} set dataList to {} repeat with i from 1 to (length of bList) set the end of labelList to contents of theName of (item i of bList) set the end of dataList to contents of numberOfTimes of (item i of bList) end repeat set targWidth to 500 set targHeight to 500 tell application "Keynote" activate set thisDocument to make new document with properties {height:764, width:1024, document theme:theme "ホワイト"} tell thisDocument set aHeight to height set aWidth to width tell slide 1 set base slide to master slide "タイトル(上)" of thisDocument set object text of default title item to aTitle tell default title item set height to 80 end tell (add chart row names {"ROW A"} column names labelList data {dataList} type pie_2d group by chart column) tell chart 1 set width to targWidth set height to targHeight set position to {(aWidth / 2) – (targWidth / 2), (aHeight / 2) – (targHeight / 2) + 20} end tell end tell end tell end tell end makeKeynoteGraph on retSerializedData() return "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"> <plist version=\"1.0\"> <array> <dict> <key>numberOfTimes</key> <integer>1721</integer> <key>theName</key> <string>サウンドトラック</string> </dict> <dict> <key>numberOfTimes</key> <integer>942</integer> <key>theName</key> <string>ロック</string> </dict> <dict> <key>numberOfTimes</key> <integer>539</integer> <key>theName</key> <string>クラシック</string> </dict> <dict> <key>numberOfTimes</key> <integer>492</integer> <key>theName</key> <string>ポップ</string> </dict> <dict> <key>numberOfTimes</key> <integer>352</integer> <key>theName</key> <string>J-Pop</string> </dict> <dict> <key>numberOfTimes</key> <integer>330</integer> <key>theName</key> <string>アニメ</string> </dict> <dict> <key>numberOfTimes</key> <integer>279</integer> <key>theName</key> <string>Pop</string> </dict> <dict> <key>numberOfTimes</key> <integer>218</integer> <key>theName</key> <string>World</string> </dict> <dict> <key>numberOfTimes</key> <integer>188</integer> <key>theName</key> <string>Soundtrack</string> </dict> <dict> <key>numberOfTimes</key> <integer>187</integer> <key>theName</key> <string>ジャズ</string> </dict> <dict> <key>numberOfTimes</key> <integer>166</integer> <key>theName</key> <string>エレクトロニック</string> </dict> <dict> <key>numberOfTimes</key> <integer>165</integer> <key>theName</key> <string>Classical</string> </dict> <dict> <key>numberOfTimes</key> <integer>148</integer> <key>theName</key> <string>Rock</string> </dict> <dict> <key>numberOfTimes</key> <integer>125</integer> <key>theName</key> <string>R&B</string> </dict> <dict> <key>numberOfTimes</key> <integer>104</integer> <key>theName</key> <string>ニューエイジ</string> </dict> <dict> <key>numberOfTimes</key> <integer>81</integer> <key>theName</key> <string>Unclassifiable</string> </dict> <dict> <key>numberOfTimes</key> <integer>57</integer> <key>theName</key> <string>Children’s</string> </dict> <dict> <key>numberOfTimes</key> <integer>47</integer> <key>theName</key> <string>歌謡曲</string> </dict> <dict> <key>numberOfTimes</key> <integer>38</integer> <key>theName</key> <string>Holiday</string> </dict> <dict> <key>numberOfTimes</key> <integer>34</integer> <key>theName</key> <string>オルタナティブ</string> </dict> <dict> <key>numberOfTimes</key> <integer>32</integer> <key>theName</key> <string>Data</string> </dict> <dict> <key>numberOfTimes</key> <integer>31</integer> <key>theName</key> <string>イージーリスニング</string> </dict> <dict> <key>numberOfTimes</key> <integer>28</integer> <key>theName</key> <string>ヴォーカル</string> </dict> <dict> <key>numberOfTimes</key> <integer>28</integer> <key>theName</key> <string>ワールド</string> </dict> <dict> <key>numberOfTimes</key> <integer>19</integer> <key>theName</key> <string>soundtrack</string> </dict> <dict> <key>numberOfTimes</key> <integer>15</integer> <key>theName</key> <string>ディズニー</string> </dict> <dict> <key>numberOfTimes</key> <integer>15</integer> <key>theName</key> <string>シンガーソングライター</string> </dict> <dict> <key>numberOfTimes</key> <integer>15</integer> <key>theName</key> <string>ブルース</string> </dict> <dict> <key>numberOfTimes</key> <integer>14</integer> <key>theName</key> <string>Easy Listening</string> </dict> <dict> <key>numberOfTimes</key> <integer>14</integer> <key>theName</key> <string>ラテン</string> </dict> <dict> <key>numberOfTimes</key> <integer>14</integer> <key>theName</key> <string>Electronica/Dance</string> </dict> <dict> <key>numberOfTimes</key> <integer>13</integer> <key>theName</key> <string>Anime</string> </dict> <dict> <key>numberOfTimes</key> <integer>10</integer> <key>theName</key> <string>フォーク</string> </dict> <dict> <key>numberOfTimes</key> <integer>9</integer> <key>theName</key> <string>J-POP</string> </dict> <dict> <key>numberOfTimes</key> <integer>9</integer> <key>theName</key> <string>New Age</string> </dict> <dict> <key>numberOfTimes</key> <integer>5</integer> <key>theName</key> <string>ダンス</string> </dict> <dict> <key>numberOfTimes</key> <integer>5</integer> <key>theName</key> <string>ホリデー</string> </dict> <dict> <key>numberOfTimes</key> <integer>4</integer> <key>theName</key> <string>カントリー</string> </dict> <dict> <key>numberOfTimes</key> <integer>4</integer> <key>theName</key> <string>演歌</string> </dict> <dict> <key>numberOfTimes</key> <integer>3</integer> <key>theName</key> <string>Latin</string> </dict> <dict> <key>numberOfTimes</key> <integer>3</integer> <key>theName</key> <string>ヒップホップ/ラップ</string> </dict> <dict> <key>numberOfTimes</key> <integer>2</integer> <key>theName</key> <string>Vocal</string> </dict> <dict> <key>numberOfTimes</key> <integer>2</integer> <key>theName</key> <string>R&B/ソウル</string> </dict> <dict> <key>numberOfTimes</key> <integer>2</integer> <key>theName</key> <string>R&B/ソウル</string> </dict> <dict> <key>numberOfTimes</key> <integer>2</integer> <key>theName</key> <string>#NIPPONSEI @ IRC.MIRCX.COM</string> </dict> <dict> <key>numberOfTimes</key> <integer>1</integer> <key>theName</key> <string>148</string> </dict> <dict> <key>numberOfTimes</key> <integer>1</integer> <key>theName</key> <string>Electronic</string> </dict> <dict> <key>numberOfTimes</key> <integer>1</integer> <key>theName</key> <string>Folk</string> </dict> <dict> <key>numberOfTimes</key> <integer>1</integer> <key>theName</key> <string>NHK FM(東京)</string> </dict> <dict> <key>numberOfTimes</key> <integer>1</integer> <key>theName</key> <string>その他</string> </dict> <dict> <key>numberOfTimes</key> <integer>1</integer> <key>theName</key> <string>チルドレン・ミュージック</string> </dict> <dict> <key>numberOfTimes</key> <integer>1</integer> <key>theName</key> <string>Seattle Pacific University – Latin</string> </dict> <dict> <key>numberOfTimes</key> <integer>1</integer> <key>theName</key> <string>Kayokyoku</string> </dict> <dict> <key>numberOfTimes</key> <integer>1</integer> <key>theName</key> <string>ヒップホップ/ ラップ</string> </dict> <dict> <key>numberOfTimes</key> <integer>1</integer> <key>theName</key> <string>Dance</string> </dict> <dict> <key>numberOfTimes</key> <integer>1</integer> <key>theName</key> <string>インストゥルメンタル</string> </dict> <dict> <key>numberOfTimes</key> <integer>1</integer> <key>theName</key> <string>146</string> </dict> </array> </plist> " end retSerializedData –list or record –> XML-format plist string on serializeToPlistString(aList as {list, record}) set pListData to current application’s NSPropertyListSerialization’s dataWithPropertyList:aList |format|:(current application’s NSPropertyListXMLFormat_v1_0) options:0 |error|:(missing value) set bStr to (current application’s NSString’s alloc()’s initWithData:pListData encoding:(current application’s NSUTF8StringEncoding)) as string return bStr end serializeToPlistString –XML-format plist string–> list or record on deserializeToPlistString(aStr as string) set deStr to current application’s NSString’s stringWithString:aStr set theData to deStr’s dataUsingEncoding:(current application’s NSUTF8StringEncoding) set aList to current application’s NSPropertyListSerialization’s propertyListWithData:theData options:(current application’s NSPropertyListMutableContainersAndLeaves) |format|:(missing value) |error|:(missing value) return aList end deserializeToPlistString |
More from my site
(Visited 52 times, 1 visits today)