오늘 나는 iTunes에 앨범 아트 워크를 추가 할 때 실제로 앨범의 일부 트랙에만 추가했음을 알았습니다. 그래서 나는 누구든지 할 일을하고 그것을 바로 잡기위한 스크립트를 작성하려고했습니다.ScriptingBridge를 통해 iTunes 앨범 아트 워크를 설정하려면 어떻게해야합니까?
이것은 약 3 시간의 땜질 후에 첫 시도입니다. 앨범의 모든 노래를 선택했다고 가정합니다.
#! /usr/local/bin/macruby
framework 'Foundation'
framework 'ScriptingBridge'
itunes = SBApplication.applicationWithBundleIdentifier("com.apple.itunes")
tracks = itunes.selection.get
# Find some track with artwork
artwork = tracks.map { |track| track.artworks[0] }.find { |a| a }
raise "No selected song has artwork" if artwork.nil?
# I checked artwork.rawData and it is PNG wrapped in an NSConcreteData.
pngData = artwork.rawData
tracks.each do |track|
if track.artworks[0]
puts "[O] #{track.name}"
else
puts "[X] #{track.name}"
# Adding the same artwork object is apparently NG so we get the data from it
# and make a copy.
# There is probably a more straight-forward way to clone an object but
# artwork.copy raises an exception.
# I have tried using the keys 'data' and 'raw data' instead - same results.
dict = {rawData: pngData}
artwork_copy = itunes.classForScriptingClass('artwork').alloc.initWithProperties(dict)
track.artworks.addObject(artwork_copy)
raise "Didn't actually add the artwork" if track.artworks.empty?
end
end
addObject를 호출하면 예외가 발생하지 않지만, 나는 그것이 실제로 트랙으로 앨범 사진을 추가하지 않는 것으로 나타났습니다 (스크립트를 테스트 속도를 다음 줄에 따라서 확인하시기 바랍니다.)
를저는 ScriptingBridge의 Objective-C 예제에서 주로 작업했으며 다른 사람들이이 작업을 수행 한 곳을 찾을 수 없습니다. 그것을 설정에게 의 작품이지만 놀랍게도 몇을 받고 의 예 많은 ...
다른 사람이 비슷한 문제를했지만, 그들이에 온 적이 어디는 4 년 전에서 흥미로운 메일 링리스트 스레드를 발견했다솔루션 중 하나 (또는 그것을 발견하고 그것을 스레드에 게시하지 않은 경우 악화되었고 그들은 나쁜 사람이고 나쁜 사람입니다.)
그래, 마침내 포기하면 해결 방법으로 AppleScript를 사용하게되었지만 이제는 비밀이 보입니다. :) – Trejkaz
비밀은 [n] 대신에 objectAtIndex (n)를 사용하는 것입니다. 배열은 불변이고 [n]은 항상 nil을 반환하지만 objectAtIndex는 자동으로 객체를 만드는 것처럼 보입니다. (그리고 회상에서 나는 지금 편집에 "나"라고 말하지 말았어야했다. 하하.) – Trejkaz