Application Launch Scripts

auto-launch-script.jpg

I love automating things. One thing I’ve noticed in my 40+ years on earth is that people tend to forget things. Whether it’s taking out the trash, remembering birthdays or starting the video recording at the right time, we forget. I’ve also noticed that computers are pretty good at remembering things. If you tell your computer that it should remind you of something two weeks from now, it will do it. 

Moreover, if you want something done the exact same way every time, well, computers are really good at doing that, too. I started playing around with this a year or so ago when I had an issue with Media Express wouldn’t hold the preference settings properly. It kept dropping back to a different codec and would fail to save the default save directory.

I decided to write an Automator/AppleScript action to launch Media Express, then set the preferences. That took an Automator function called Watch Me Do, which moves the mouse for you. Somehow, that problem magically fixed itself, but it occurred to me that I could automate some other functions of our start up process. 

I re-wrote the startup AppleScript to do the following:

  • Launch the app
  • Switch to Recording mode
  • Enter some parameters in the clip name fields

That seemed pretty easy, and it was. Unfortunately, Media Express is not GUI Scriptable, so I can’t get it to click the little plus signs that actually add the name elements to the clip name (I guess we have to give the video director something to do, right?). 

After that was working really well, it occurred to me that one other issue we have is our capture drive running out of free space. While it’s a 5 TB RAID, we do need to clear it out every so often. While it’s true that I could check it each week, I figured AppleScript could probably do that for me, and it won’t forget.

So I added a few lines to my launch script. After Media Express is launched and the name fields entered, the scrip polls the drive and figures out how much free space is there. If there is more than 300 GB of space open, it pops up a dialog that says everything is fine. If there is less than 300 GB, it alerts the operator that we need to clear off some space. Here is the script: 

tell application "Blackmagic Media Express.app"
activate
end tell
tell application "System Events"
keystroke "1" using command down
--enters record mode
end tell

tell application "System Events"
keystroke tab
keystroke tab
keystroke tab
keystroke tab
keystroke tab
keystroke tab
keystroke tab
--tabs to the correct field
set CurrentDate to month of (current date) & " " & day of (current date) & ", " & year of (current date) as string
--gets current date and puts it in a text format
tell application "System Events" to keystroke CurrentDate
--enters the date string in the field
keystroke tab
--tabs to the next field
tell application "System Events"
tell application "System Events" to keystroke "9 AM"
--enters 9AM in the field (we manually change it to 11AM)
end tell
end tell
tell application "Finder" to set free_bytes to free space of disk "Mac Daddy RAID" -- the number of free bytes left on the disk
set free_Gbytes to (free_bytes / (1024 * 1024 * 0.1024) div 100) / 100
--calculates current free space
if free_Gbytes < 300 then
tell application "SystemUIServer"
activate
display dialog "The Capture Disk is getting full (" & free_Gbytes & " GB of space left). We need to clear off some space. Better get Mike or Jon."
--if free space is less than 300 GB, displays the above alert
end tell
else
tell application "SystemUIServer"
activate
display dialog "Everything's shiny, Cap'n. Have a great weekend!"
--if free space is good, displays this dialog
end tell
end if

As you can see, it’s not a complicated script. I pulled much of the disk calculation code from a forum on AppleScript. The Google is a wonderful tool for figuring this stuff out. 

Now that I have this running on my video capture computer, I’m going to set it up on our audio recorder as well. There’s nothing worse than discovering your drive is full mid-service. Here is a link to the AppleScript if you want it in actual script format. Feel free to use, adapt and modify as you need to.

Today's post is brought to you by Heil Sound. Established in 1966, Heil Sound Ltd. has developed many professional audio innovations over the years, and is currently a world leader in the design and manufacture of large diaphragm dynamic, professional grade microphones for live sound, broadcast and recording.

And by CCI Solutions. With a reputation for excellence, technical expertise and competitive pricing, CCI Solutions has served churches across the US in their media, equipment, design and installation needs for over 35 years.