這裏有一些相似的問題,但沒有涉及NSApplescript。如何在Xcode中使用NSApplescript將藝術品設置爲iTunes歌曲?
我試圖iTunes插圖添加到選定的曲目,我的代碼是:
set newFile to add aFileName as POSIX file to ipod_lib
set current_track to newFile
set jpegFilename to ":temp:artwork.jpg" as string
set data of artwork 1 of current_track to (read (file jpegFilename) as picture)
tell current_track
set name to "Song Name" as string
set artist to "Custom Artist" as string
set album to "Custom Album" as string
set year to "2011" as string
set track number to "1" as number
set track count to "38" as number
end tell
凡aFileName是一個mp3的路徑。 我正在使用Script Debugger 4.5測試它,它工作正常,但是當我將代碼複製到我的Xcode項目並運行它時,不會將其他元數據設置爲藝術作品。 但如果我評論的「設置藝術作品的數據。」行,則它設置其他元數據(名稱,藝術家等)
我的Xcode的代碼是:
NSString *scriptote = @"with timeout of 600 seconds\n"
"tell application \"iTunes\"\n"
...
"set newFile to add aFileName as POSIX file to ipod_lib\n"
"set current_track to newFile\n"
"set jpegFilename to \":temp:artwork.jpg\" as string\n"
// If a comment the following line, everything else works, if I left this line, no meta data is set.
"set data of artwork 1 of current_track to (read (file jpegFilename) as picture)\n"
"tell current_track\n"
"set name to \"Song Name\" as string\n"
"set artist to \"Custom Artist\" as string\n"
"set album to \"Custom Album\" as string\n"
"set year to \"2011\" as string\n"
"set track number to \"1\" as number\n"
"set track count to \"38\" as number\n"
"end tell\n"
...
;
if ((ascript = [[NSAppleScript alloc] initWithSource:scriptote])) {
status = [[ascript executeAndReturnError:&errorInfo] stringValue];
if (!errorInfo) {
// do something
NSLog(@"NO Error");
} else {
// process errors
// NSRange errorRange = [[errorInfo objectForKey:@"NSAppleScriptErrorRange"] rangeValue];
NSLog(@"Error\n Error line: ");
}
[ascript release];
}
我一直谷歌搜索了很多小時,但沒有運氣。 我不想使用ScriptBridge框架,因爲我需要翻譯大量的applescript,所以它現在不適合我。
任何幫助將不勝感激。
謝謝你謝謝你謝謝你。 – roocell