Menu

Skip to content
AppleScriptの穴
  • Home
  • Products
  • Books
  • Docs
  • Events
  • Forum
  • About This Blog
  • License
  • 仕事依頼

AppleScriptの穴

Useful & Practical AppleScript archive. Click '★Click Here to Open This Script' Link to download each AppleScript

タグ: iTunes

Apple Musicが2021年6月から高音質化、空間オーディオ対応

Posted on 5月 18, 2021 by Takaaki Naganoya

サブスクリプション(月額固定費用)サービスのApple Musicの全曲が、「6月からロスレスオーディオのApple Lossless Audio Codec(ALAC)に対応し、一部ではDolby Atmos空間オーディオに対応した楽曲が利用可能になる」とのこと。噂では聞いていましたが、話半分ぐらいで聞いていました。

目下作成中で完成間近の「ミュージック.app Scripting Book With AppleScript」、「書いていないことはない」と自分が胸を張って送り出そうとしている本ですが、当然のようにこの発表に影響を受けます。

こちらで、iTunes Storeで購入した楽曲の詳細情報と、Apple Musicからダウンロードしてきた曲の詳細情報を比較しているのですが……

6/1になったら、再度確認してアップデートする必要がありそうです。この表自体はAppleScriptで、「AppleScriptの実行結果をNumbersの表にまとめる」という処理を行なっているため、作り直してもそれほど作業は発生しないのですが(自動化しておいてよかった!)、まー、反映しておかないとマズイ情報であることに代わりはありません。

Codecが変わるだけだと思われるので、拡張子やらファイル呼称が変わったりすることはなさそうですが、ファイルのサイズが巨大化しそうでそのあたりどーなるのか? 目下、.m4p形式のファイルをローカルにダウンロードできるようになっていますが、そこが変わるのか変わらないのか。

高音質化しても違いがわからない人向けに、従来どおりのCodecでダウンロード/ストリーミングさせるオプションがあるような気もします。6月にMusic.app自体のアップデートもあると見るべきでしょうか。

(Visited 54 times, 1 visits today)
Posted in news | Tagged 10.14savvy 10.15savvy 11.0savvy iTunes Music | Leave a comment

display text fields Library v1.3

Posted on 12月 31, 2019 by Takaaki Naganoya

「display text fields」AppleScriptライブラリをv1.3にアップデートしました。

–> Download display text fields_v13 (To ~/Library/Script Libraries/)

v1.3ではテキストフィールドの最大横幅の計算を修正し、フィールド数が増えたときにダイアログ上から項目がはみ出さないようにScroll Viewをつけるようにしました。

本来目的としていた用途に使ってみたらイマイチだった点を修正した格好です。AppleScriptで取得した各種アプリケーションのオブジェクトのプロパティ情報をダイアログ上で一覧表示して確認するというのが、自分がこのライブラリを作った目的です。

以下は、サンプルスクリプト「文字列で指定したAppleScriptの実行結果をテキストで取得する v2」についての説明です。

割とえげつない処理をしていますが、作りためておいたルーチンを引っ張り出してきただけなので、書くのにさほど時間はかけていません。

こうしたAppleScriptのプロパティ値をparseするには、スクリプトエディタの結果欄を文字列として取得するか(GUI Scripting経由でやったことがあります)、こうしてメモリ上にスクリプトエディタ+結果表示用のビューを生成してメモリ上でAppleScriptを実行して結果をテキストで取得するということになると思います。前者だとGUI Scriptingの実行権限が必要になるため、Cocoaの機能を利用したほうが手軽という状況です。

(途中で入れ替えた)v2では、macOS 10.15対応、ランタイム環境によってはうまく動かない「as anything」の使用をやめるなどの変更を加えました。

AppleScript名:文字列で指定したAppleScriptの実行結果をテキストで取得する v2.scpt
— Created 2016-01-08 by Takaaki Naganoya
— 2016 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "OSAKit"
use framework "AppKit"
use tfLib : script "display text fields"

property OSAScript : a reference to current application’s OSAScript
property NSTextView : a reference to current application’s NSTextView
property OSAScriptView : a reference to current application’s OSAScriptView
property OSAScriptController : a reference to current application’s OSAScriptController

property myRes : ""

–OSのメジャーバージョンを数値で取得
set osVer to system attribute "sys2"

if osVer ≥ 15 then
  set srcStr to "tell application \"Music\"
  set aSel to first item of selection
  set aRes to (properties of aSel)
end tell"
else
  set srcStr to "tell application \"iTunes\"
  set aSel to first item of selection
  set aRes to (properties of aSel)
end tell"
end if

my performSelectorOnMainThread:"getResultStringFromScript:" withObject:(srcStr) waitUntilDone:true

set aRes to getListFromText(myRes) of me

set aList to {}
set bList to {}
set aLen to length of aRes

repeat with i from 1 to aLen
  set {aCon, bCon} to contents of item i of aRes
  
set the end of aList to aCon
  
set the end of bList to bCon
end repeat

confirm text fields main message "Track Info" sub message "Properties about selected track" key list aList value list bList

–Get AppleScript’s Result as string
on getResultStringFromScript:paramObj
  set srcStr to paramObj as string
  
set myRes to ""
  
  
set targX to 500 –View Width
  
set targY to 200 –View Height
  
  
set osaCon to OSAScriptController’s alloc()’s init()
  
