AppleScript名:AIFFをM4aに変換する |
— Created 2016-10-24 by Shane Stanley use AppleScript version "2.4" use framework "Foundation" use framework "AVFoundation" use scripting additions set posixPath to POSIX path of (choose file with prompt "Choose an AIFF file:" of type {"public.aifc-audio"}) my convertAIFFToM4aAt:posixPath deleteOriginal:false on convertAIFFToM4aAt:posixPath deleteOriginal:deleteFlag set theURL to current application’s |NSURL|’s fileURLWithPath:posixPath — set destination to use same path, different extension set destURL to theURL’s URLByDeletingPathExtension()’s URLByAppendingPathExtension:"m4a" set theAsset to current application’s AVAsset’s assetWithURL:theURL — check asset can be converted set allowedPresets to current application’s AVAssetExportSession’s exportPresetsCompatibleWithAsset:theAsset if (allowedPresets’s containsObject:(current application’s AVAssetExportPresetAppleM4A)) as boolean is false then error "Can’t export this file as an .m4a file." end if — set up export session set theSession to current application’s AVAssetExportSession’s exportSessionWithAsset:theAsset presetName:(current application’s AVAssetExportPresetAppleM4A) theSession’s setOutputFileType:(current application’s AVFileTypeAppleM4A) theSession’s setOutputURL:destURL — begin export and poll for completion theSession’s exportAsynchronouslyWithCompletionHandler:(missing value) repeat set theStatus to theSession’s status() as integer if theStatus < 3 then delay 0.2 else exit repeat end if end repeat — throw error if it failed if theStatus = (current application’s AVAssetExportSessionStatusFailed) as integer then error (theSession’s |error|()’s localizedDescription() as text) end if — delete original if required if deleteFlag then current application’s NSFileManager’s defaultManager()’s removeItemAtURL:theURL |error|:(missing value) end if end convertAIFFToM4aAt:deleteOriginal: |
More from my site
(Visited 37 times, 1 visits today)