我有一个AppleScript-ObjC应用程序,该应用程序是沙盒的,并且在尝试获取或设置iTunes轨道属性时遇到了问题。奇怪的是,我可以在使用iTunesTrack对象时成功运行get / set方法,但在处理iTunesFileTrack对象时却无法运行。
示例:
set iTunesAppObject to current application's SBApplication's applicationWithBundleIdentifier_("com.apple.iTunes")
set trackToEdit to iTunesAppObject's currentTrack()
set trackPersistentID to trackToEdit's persistentID()
trackToEdit's setName_("TEST NAME") -- this works, trackToEdit is an iTunesTrack object
-- GET ALL SOURCES FROM ITUNES
set iTunesSources to iTunesAppObject's sources()
-- REPEAT FOR EVERY SOURCE
repeat with aSource in iTunesSources
-- LOOK FOR MAIN LIBRARY SOURCE
if (aSource's |kind|()) is 1.800169826E+9 then
set mainLibrary to aSource
exit repeat
end if
end repeat
set libraryPlaylist to mainLibrary's |libraryPlaylists|() -- GET LIBRARY PLAYLIST
set libraryPlaylist to libraryPlaylist's objectAtIndex_(0)
set allTracksInPlaylist to libraryPlaylist's |fileTracks|() -- GET ALL TRACKS IN PLAYLIST
-- SET UP PREDICATE TO FIND TRACK WITH ID
set searchPredicate to current application's NSPredicate's predicateWithFormat_(("persistentID == " & quoted form of (trackPersistentID as text)))
allTracksInPlaylist's filterUsingPredicate_(searchPredicate) -- FILTER ARRAY
set trackToEdit to allTracksInPlaylist's objectAtIndex_(0) -- GET REMAINING ITEM IN ARRAY, RETURNS iTunesFileTrack OBJECT
log trackToEdit -- returns a seemingly valid iTunesFileTrack object
trackToEdit's setName_("TEST NAME") -- does NOT work, result in sandbox dispatch deny error in Console.app
log trackToEdit's |name|() -- does NOT work, returns null/missing value
当应用程序没有沙盒时,一切正常。我已经为我的项目添加了几乎所有权利,包括:
com.apple.iTunes.library.read-write
com.apple.iTunes.user-interface
com.apple.iTunes.playerInfo
com.apple.iTunes.playback
有人能想出解决这个问题的方法吗?有可能"转换" iTunesFile对象的iTunesFileTrack对象?提前感谢任何建议!
答案 0 :(得分:1)
property aTrack : missing value
on getTrack_(sender)
tell application "iTunes"
set aTrack to (get current track)
end tell
end getTrack_
on renameTrack_(sender)
set name of aTrack to "whatever"
end renameTrack_