Last active
April 21, 2018 08:57
-
-
Save mikan-megane/bb711352bf3b315a48eb0041f9a73d14 to your computer and use it in GitHub Desktop.
プレイリスト名をコメントに入れる奴
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=== 注意 == | |
これはみかんのめがねが自分用として作ったスクリプトです。 | |
何があっても、コメントが全部消えるとかiTunesライブラリが壊れたとか有っても一切責任は取りませんのでご注意を。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Playlist2Comment | |
-- autor: @mikan_megane | |
-- 停止を押してもかなりオーバーランするので注意 | |
tell application "iTunes" | |
set FirstRun to true | |
set vPlaylistCount to 0 | |
set vErrorCount to 0 | |
repeat with vPlaylist in user playlists | |
set vPlaylistCount to (vPlaylistCount + 1) | |
if (count track of vPlaylist) > 0 then | |
set vPlaylistName to parentPlaylist(vPlaylist) of me & (get name of vPlaylist) | |
init((count track of vPlaylist), vPlaylistName, vPlaylistCount & " of " & (count user playlist)) of cProgress | |
repeat with vTrack in tracks of vPlaylist | |
incriment(vErrorCount) of cProgress | |
try | |
if FirstRun then | |
set comment of vTrack to (strpos(get comment of vTrack, return & "$$PlayList$$") of me & return & "$$PlayList$$") | |
else | |
set comment of vTrack to ((get comment of vTrack) & return & vPlaylistName & ",") | |
end if | |
on error | |
log ("Error in" & vPlaylistName & ":" & (get name of vTrack)) | |
set vErrorCount to (vErrorCount + 1) | |
end try | |
end repeat | |
set FirstRun to false | |
end if | |
end repeat | |
end tell | |
-- プレイリストフォルダ名を返す | |
-- in : playlist | |
-- out: String | |
on parentPlaylist(vPlaylist) | |
tell application "iTunes" | |
try | |
return (parentPlaylist(parent of vPlaylist) of me) & (get name of parent of vPlaylist) & "/" | |
end try | |
return "" | |
end tell | |
end parentPlaylist | |
-- HaystackをNeedleが最後に発見された所まで返す | |
-- in1: String 検索したい元の文章 | |
-- in2: String 分割したい文字列 | |
-- out: String | |
on strpos(Haystack, Needle) | |
set tmp to AppleScript's text item delimiters | |
set AppleScript's text item delimiters to Needle | |
try | |
set BeforeNeedle to text from text item 1 to text item -2 of Haystack | |
on error | |
set BeforeNeedle to Haystack | |
end try | |
set AppleScript's text item delimiters to tmp | |
return BeforeNeedle | |
end strpos | |
script cProgress | |
property total_ : 0 | |
property process_ : "" | |
on init(vTotal, vProcess, vCount) | |
set progress total steps to vTotal | |
set progress completed steps to 0 | |
set progress description to "Processing " & vProcess & "... " & vCount | |
set progress additional description to "Preparing to process." | |
set total_ to vTotal | |
set process_ to vProcess | |
end init | |
on incriment(vErrorCount) | |
set progress completed steps to (progress completed steps + 1) | |
set progress additional description to ("Processing " & process_ & " " & progress completed steps & " of " & total_ & "(Error " & vErrorCount & ")") | |
end incriment | |
end script |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/mikan-megane/7f6218ebe7162214f0976efac8ef4cd3
こちらの方が新しいのでこれを使う意味はあんまり無いです