Automating batch export of large projects from GarageBand 6.0.5

I have a need to export chapter-length audio from Gargeband projects. These are chapters from audiobooks that can sometimes be a few minutes up to an hour, and there can be as few as a couple to as many as 30 in a single book.

I’ll say, I’m no AppleScript expert (and I’ve gotten worse over the years, actually), but I’ve managed to cobble together from various examples something that sort of does what I need. Since GB has anemic AppleScript support, some of this happens via assistive access.

Here’s the code.

on open drop_items
	
	repeat with i from 1 to the count of drop_items
		
		set this_item to item i of drop_items
		set the this_info to info for this_item
		tell application "GarageBand 6.0.5"
			activate
			open this_item
			delay 1
			
			tell application "System Events"
				
				tell process "GarageBand"
					
					click menu item "Export Song to Disk..." of menu "Share" of menu bar 1
					delay 1
					click button "Export" of sheet 1 of window 1
					delay 1
					click button "Save" of window "Export to Disk"
					
					delay 1
					set replace_button to (a reference to (first button whose name is "Replace") of sheet 1 of window "Export to Disk")
					if replace_button exists then
						click replace_button
					end if
					
					
				end tell -- Process "GarageBand"
				
			end tell -- System Events
			
			close window named (name of this_info) saving no
			
		end tell -- GarageBand
		
	end repeat -- Repeat
	
end open

As I said, it sort of works.
Caveats:

  1. GB has to be open already. Not great, but not the end of the world.
  2. Nothing in the script after the export begins processes… no closing windows-without-save, etc.
  3. I can’t process more than one file at a time via the droplet app I exported.

What I’d like is…

  1. Open GB if not open. (Again, not end of world if it doesn’t.)
  2. Process more than one file, e.g., close previous file and open next that was dropped on droplet. Or if that’s not possible…
  3. Beep/message/whatever on completion of export(s).

I’ve tried lots of things, but I plain don’t understand this assistive stuff very well. Nor probably AppleScript as well as I need to.

Using Mavericks. (Not 10.8 as the un-updated popup below will suggest).

Thanks for any suggestions and help!!

Model: Late 2011 15" Macbook Pro
Browser: Safari 537.71
Operating System: Mac OS X (10.8)

Nobody? :frowning:

Hi manwich,

I don’t have a solution, because I myself began really trying to use GarageBand a couple of days before you posted. I have a question though. Are you planning to save the opened audio chapter in a certain format?

gl,
kel

I will always save the files as 192 Kbit MP3.

Hi manwich,

So, you have your GarageBand Set to export as mp3. What is the format of the audio files? What I don’t understand is if you have the audio files (I assume it’s mp3), then why are you loading it into GarageBand and exporting as mp3. You could just duplicate the file. I’m guessing that the input files aren’t mp3. Actually, I’m mixed up about what you’re trying to do.

Edited: also, which setting is mp3: low, medium, high, or highest? or is it set in iTunes?

gl,
kel

The files come in as MP3, WAV and AIFF formats, sometimes stereo, sometimes mono. Our distribution requires two sets of output files, 192 and 96 Kbit mono files. The narrators are not always the same. I have GB 6.0.5 settings to normalize and filter their individual voices and unique studio noise to our standards. Furthermore, the narrators aren’t perfect. While some are high-grade amateurs, and some are pros, I almost always have to trim out long pauses, fix repeats from punch ins they missed, and sometimes have them correct mispronunciations and deviations from the scripts. Standard work for spoken-word audio voiced by remote narrators (e.g., not in my studio or under my direction.)

So yes, if I could do something as simple as duplicate the files, I’d have already discarded GB long ago. As it is, Apple will eventually force me to move to Logic Pro since the new GB for Mavericks is basically unusable in my workflow (no podcasting/spoken word controls.) In fact, GB 7 (and all the new iWork and iLife apps) is essentially an iPad app.

At least maybe Logic Pro is scriptable. GB 7 has no Applescript support. GB 6 is partially scriptable.

I use the command Export Podcast to Disk with Custom settings.

Hi manwich,

I see now. Apple changed GB in Mavericks. It’s less versatile now with GB 10.0.1.

If you have Xcode, then you can use the Accessibility Inspector. It will help you to use System Events ui scirpting. Part of your code is wrong in the menu bar part. There should be 2 menu bar 1 calls I think. It’s hard with twoo different systems.

I’ll try to make a script in my system for saving the file, but it’s two different systems. Maybe you can try to adjust it to your system if it can be done.

Hope you find your answer,
kel

Hi manwich,

Here’s a script that saves the already loaded file in GarageBand to my current settings to a location setting in GarageBand. Things are very different in my system, but ma bye you can adjust it.

--set f to choose file
tell application "GarageBand"
	launch
	activate
	--open f
end tell
tell application "System Events"
	tell process "GarageBand"
		tell menu bar 1
			tell menu bar item "Share"
				tell menu "Share"
					tell menu item "Export Song to Disk..."
						click
					end tell
				end tell
			end tell
		end tell
	end tell
	delay 1
	keystroke return
end tell

gl,
kel

Thanks! I finally got back to this today since I’m facing down a 20-chapter book.

I was able to take what you posted, add to it a bit, and embed it into an Automator workflow that does exactly what I need - open a sequence of GB files, export them one by one, close the previous and repeat. Automator doesn’t handle loops very well, but a 3rd-party addition to it allows it to handle them better.

What I added into my Automator flow. The “replace” bit doesn’t work, but it was only for testing. My normal workflow won’t be encountering a need to replace existing files.

on run {input, parameters}
	tell application "System Events"
		tell process "GarageBand"
			tell menu bar 1
				tell menu bar item "Share"
					tell menu "Share"
						tell menu item "Export Song to Disk..."
							click
							keystroke return
							delay 1
							keystroke return
							
							if exists sheet 1 of window 1 then
								click button "Replace" of sheet 1
							end if
						end tell
					end tell
				end tell
			end tell
		end tell
	end tell
end run

-Marc

Spoke too soon. The Export file to Disk process can take a long time for these files. Sometime during the Mix-down/Normalize/Convert functions, the rest of the script - or perhaps the Automator actions - continues on and the workflow fails.

I need some way in the script to check for the presence of the sheets (?) with the progress bars that say creating mix down, Normailizing, and Converting. If they exist, delay the continuation of the script for some time and then check again, looping that until the sheets are gone.

Not sure if that’s possible, but I’ve tried inserting lines like

if exists sheet 1 of window 1 then
delay 600

…to no avail.

I’m out of my depth.

For the record: Logic Pro X isn’t scriptable either.

I noticed that yesterday. :frowning:

You could use GUI scripting since Logic Pro X is the first version of Logic written in Cocoa. For editing wave files I was always very fond of soundtrack.app. This application shipped with Logic and Final Cut, but doesn’t with today’s versions.

If you’re all doing this for editing wave (or any kind of audio ) files I would take a look into audacity. Have worked with it some years ago and for free software it’s (was) pretty good.