1

我有一个 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

谁能想到解决这个问题的方法?是否可以将 iTunesFileTrack 对象“转换”为 iTunesTrack 对象?在此先感谢您的任何建议!

4

1 回答 1

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_
于 2014-08-13T19:00:54.107 回答