ここにいくつかの同様の質問がありますが、NSApplescriptに関係するものはありません。
選択したトラックに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を翻訳する必要があるため、現時点ではオプションではないためです。
どんな助けでも大歓迎です。