set osaView to OSAScriptView’s alloc()’s initWithFrame:(current application’s NSMakeRect(0, 0, targX, targY))
  
  
set resView to NSTextView’s alloc()’s initWithFrame:(current application’s NSMakeRect(0, 0, targX, targY))
  
resView’s setRichText:true
  
resView’s useAllLigatures:true
  
  
osaCon’s setScriptView:osaView
  
osaCon’s setResultView:resView
  
  
osaView’s setString:srcStr
  
osaCon’s runScript:(missing value)
  
  
set myRes to resView’s |string|() as string
end getResultStringFromScript:

–スクリプトエディタのresult欄に返ってきたテキストをリストに変える
on getListFromText(aText)
  
  
script getListFromTextO
    property aaText : ""
    
property gList : {}
    
property outList : {}
    
property aG : ""
    
property valList : {}
  end script
  
  
copy aText to (aaText of getListFromTextO)
  
  
set (gList of getListFromTextO) to {}
  
set (outList of getListFromTextO) to {}
  
set (aG of getListFromTextO) to ""
  
set (valList of getListFromTextO) to {}
  
  
if (aaText of getListFromTextO) does not start with "{" and (aaText of getListFromTextO) does not end with "}" then
    return {}
  end if
  
  
set aLen to length of (aaText of getListFromTextO)
  
set (aG of getListFromTextO) to text 2 thru -2 of (aaText of getListFromTextO)
  
set (gList of getListFromTextO) to characters of (aG of getListFromTextO)
  
  
  
set sPos to 2 –1文字目は\"{\"なので2文字目からスキャンを開始する
  
set ePos to 2
  
  
set imdF to false –Immediate Data Flag(文字列中を示すダブルクォート内の場合にはtrueになる)
  
set listF to 0 –stacking段数が入る
  
  
set attrF to true –属性ラベルスキャン時にtrue、データ末尾スキャン時にfalse
  
  
  
repeat with i in (gList of getListFromTextO)
    
    
set j to contents of i
    
    
if attrF = true and imdF = false and listF = 0 then
      
      
–属性値部分の末尾検出
      
if j = ":" then
        if text sPos thru sPos of (aaText of getListFromTextO) = " " then
          set sPos to sPos + 1
        end if
        
set anOut to text sPos thru ePos of (aaText of getListFromTextO)
        
set sPos to ePos + 1
        
set the end of (valList of getListFromTextO) to anOut
        
set attrF to false –データのスキャンを開始する
        
set imdF to false
        
set listF to 0
      end if
      
    else if imdF = false and listF = 0 and j = "," then
      
      
–データ部分の末尾検出
      
set anOut to text sPos thru (ePos – 1) of (aaText of getListFromTextO)
      
set sPos to ePos + 1
      
set the end of (valList of getListFromTextO) to anOut
      
set the end of (outList of getListFromTextO) to (valList of getListFromTextO)
      
set (valList of getListFromTextO) to {}
      
      
set attrF to true –次が属性値ラベルであることを宣言
      
set imdF to false
      
set listF to 0
      
    else if j = "{" then
      if imdF = false then
        set listF to listF + 1 –1段スタックにpush
      end if
    else if j = "}" then
      if imdF = false then
        set listF to listF – 1 –1段スタックからpop
      end if
    else if j = "\"" then
      if imdF = true then
        set imdF to false
      else
        set imdF to true
      end if
    end if
    
    
set ePos to ePos + 1
    
  end repeat
  
  
–ラストのデータ部分を出力
  
try
    set the end of (valList of getListFromTextO) to text sPos thru (ePos – 1) of (aaText of getListFromTextO)
    
set the end of (outList of getListFromTextO) to (valList of getListFromTextO)
  on error
    false
  end try
  
  
return contents of (outList of getListFromTextO)
  
end getListFromText

★Click Here to Open This Script 

(Visited 61 times, 1 visits today)
Posted in dialog GUI OSA | Tagged 10.13savvy 10.14savvy 10.15savvy iTunes NSTextView OSAScript OSAScriptController OSAScriptView | Leave a comment

Apple TVアプリベータ版にAppleScript用語辞書

Posted on 6月 5, 2019 by Takaaki Naganoya

You'll be happy to know that but both Music and Apple TV apps on Catalina have Applescript dictionaries. Music even has stuff for controlling Air Play.

I'm pleasantly surprised.

— Kevin van Haaren (@kvanh) June 4, 2019


macOS 10.15, Catalina Beta 1を試用したユーザーからの報告によると、同バージョンに同梱されているApple TVアプリに旧iTunes.appのAppleScript用語辞書を元にしたと思われるAppleScript用語辞書が含まれており、AppleScriptからコントロールできるようです。

旧iTunes.appを親に持つ新アプリは「Music」「Apple TV」、そして「Podcast」の3本があるわけですが、前者2つにAppleScript用語辞書があることが確認されました。

残念ながら現時点ではPodcastアプリにAppleScript用語辞書はないようですが、今後のアップデートで状況は変わるかもしれません。

(Visited 36 times, 1 visits today)
Posted in sdef | Tagged 10.15savvy Apple TV iTunes Music | Leave a comment

Musicアプリベータ版にAppleScript用語辞書

Posted on 6月 4, 2019 by Takaaki Naganoya

https://twitter.com/boyvanamstel/status/1135651562540478466

