• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Running a service
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Running a service


  • Subject: Re: Running a service
  • From: Shane Stanley <email@hidden>
  • Date: Mon, 24 Oct 2016 11:04:59 +1100

On 23 Oct. 2016, at 3:39 am, Jeremy Roussak <email@hidden> wrote:

I have a load of files which are in AIFF-C audio format, which is good for my home audio system. I need to convert them to .m4a files

You can do it without resort to services or Automator. You'll need to be running 10.10 or later:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use framework "AVFoundation"
use scripting additions

set posixPath to POSIX path of (choose file with prompt "Choose an AIFF file:")
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:

-- 
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>, <latenightsw.com>


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Running a service
      • From: Jeremy Roussak <email@hidden>
References: 
 >Running a service (From: Jeremy Roussak <email@hidden>)

  • Prev by Date: Re: Running a service
  • Next by Date: Script Editor hangs on launch
  • Previous by thread: Re: Running a service
  • Next by thread: Re: Running a service
  • Index(es):
    • Date
    • Thread