Posts Tagged ‘AppleScript’

Launch NetBeans when opening files in the MacOS X Finder

I recently switched from Open Komodo to NetBeans 7. What drove me absolutely nuts was the fact that I couldn’t drag and drop files onto the NetBeans application to have them open. Further complicating the issue, NetBeans does not use a standard file browser dialog so you cannot drag and drop onto that either.

Here is my work around. It allows you to drag and drop a single file, or group of files and have them open in NetBeans. I created an application with AppleScript that takes the dropped files and passes them to a shell command that opens netbeans. To use this you must first have NetBeans already launched. I keep this application sitting in my Dock right next the NetBeans icon.

You may need to edit the path to NetBeans if you are using a different version or location

The AppleScript

-- This AppleScript created by John Kramlich of http://www.johnkramlich.com
-- Modify it in anyway you see fit.
return -- not needed, but shows that the script stops here when "run"

on open of finderObjects -- "open" handler triggered by drag'n'drop launches
	repeat with i in (finderObjects) -- in case multiple objects dropped on applet
		
		set mypath to posix_path(i)
		
		do shell script "/Applications/NetBeans/NetBeans\\ 7.0.app/Contents/MacOS/netbeans --open " & mypath
		
	end repeat
	
	tell application "NetBeans 7.0"
		activate
	end tell
	
end open

on posix_path(mac_path)
	set mac_path to (mac_path as text)
	set root to (offset of ":" in mac_path)
	set rootdisk to (characters 1 thru (root - 1) of mac_path)
	tell application "Finder"
		if (disk (rootdisk as string) is the startup disk) then
			set unixpath to "/" & (characters (root + 1) thru end of mac_path)
		else
			set unixpath to "/Volumes:" & mac_path
		end if
	end tell
	set chars to every character of unixpath
	repeat with i from 2 to length of chars
		if item i of chars as text is equal to "/" then
			set item i of chars to ":"
		else if item i of chars as text is equal to ":" then
			set item i of chars to "/"
		else if item i of chars as text is equal to "'" then
			set item i of chars to "\\'"
		else if item i of chars as text is equal to "\"" then
			set item i of chars to "\\" & "\""
		else if item i of chars as text is equal to "*" then
			set item i of chars to "\\*"
		else if item i of chars as text is equal to "?" then
			set item i of chars to "\\?"
		else if item i of chars as text is equal to " " then
			set item i of chars to "\\ "
		else if item i of chars as text is equal to "\\" then
			set item i of chars to "\\\\"
		end if
	end repeat
	return every item of chars as string
end posix_path

The Icon

Download the Files

Batch Exporting Adobe Flash FLAs to QuickTime Movies

I worked on a project with 170 Adobe Flash videos which were published as SWF files.  These files were published prior to FLV becoming the norm, so all video and audio was contained within a each individual SWF.  Programs such as Sothink’s SWF to Video Converter produced output files that had many audio sync issues.

JSFL alone does not allow exporting to QuickTime movies.  The solution was to use a combination of Sothink SWF Decompiler, JSFL, Automator for MacOSX and AppleScript.

Step 1: Getting the content into FLA format

For this I used Sothink SWF Decompiler.  It is available for both Windows and MacOS X.  In this instance I actually used the Windows version because I had a license for it.  Both Mac and Windows versions should have the option to batch an entire folder of SWF files and convert them into FLA.

Step 2: Setting a publish profile

Unfortunately, the publish profile of the decompiled FLA’s was a bit off.  There may be other ways to modify the default publish profile but I found a neat JSFL script from Grant Skinner to batch publish Flash files. I was able to modify it so that it imported a publish profile and then saved the resulting Flash file.  These files were then used for the next batch.  My modifications to his script can be found here.

Step 3: Use MacOS X Automator and AppleScript to export to QuickTime

Apple’s Automator introduced a great new feature titled “Watch Me Do”.  It’s intended to watch you interact with the keyboard and mouse and then be able to play back those actions. The trouble is, it doesn’t capture everything you do.  For everything that it doesn’t capture, we will use AppleScript to fill in the blanks.

Open Automator and create a new Workflow.  Now, launch Adobe Flash and open a few files to work with.  You will need at least 3 files to test the batch capabilities.  Go back into Automator and click the Record button.  Go back into Flash and Select File > Export > Export Movie…

Pick a directory you would like the result to go into and use the default name Flash suggests (If you need to rename the files later I suggest A Better Finder Rename). Click Save and you’ll be presented with the QuickTime Export Settings window like this:

Flash will remember the Export settings and use them for the next file you export.  Make sure you have them set properly and click Export.

Your movie will begin exporting.  Depending on the complexity it could take awhile.  Keep an eye on the clock, you’ll want to know about how long it takes to export your files.

When the export is complete you’ll see a dialog like this:

Automator cannot dimiss this dialog with “Watch Me Do”.  You will need to add a bit of AppleScript to make that work.  You can download my Automator workflow, with the needed AppleScript here.  Please note that you will need to adjust the duration that the workflow pauses for during export.  Many of my movies exported in just under a minute so I set the duration to 2 minutes just to be sure everything would finish before AppleScript attempted to dismiss the confirmation dialog.

Files: