(Oddly, putting in an error handler to catch the errors and prevent it from halting the script also seemed to prevent the properties from being set. If any one of the tracks are still locked, it'll cause the script-and the workflow-to throw an error. If the file tracks are all unlocked by this point, it'll do it beautifully. Inserting a pause into the workflow of 5 seconds gave the files sufficient time to be unlocked on my system, before proceeding to the final AppleScript.Īs per your request, this AppleScript's only job is to use the part of the filename that comes before the underscore ( "_") to name the album, and that's what it does. The duration will vary from system to system, and probably on the number of files imported as well. During this time, setting any properties of the new imported tracks is not possible, and results in a "File permissions error". Here's the annoying bit: it seems that when iTunes imports new files into its library, it temporarily places a lock on the files, presumably as the files are copied across, the files scanned, and the metadata are written. They get sent straight to the library, and end up in the audiobooks section. the audiobook files, and imports them into iTunes without doing any further conversions. The workflow retrieves the contents of this directory, i.e. The shell script returns the path to the "Audio" directory, now populated with audiobook files. m4b file extension is that, when it's imported into iTunes, it's instantly recognised as being an audiobook, and placed in the audiobooks section. m4b extension tells macOS that the audio file is an iTunes audiobook (other ones Apple uses are.
#HOW TO SET UP OF CANCEL KEY ON AUTOMATOR MAC MP4#
m4b, which may seem unfamiliar, but is essentially an aac file encapsulated in an mp4 wrapper, with the file extension altered in line with Apple's recommendations. The data format used for the audio files is aac, which avoids having to do a second conversion in iTunes later. I selected a voice for it that speaks Mandarin ("Sin-ji"). Otherwise, the command line tool say is used to convert the contents of each file to a spoken audio track. Then it loops through every file in the supplied folder. The shell script navigates into the supplied folder and creates a subfolder called "Audio", in which the audio files will be saved. Its contents is retrieved, which provides the workflow with a list of files inside the folder. You can also assign a keyboard shortcut to it. This workflow is designed to operate as a service in Finder, which will let you select a folder, right-click, and run the workflow from the pop-up context menu. The two scripts (shell script and AppleScript) are reproduced at the bottom of this answer for simple copy-n-pasting, but the content of each is fully visible in the screenshot. Here's a screenshot of the Automator workflow I came up with, which I believe addresses all of your needs and wants: I feel this particular problem is more well suited to bash scripting than AppleScripting overall, given the sheer number of files you'll be dealing with, and the need to convert their contents to spoken audio.