このところ、仕事で大きめのAppleScriptのシステムを組んでいるのでWWDC方面はぜんぜんキャチアップできていないのですが、iTunesがMusic、Podcast、Movieの3つのアプリに解体されるという噂が、だいたいそのとおりになったようで。

さらに、Musicアプリのベータ版にはiTunesと同じ(未確認)AppleScript用語辞書が搭載されているとか。ただし、iTunesの辞書そのままではない(比較してみると完全に同じではないらしい)点に注意が必要です。別アプリに分離されたデータとかは扱えないように(珍しくきちんと)配慮されているようです。

地味に、macOS 10.15, CatalinaでMacBook Pro 2012が切られなかったことが驚きであります。画面のコーティングが剥離してきても、ディスプレイまわりのパッキンがつぶれても、筐体裏面のゴム足が消え失せても、まだサポートが続くMacBook Pro 2012。

(Visited 38 times, 1 visits today)
Posted in sdef | Tagged 10.15savvy iTunes Music | Leave a comment

iTunesライブラリ中の楽曲のみしぼりこんでアルバム名と曲名を出力 v2

Posted on 12月 23, 2018 by Takaaki Naganoya

iTunesライブラリ(+Apple Book)のメディアから楽曲(mediaKind=ITLibMediaItemMediaKindSong)のみ抽出してアルバムのタイトル+曲名の一覧を取得するAppleScriptです。

--> {{albumTitle:"アルバムタイトル名", songTitle:"曲名"}....}

のように、アルバム名と曲名のレコードをリスト化して返します。

iTunesLibrary.framework経由でメデイアアイテムの情報にアクセスするため、iTunes.appが起動していてもいなくても関係ありません。開発環境のマシン(MacBook Pro Retina 2012 Core i7 2.66GHz)でiTunesに6,871曲の楽曲が存在している状態で3.12秒程度です。

iTunes.appとプロセス間通信していないため、macOS 10.14でSecurityダイアログが表示されることもありません。

AppleScript名:iTunesライブラリ中の楽曲のみしぼりこんでアルバム名と曲名を出力 v2.scptd
— Created 2018-10-16 by Takaaki Naganoya
— 2018 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "iTunesLibrary"

script spdList
  property albmList : {}
  
property outList : {}
end script

property ITLibrary : a reference to current application’s ITLibrary
property NSPredicate : a reference to current application’s NSPredicate

set library to 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())

set aPredicate to NSPredicate’s predicateWithFormat:"self.mediaKind = 2" –ITLibMediaItemMediaKindSong
set filteredArray to gArray’s filteredArrayUsingPredicate:aPredicate

set albmArray to (filteredArray’s album’s title)
set (albmList of spdList) to (albmArray’s valueForKeyPath:"@distinctUnionOfObjects.self") as list
set songArray to (filteredArray’s title) as list
set aLen to length of songArray
set albmArray to albmArray as list

repeat with i from 1 to aLen
  set tmpItem1 to contents of item i of albmArray
  
set tmpItem2 to contents of item i of songArray
  
set the end of (outList of spdList) to {albumTitle:tmpItem1, songTitle:tmpItem2}
end repeat

★Click Here to Open This Script 

(Visited 43 times, 1 visits today)
Posted in list Record | Tagged 10.11savvy 10.12savvy 10.13savvy 10.14savvy ITLibrary iTunes NSPredicate | Leave a comment

iTunesライブラリ中の楽曲のみしぼりこんでアルバムのtitle一覧を取得

Posted on 12月 22, 2018 by Takaaki Naganoya

iTunesライブラリ(+Apple Book)のメディアから楽曲(mediaKind=ITLibMediaItemMediaKindSong)のみ抽出してアルバムのタイトル一覧を取得するAppleScriptです。

iTunesLibrary.framework経由でメデイアアイテムの情報にアクセスするため、iTunes.appが起動していてもいなくても関係ありません。開発環境のマシン(MacBook Pro Retina 2012 Core i7 2.66GHz)でiTunesに6,871曲の楽曲が存在している状態で0.03秒程度です。

iTunes.appとプロセス間通信していないため、macOS 10.14でSecurityダイアログが表示されることもありません。

AppleScript名:iTunesライブラリ中の楽曲のみしぼりこんでアルバムのtitle一覧を取得.scptd
— Created 2018-10-16 by Takaaki Naganoya
— 2018 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "iTunesLibrary"

property ITLibrary : a reference to current application’s ITLibrary
property NSPredicate : a reference to current application’s NSPredicate

set library to 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())

set aPredicate to NSPredicate’s predicateWithFormat:"self.mediaKind = 2" –ITLibMediaItemMediaKindSong
set filteredArray to gArray’s filteredArrayUsingPredicate:aPredicate
set tArray to (filteredArray’s album’s title)
set bList to (tArray’s valueForKeyPath:"@distinctUnionOfObjects.self") as list
–> {"アニメる", "庄野真代ゴールデン☆ベスト: シングル・コレクション & 筒美京平作品集", "ウォンテッド(指名手配) [Original Cover Art] – Single", "君が人生の時…", "3年B組金八先生 THEME SONG COLLECTION", "HOLD ME", "Piano Stories", "にんじゃりばんばん – Single", …..}

★Click Here to Open This Script 

(Visited 42 times, 2 visits today)
Posted in list | Tagged 10.11savvy 10.12savvy 10.13savvy 10.14savvy ITLibrary iTunes NSPredicate | Leave a comment

