Run command-line from JSFL

This is a somewhat old topic born with the original FLfile library by Guy Watson: the undocumented runCommandLine JSFL command, which still exists in FLfile. Previously we had FLappleScript, but it stopped working some time before runCommandLine was available for us in the Mac (IIRC).

If you are new to this, you may be shocked when you type and run this in a new “Flash JavaScript File” document:

FLfile.runCommandLine("echo 'ok' > /tmp/sample.txt;open /tmp/sample.txt");
// works in Mac, use your windows' shell knowledge if you use Win

Or this one:

FLfile.runCommandLine("osascript -e 'tell app \"iTunes\" to playpause'");

These are stupid examples, but I have a couple of interesting projects using a mix of various technologies, including JSFL and Flash, AppleScript, the shell and Illustrator, etc., which is a very promiscuous mode of scripting, but very funny and inedited for many people.

This command only returns (I think) the exit status (1 or 0), but still there is a bunch of ways to get your data (such as writing it to tmp files and reading them from JSFL using FLfile.read())

Advertisement

WindowSWF, mix ActionScript and JSFL for automation and productivity

It’s a long title for a post which could, in fact, be the only message without extra ellaboration. But I’ll ellaborate a bit, because I think this is a underrated feature I love in Flash, which allows to the end-user a full experience of automation and high detail customization of the Flash IDE. This post is for those of you who don’t know about it.

You can create a UI in Flash/ActionScript, link it with JSFL (Javascript Flash, a javascript-based language to drive the Flash IDE) and create your own utilities panel with customized solutions for your daily work. Such as this:

windowswf

I use every day the buttons in this panel. The first button in the top-left corner, for example, will convert selected items in the stage to named movie clips. It’s a silly task, but some times, before I worked out this solution, I was forced to do it manually hundreds of times in a single day (!) –> select, F8, insert name for symbol, insert name for instance in the stage.

My most impressive automation task was one responsible of arranging, making certains changes and publishing thousands of FLA files in a row, which reduced various workdays to 20 or 30 minutes I could spend in a delicious capuccino while the machine was working by itself.

This isn’t a guide, so I’ll describe briefly the mechanism:

1. You have some need (usually automation of repetitive tasks in the Flash IDE).
2. You write a JSFL command in order to replicate what you use to do manually –> most of times *any* task can be duplicated via JSFL. If you don’t believe it, create a new document, make a rectangle, group it, then go to the menu Window > Other Panels > History. Everything listed in there is pure JSFL recorded which you can copy to the clipboard. More complex tasks will require heavy tweaks, though 😉
3. You create a FLA file with a button (or buttons, progress bars or whatever) linking to the JSFL command. Usually, JSFL commands are stored in the “Commands” folder of Flash’ main configuration dir and can be accesed as well from the Commands menu. You can even assign them a shortcut. But sometimes you run out of shortcuts or you can’t remember more shortcuts (!). This is the time when you need to create your own toolbar with that bunch of customized daily tasks. You call the JSFL command from ActionScript as follow:

myButton.onRelease=function(){
	MMExecute('fl.runScript(fl.configURI + "Commands/selec-to-movies.jsfl");');
}

This example is using AS 2 syntax, but that isn’t a problem, very simple to port it to AS 3. Basically, you call the ActionScript method of the same name, which executes JSFL code. This method is *only* available to “WindowSWF” panels, XMLtoUI dialogs (created on the fly usually by JSFL commands, that is another topic) or UI components. Obviously, no sense out of the Adobe Flash IDE.
4. Move the resulting SWF file to the WindowSWF folder of the config folder (next to Commands, Components, etc.).
5. Relaunch Flash. Now you can access your brand new panel from the menu Window > Other Panels, and it will behave just like any other utilities panel (more or less, you will learn some tiny details when you do it real).

And that’s all. Even if you don’t write your own JSFL solutions, you can still create a WindowSWF panel and link it to others’ JSFL commands you can find in Adobe’s Exchange web site.

FLA to PNG via AppleScript plus JSFL

We use this as a droplet, so we can convert dropped FLA files to PNG in a shot. The original script is much larger, as PNG files are post-processed before using them (need some tweaks in GraphicConverter or a similar apple-scriptable app), but it is a skeleton you can use in many little automation projects involving the wonderful world of AppleScript and Flash Javascript (aka JSFL), the language used to automate and extend the Flash IDE capabilities.

AppleScript --> FLA to PNG

AppleScript --> FLA to PNG (click to enlarge)

The FLA file will be exported as PNG using the last settings you used to export a PNG file.

You can download it here.