iTunesライブラリ中の楽曲のみしぼりこんでtitle取得

Posted on 10月 24, 2018 by Takaaki Naganoya

iTunesライブラリ(+Apple Book)のメディアから楽曲(mediaKind=ITLibMediaItemMediaKindSong)のみ抽出してタイトルを取得するAppleScriptです。

iTunesLibrary.framework経由でメデイアアイテムの情報にアクセスするため、iTunes.appが起動していてもいなくても関係ありません。開発環境のマシン(MacBook Pro Retina 2012 Core i7 2.66GHz)でiTunesに6,871曲の楽曲が存在している状態で0.02秒程度です。

Scriptの末尾で配列の大きさを取得しているのは、タイトルのリストをそのままスクリプトエディタの「結果」欄に出力させると、数千項目にもなる結果データをスクリプトエディタが受信するのに余計に時間がかかるので、ダミーで計算させたものです。

iTunes.appとプロセス間通信していないため、macOS 10.14でSecurityダイアログが表示されることもありません。

AppleScript名:iTunesライブラリ中の楽曲のみしぼりこんでtitle取得.scptd
— Created 2018-10-16 by Takaaki Naganoya
— 2018 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "iTunesLibrary"

property ITLibrary : a reference to current application’s ITLibrary
property NSPredicate : a reference to current application’s NSPredicate

set library to 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())

set aPredicate to NSPredicate’s predicateWithFormat:"self.mediaKind = 2" –ITLibMediaItemMediaKindSong
set filteredArray to gArray’s filteredArrayUsingPredicate:aPredicate
set tList to (filteredArray’s title) as list
–> {"Wait & See~リスク~", "Can You Keep A Secret?", "DISTANCE", "サングラス", "ドラマ", "Eternally", "Addicted To You (UP-IN-HEAVEN-MIX)"…}

set tLen to length of tList
–> 7010

★Click Here to Open This Script 

(Visited 41 times, 1 visits today)
Posted in list | Tagged 10.11savvy 10.12savvy 10.13savvy 10.14savvy ITLibrary iTunes NSPredicate | Leave a comment

iTunesライブラリ中の各trackの種別を集計(media種別)

Posted on 10月 24, 2018 by Takaaki Naganoya

iTunesライブラリ(+Apple Book)のメディアの種別(mediaKind)を集計するAppleScriptです。

iTunesLibrary.framework経由でメデイアアイテムの情報にアクセスするため、iTunes.appが起動していてもいなくても関係ありません。開発環境のマシン(MacBook Pro Retina 2012 Core i7 2.66GHz)でiTunesに6,871曲の楽曲が存在している状態で、集計に0.01秒程度です。

ITMediaItemのmediaKindを取得して種別情報を取り出しました。「楽曲のみ抽出」といった用途にバッチリ向いているようです。

iTunes.appとプロセス間通信していないため、macOS 10.14でSecurityダイアログが表示されることもありません。

AppleScript名:iTunesライブラリ中の各trackの種別を集計(media種別).scptd
— Created 2018-10-16 by Takaaki Naganoya
— 2018 Piyomaru Software
use AppleScript version “2.4”
use scripting additions
use framework “Foundation”
use framework “iTunesLibrary”
(*
ITLibMediaItemMediaKindAlertTone:21
ITLibMediaItemMediaKindAudiobook:5
ITLibMediaItemMediaKindBook:19
ITLibMediaItemMediaKindDigitalBooklet:15
ITLibMediaItemMediaKindHomeVideo:12
ITLibMediaItemMediaKindIOSApplication:16
ITLibMediaItemMediaKindInteractiveBooklet:9
ITLibMediaItemMediaKindMovie:3
ITLibMediaItemMediaKindMusicVideo:7
ITLibMediaItemMediaKindPDFBook:20
ITLibMediaItemMediaKindPDFBooklet:6
ITLibMediaItemMediaKindPodcast:4
ITLibMediaItemMediaKindRingtone:14
ITLibMediaItemMediaKindSong:2
ITLibMediaItemMediaKindTVShow:8
ITLibMediaItemMediaKindUnknown:1
ITLibMediaItemMediaKindVoiceMemo:17
ITLibMediaItemMediaKindiTunesU:18
*)

property NSDictionary : a reference to current application’s NSDictionary
property NSCountedSet : a reference to current application’s NSCountedSet
property NSMutableArray : a reference to current application’s NSMutableArray
property NSSortDescriptor : a reference to current application’s NSSortDescriptor


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 gList to (library’s allMediaItems())’s mediaKind
set aRes to countItemsByItsAppearance(gList) of me
–> {{theName:2, numberOfTimes:7010}, {theName:4, numberOfTimes:1422}, {theName:19, numberOfTimes:57}, {theName:3, numberOfTimes:25}, {theName:12, numberOfTimes:21}, {theName:5, numberOfTimes:5}, {theName:6, numberOfTimes:5}, {theName:7, numberOfTimes:2}, {theName:20, numberOfTimes:1}}


–出現回数で集計
on countItemsByItsAppearance(aList)
  set aSet to NSCountedSet’s alloc()’s initWithArray:aList
set bArray to 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:(NSDictionary’s dictionaryWithObjects:{aValue, (aSet’s countForObject:aValue)} forKeys:{“theName”, “numberOfTimes”})
  end repeat


  –出現回数(numberOfTimes)で降順ソート
set theDesc to NSSortDescriptor’s sortDescriptorWithKey:“numberOfTimes” ascending:false
bArray’s sortUsingDescriptors:{theDesc}


  return bArray as list
end countItemsByItsAppearance


★Click Here to Open This Script 
(Visited 51 times, 1 visits today)
Posted in list | Tagged 10.11savvy 10.12savvy 10.13savvy 10.14savvy ITLibrary iTunes NSCountedSet NSDictionary NSMutableArray NSSortDescriptor | Leave a comment

iTunesライブラリ中の各trackの種別を集計(ファイル種別文字列)

Posted on 10月 24, 2018 by Takaaki Naganoya

iTunesライブラリ(+Apple Book)のメディアの種別(kind)を集計するAppleScriptです。

iTunesLibrary.framework経由でメデイアアイテムの情報にアクセスするため、iTunes.appが起動していてもいなくても関係ありません。開発環境のマシン(MacBook Pro Retina 2012 Core i7 2.66GHz)でiTunesに6,871曲の楽曲が存在している状態で、集計に0.01秒程度です。

ITMediaItemのkindを取得して種別情報を取り出してみたものの、この文字列情報がローカライズされているのと、あくまでファイル属性の情報を返すため、「楽曲のみ抽出」といった用途には向いていません。

iTunes.appとプロセス間通信していないため、macOS 10.14でSecurityダイアログが表示されることもありません。

AppleScript名:iTunesライブラリ中の各trackの種別を集計(ファイル種別文字列).scptd
— Created 2018-10-16 by Takaaki Naganoya
— 2018 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 playLists to library’s allPlaylists()
set gList to (library’s allMediaItems())’s |kind| –kind is *localized*!!
set aRes to countItemsByItsAppearance(gList) of me
–> {{theName:”AAC オーディオファイル”, numberOfTimes:3260}, {theName:”MPEG オーディオファイル”, numberOfTimes:1760}, {theName:”購入した AAC オーディオファイル”, numberOfTimes:1302}, {theName:”保護された AAC オーディオファイル”, numberOfTimes:1102}, {theName:”MPEGオーディオファイル”, numberOfTimes:421}, {theName:”保護された MPEG-4 オーディオストリーム”, numberOfTimes:134}, {theName:”購入したAACオーディオファイル”, numberOfTimes:124}, {theName:missing value, numberOfTimes:111}, {theName:”MPEG オーディオストリーム”, numberOfTimes:88}, {theName:”MPEGオーディオストリーム”, numberOfTimes:40}, {theName:”Apple ロスレス・オーディオファイル”, numberOfTimes:36}, {theName:”QuickTime ムービーファイル”, numberOfTimes:34}, {theName:”保護されたブック”, numberOfTimes:32}, {theName:”AIFF オーディオファイル”, numberOfTimes:21}, {theName:”購入したブック”, numberOfTimes:21}, {theName:”MPEG-4 ビデオファイル”, numberOfTimes:16}, {theName:”保護された MPEG-4 ビデオファイル”, numberOfTimes:12}, {theName:”PDF 書類”, numberOfTimes:6}, {theName:”AACオーディオファイル”, numberOfTimes:5}, {theName:”ブック”, numberOfTimes:4}, {theName:”購入したMPEG-4ビデオファイル”, numberOfTimes:4}, {theName:”インターネットオーディオストリーム”, numberOfTimes:3}, {theName:”購入した MPEG-4 ビデオファイル”, numberOfTimes:3}, {theName:”WAV オーディオファイル”, numberOfTimes:2}, {theName:”iTunes Extras”, numberOfTimes:2}, {theName:”QuickTimeムービーURL”, numberOfTimes:2}, {theName:”QuickTime ムービー URL”, numberOfTimes:1}, {theName:”MPEG-4ビデオファイル”, 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

 

★Click Here to Open This Script 

 

(Visited 51 times, 1 visits today)
Posted in list | Tagged 10.11savvy 10.12savvy 10.13savvy 10.14savvy iTunes NSCountedSet NSDictionary NSMutableArray NSSortDescriptor | Leave a comment

iTunesライブラリ中の各trackのartworkの種別を集計 v2

Posted on 10月 16, 2018 by Takaaki Naganoya

iTunesライブラリ中の各trackのアートワークの画像フォーマットの種別を集計するAppleScriptです。

iTunesライブラリ中の各trackのアートワークの画像フォーマットについては、iTunes.app上で楽曲を何曲か選択状態にした状態で、

tell application "iTunes"
  set aSel to selection
  
–> {file track id 50115 of user playlist id 43242 of source id 65 of application "iTunes"}
  
  
repeat with i in aSel
    set j to contents of i
    
    
set aFormat to (format of artwork 1 of j) as string
    
log aFormat
    
–>   (*JPEG picture*)
  end repeat
end tell

★Click Here to Open This Script 

のように、個別に取り出すことが可能です。

ただし、iTunes内の(数千とか数万)trackすべてについて集計を行いたい、といった場合にiTunes.appに対して問い合わせを行うと、Objective-CだろうがSwiftだろうがAppleScriptだろうが、どの言語を使っても膨大な処理時間がかかります。

そこで、iTunesLibrary.frameworkを介して、iTunesライブラリに直接アクセスしてアートワーク画像の集計を行なってみました。iTunes.appに対して数千個のtrackのアートワークの画像フォーマットを確認していては、処理に何時間かかるかわかりませんが、直接Frameworkの機能を呼び出せば、迅速に処理できます。

開発環境(MacBook Pro 2012 Core i7 2.66GHz)で、iTunesに音楽が6,800曲程度入っている環境で、集計処理に10秒程度かかりました。アートワークにアクセスすると楽曲情報よりも多めに処理時間がかかるようです。

アートワークの種別については、iTunesLibrary.frameworkが定めるところでは9種類ほど画像フォーマットが存在し、自分の環境ではJPEGが多く、PNGもありました。

macOS 10.14でも動かしてみましたが、とくに問題ありません。GUIアプリへの問い合わせではないので、「オートメーション」の許可ダイアログも表示されません。

AppleScript名:各trackのartworkの種別を集計 v2.scptd
— Created 2018-10-16 by Takaaki Naganoya
— 2018 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "iTunesLibrary"

–https://developer.apple.com/documentation/ituneslibrary/itlibartwork/itlibartworkformat?language=objc
property ITLibArtworkFormatNone : 0
property ITLibArtworkFormatBitmap : 1
property ITLibArtworkFormatJPEG : 2
property ITLibArtworkFormatJPEG2000 : 3
property ITLibArtworkFormatGIF : 4
property ITLibArtworkFormatPNG : 5
property ITLibArtworkFormatBMP : 6
property ITLibArtworkFormatTIFF : 7
property ITLibArtworkFormatPICT : 8

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 artwork

set imgFormatArray to gArray’s imageDataFormat

set aRes to countItemsByItsAppearance(imgFormatArray) of me
–>{{theName:2, numberOfTimes:4001}, {theName:missing value, numberOfTimes:2659}, {theName:5, numberOfTimes:1884}}

–出現回数で集計
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

★Click Here to Open This Script 

(Visited 39 times, 1 visits today)
Posted in list System | Tagged 10.11savvy 10.12savvy 10.13savvy 10.14savvy iTunes | Leave a comment

iTunesライブラリの曲名をすべて取得

Posted on 9月 9, 2018 by Takaaki Naganoya

iTunesLibrary.framework経由でiTunesライブラリの曲名をすべて取得するAppleScriptです。

8,500曲の曲名を取得するのにおおよそ1.2秒程度です。

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"

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 title) as list

★Click Here to Open This Script 

(Visited 62 times, 1 visits today)
Posted in list | Tagged 10.11savvy 10.12savvy 10.13savvy ITLibrary iTunes | Leave a comment

SafariとiTunesがアップデート

Posted on 4月 2, 2018 by Takaaki Naganoya

macOS 10.13.4 Releaseに合わせて、macOS 10.12向けにもSafari v11.1とiTunes v12.7.4のアップデートがリリースされました。

大幅な整理と謎の見直しが行われたSafari v11.1

Safari v11.1では過去に例を見ないほどの用語辞書の変更が行われました。ただし、ほとんどが「整理」「清書」に類するものであり、機能的に変更があったということではありません。

これまで、Safariの用語辞書には「Text Suites」という「意味のない予約語」が記載されていました。

これがv11.1では削除されました。削除されても、もともと意味がなかったので問題はありません。

saveコマンドで指定するパスオブジェクトがaliasからfileに変更されていますが、これはもともとfileで指定するものなので、「用語辞書の間違いを直した」といえます。実体が存在しない(保存する前なので)パスのaliasは作れません。

ほかには、AppleScript用語内の細かい表記が修正されています。もともと、macOS 10.5でText, String, Unicode textは統一されているので、あえて用語辞書にUnicode Textと書いておく必要はなかったわけで、それがTextに書き換えられていたりします(説明文が変わっただけで動作に変更はありません)。

あと気になるのは「anything」の表記があることです。あまり多用されてこなかったこの予約語、AppleScriptObjC環境でも「list of string or string」などという表記にならないことを期待したいところです(ScriptDebuggerではこれが「any」などという単語に解釈されてしまうし)。

iTunesには変更なし

iTunes v12.7.4には変更がありません。

(Visited 34 times, 1 visits today)
Posted in 未分類 | Tagged 10.12savvy 10.13savvy iTunes Safari | Leave a comment

エンコーダーの情報を取得する

Posted on 2月 25, 2018 by Takaaki Naganoya
AppleScript名:エンコーダーの情報を取得する
tell application "iTunes"
  set anEncoder to current encoder
  
set aProp to properties of anEncoder
  
–> {class:encoder, id:63, index:1, name:"AAC Encoder"}
  
  
set encList to every encoder
  
–> {encoder id 63 of application "iTunes", encoder id 60 of application "iTunes", encoder id 61 of application "iTunes", encoder id 62 of application "iTunes", encoder id 59 of application "iTunes"}
  
  
set encnameList to name of every encoder
  
–> {"AAC Encoder", "AIFF Encoder", "Lossless Encoder", "MP3 Encoder", "WAV Encoder"}
  
  
set encPropList to properties of every encoder
  
–> {{class:encoder, id:63, index:1, name:"AAC Encoder"}, {class:encoder, id:60, index:2, name:"AIFF Encoder"}, {class:encoder, id:61, index:3, name:"Lossless Encoder"}, {class:encoder, id:62, index:5, name:"MP3 Encoder"}, {class:encoder, id:59, index:6, name:"WAV Encoder"}}
  
end tell

★Click Here to Open This Script 

iTunes Control

(Visited 42 times, 1 visits today)
Posted in System | Tagged 10.11savvy 10.12savvy 10.13savvy iTunes | Leave a comment

iTunesライブラリの場所を取得

Posted on 2月 25, 2018 by Takaaki Naganoya
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 iTunesLibraryLocURL to (library’s musicFolderLocation)’s absoluteString() as string
–>  "file:///Users/me/Music/iTunes/iTunes%20Music/"

set iTunesLibraryLocAlias to (library’s musicFolderLocation) as alias
–>  alias "Cherry:Users:me:Music:iTunes:iTunes Music:"

set iTunesLibraryLocPOSIX to (library’s musicFolderLocation)’s |path|() as string
–>  "/Users/me/Music/iTunes/iTunes Music"

★Click Here to Open This Script 

iTunes Control

(Visited 45 times, 1 visits today)
Posted in file | Tagged 10.11savvy 10.12savvy 10.13savvy ITLibrary iTunes | Leave a comment

iTunesライブラリの曲のアーティスト名を集計

Posted on 2月 25, 2018 by Takaaki Naganoya

iTunesライブラリ中の曲のアーティスト名を集計して、曲数が多い順に集計するAppleScriptです。

アーティスト名のFirst NameとLast Nameの間にスペースが存在している場合としていない場合が(iTunes Music Storeからダウンロード購入した曲でも)混在していたので、こうしたデータのゆらぎに対処しています。

6,827曲のライブラリの集計が、筆者の開発環境(MacBook Pro Retina 2012 Core i7 2.66GHz)で2.7秒ぐらいです。

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:

★Click Here to Open This Script 

iTunes Control

(Visited 33 times, 1 visits today)
Posted in list Record | Tagged 10.11savvy 10.12savvy 10.13savvy ITLibrary iTunes | Leave a comment

Notification

Posted on 2月 8, 2018 by Takaaki Naganoya

macOS 10.10より、標準のScripting環境(スクリプトエディタ)上でCocoa-bridgeが使えるようになったので、Cocoa系のevent(Notification)が使えるようになったことを利用したサンプルです。

AppleScriptは基本的に、アプリケーションの機能や設定値を呼び出すためのもので、ごく一部の限られたアプリケーション以外からは「アプリケーション側からAppleScript(の所定のハンドラ)を呼び出す」方向のイベント呼び出しは利用できませんでした。

しかし、Cocoaのnotificationが利用できるようになったことで、多彩なイベント受信が行えるようになりました。

iTunes(or Music.app)の再生曲変更のnotificationを受信してやたらとTwitterなどに流そうとする入門Scripterがいるのですが(どこかの伝統芸か何かなんだろうか?)、そこはそんなに楽しいとも思えないし、本来のパワーを発揮していないとは思うのですが、見かけたらそっと触れないようにしておくことにしています。

AppleScript名:Notification
— Created 2017-10-13 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"

property NSDistributedNotificationCenter : a reference to current application’s NSDistributedNotificationCenter

on run
  NSDistributedNotificationCenter’s defaultCenter()’s addObserver:me selector:"statusChanged:" |name|:"com.apple.iTunes.playerInfo" object:(missing value)
  
end run

on statusChanged:sender
  tell application id "com.apple.iTunes"
    try
      tell current track
        set anAlbum to album
        
set aName to name
        
set anArtist to album artist
        
set aRating to rating
      end tell
    on error
      return
    end try
  end tell
  
display notification aName
end statusChanged:

★Click Here to Open This Script 

(Visited 79 times, 1 visits today)
Posted in Noification System | Tagged 10.11savvy 10.12savvy 10.13savvy iTunes Music | Leave a comment

iTunesでAirPlayデバイスを指定

Posted on 2月 6, 2018 by Takaaki Naganoya
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

★Click Here to Open This Script 

iTunes Control

(Visited 87 times, 1 visits today)
Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy iTunes | Leave a comment

iTunesライブラリの曲のアーティスト名を集計

Posted on 2月 6, 2018 by Takaaki Naganoya
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:

★Click Here to Open This Script 

iTunes Control

(Visited 29 times, 1 visits today)
Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy ITLibrary iTunes | Leave a comment

iTunesライブラリのファイル種別集計

Posted on 2月 6, 2018 by Takaaki Naganoya
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

★Click Here to Open This Script 

iTunes Control

(Visited 33 times, 1 visits today)
Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy ITLibrary iTunes | Leave a comment

電子書籍(PDF)をオンラインストアで販売中!

Google Search

Popular posts

  • AppleScriptによるWebブラウザ自動操縦ガイド
  • macOS 13, Ventura(継続更新)
  • ドラッグ&ドロップ機能の未来?
  • macOS 12.x上のAppleScriptのトラブルまとめ
  • PFiddlesoft UI Browserが製品終了に
  • macOS 12.3 beta 5、ASの障害が解消される(?)
  • SF Symbolsを名称で指定してPNG画像化
  • 新刊発売:AppleScriptによるWebブラウザ自動操縦ガイド
  • macOS 12.3 beta4、まだ直らないASまわりの障害
  • macOS 12.3上でFinder上で選択中のファイルをそのままオープンできない件
  • Safariで表示中のYouTubeムービーのサムネイル画像を取得
  • macOS 12のスクリプトエディタで、Context Menu機能にバグ
  • Pixelmator Pro v2.4.1で新機能追加+AppleScriptコマンド追加
  • 人類史上初、魔導書の観点から書かれたAppleScript入門書「7つの宝珠」シリーズ開始?!
  • CotEditor v4.1.2でAppleScript系の機能を追加
  • macOS 12.5(21G72)がリリースされた!
  • UI Browserがgithub上でソース公開され、オープンソースに
  • Pages v12に謎のバグ。書類上に11枚しか画像を配置できない→解決
  • 新発売:AppleScriptからSiriを呼び出そう!
  • iWork 12.2がリリースされた

Tags

10.11savvy (1102) 10.12savvy (1243) 10.13savvy (1391) 10.14savvy (586) 10.15savvy (434) 11.0savvy (274) 12.0savvy (174) 13.0savvy (34) CotEditor (60) Finder (47) iTunes (19) Keynote (97) NSAlert (60) NSArray (51) NSBezierPath (18) NSBitmapImageRep (21) NSBundle (20) NSButton (34) NSColor (51) NSDictionary (27) NSFileManager (23) NSFont (18) NSImage (42) NSJSONSerialization (21) NSMutableArray (62) NSMutableDictionary (21) NSPredicate (36) NSRunningApplication (56) NSScreen (30) NSScrollView (22) NSString (118) NSURL (97) NSURLRequest (23) NSUTF8StringEncoding (30) NSUUID (18) NSView (33) NSWorkspace (20) Numbers (55) Pages (36) Safari (41) Script Editor (20) WKUserContentController (21) WKUserScript (20) WKWebView (23) WKWebViewConfiguration (22)

カテゴリー

  • 2D Bin Packing
  • 3D
  • AirDrop
  • AirPlay
  • Animation
  • AppleScript Application on Xcode
  • beta
  • Bluetooth
  • Books
  • boolean
  • bounds
  • Bug
  • Calendar
  • call by reference
  • Clipboard
  • Code Sign
  • Color
  • Custom Class
  • dialog
  • drive
  • exif
  • file
  • File path
  • filter
  • folder
  • Font
  • Font
  • GAME
  • geolocation
  • GUI
  • GUI Scripting
  • Hex
  • History
  • How To
  • iCloud
  • Icon
  • Image
  • Input Method
  • Internet
  • iOS App
  • JavaScript
  • JSON
  • JXA
  • Keychain
  • Keychain
  • Language
  • Library
  • list
  • Locale
  • Machine Learning
  • Map
  • Markdown
  • Menu
  • Metadata
  • MIDI
  • MIME
  • Natural Language Processing
  • Network
  • news
  • Noification
  • Notarization
  • Number
  • Object control
  • OCR
  • OSA
  • PDF
  • Peripheral
  • PRODUCTS
  • QR Code
  • Raw AppleEvent Code
  • Record
  • recursive call
  • regexp
  • Release
  • Remote Control
  • Require Control-Command-R to run
  • REST API
  • Review
  • RTF
  • Sandbox
  • Screen Saver
  • Script Libraries
  • sdef
  • search
  • Security
  • selection
  • shell script
  • Shortcuts Workflow
  • Sort
  • Sound
  • Spellchecker
  • Spotlight
  • SVG
  • System
  • Tag
  • Telephony
  • Text
  • Text to Speech
  • timezone
  • Tools
  • Update
  • URL
  • UTI
  • Web Contents Control
  • WiFi
  • XML
  • XML-RPC
  • イベント(Event)
  • 未分類

アーカイブ

  • 2023年3月
  • 2023年2月
  • 2023年1月
  • 2022年12月
  • 2022年11月
  • 2022年10月
  • 2022年9月
  • 2022年8月
  • 2022年7月
  • 2022年6月
  • 2022年5月
  • 2022年4月
  • 2022年3月
  • 2022年2月
  • 2022年1月
  • 2021年12月
  • 2021年11月
  • 2021年10月
  • 2021年9月
  • 2021年8月
  • 2021年7月
  • 2021年6月
  • 2021年5月
  • 2021年4月
  • 2021年3月
  • 2021年2月
  • 2021年1月
  • 2020年12月
  • 2020年11月
  • 2020年10月
  • 2020年9月
  • 2020年8月
  • 2020年7月
  • 2020年6月
  • 2020年5月
  • 2020年4月
  • 2020年3月
  • 2020年2月
  • 2020年1月
  • 2019年12月
  • 2019年11月
  • 2019年10月
  • 2019年9月
  • 2019年8月
  • 2019年7月
  • 2019年6月
  • 2019年5月
  • 2019年4月
  • 2019年3月
  • 2019年2月
  • 2019年1月
  • 2018年12月
  • 2018年11月
  • 2018年10月
  • 2018年9月
  • 2018年8月
  • 2018年7月
  • 2018年6月
  • 2018年5月
  • 2018年4月
  • 2018年3月
  • 2018年2月

https://piyomarusoft.booth.pm/items/301502

メタ情報

  • 登録
  • ログイン
  • 投稿フィード
  • コメントフィード
  • WordPress.org

Forum Posts

  • 人気のトピック
  • 返信がないトピック

メタ情報

  • 登録
  • ログイン
  • 投稿フィード
  • コメントフィード
  • WordPress.org
Proudly powered by WordPress
Theme: Flint by Star Verte LLC