Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

prramesh

macrumors newbie
Original poster
Jul 16, 2008
28
0
I have the following command line that does the conversion of swf file (single page) to png
Code:
$ swfrender file01.swf -o output3.png

I have more than hundred files (file01 to file 143.swf) to convert them into png. Since swfrender doesn't support batch conversion, I'm thinking to use applescript. I spent some time to learn applescript, but I couldn't do this in time.

I tried something like this
Code:
set filePath to "~/Downloads/test/"
tell application "Finder"
	set theFile to selection
	try
		do shell script "swfrender file01.swf -o output.png"
	end try
end tell

It will be great if you could help to get a working script.
 
Last edited:
You need to loop over the entire folder and for each file store the name in a variable and replace the file extension before you call the swfrender command.

IMO this is much easier to do in the terminal and since you already use "do shell script" you may as well do everything in shell script, again in my opinion. If you change directory to the one with the files in it you can try this line:

Code:
for i in * ; do echo "$i" "${i%.*}.png" ; done

This will just print the result so you can test that it does what you want. Perhaps someone else will give you an Applescript solution.
 
Look at Automator instead of AppleScript.

First, it has good drag-and-drop support. Second, it has a clearer Run Shell Script than AppleScript does.

Launch Automator. Choose an Application new document, then type "shell" into the Find box for Actions at left. Drag the "Run Shell Script" step out. Finally, choose the "Pass input: as arguments" option. You'll see a model shell script: a for/do/done loop. Save it as-is, and try running it by dragging image-files onto it. Observe the output. Think about what you see in the output relates to what you want to accomplish.

Once you have the basic Automator thing working, post a few lines of its output. We can then advise you about additional shell commands to put in the loop that do things like replacing the file extension, running the conversion command, and so on.

You can also search the web for examples of Automator's Run Shell Script loops.
 
found applescript

thanks a lot for your help, I found a applescript that does the job in loop for the given folder. It took more than half day to figure out right script, but I can't use this now as swfrender produces low quality png files (I can't read texts), here is the script
set theFolder to POSIX path of (choose folder with prompt "Choose Folder containing .swf files")
set theFolderList to list folder theFolder without invisibles

repeat with x from 1 to count of theFolderList
set theFile to theFolder & item x of theFolderList
set theNewFile to theFolder & theFile
try
do shell script "/opt/local/bin/swfrender " & theFile & " -o " & theFile & "output.png"
end try
end repeat
 
Edit: never mind I missed an ampersand.

Nice, so you are going to investigate swfrender a bit more?
 
found a solution

Edit: never mind I missed an ampersand.

Nice, so you are going to investigate swfrender a bit more?

yup found the solution; just increase the resolution, here is the best setting that renders the letters very well.
swfrender -X 3840 file.swf -o output_3840.png

complete script
set theFolder to POSIX path of (choose folder with prompt "Choose Folder containing .swf files")
set theFolderList to list folder theFolder without invisibles

repeat with x from 1 to count of theFolderList
set theFile to theFolder & item x of theFolderList
set theNewFile to theFolder & theFile
try
do shell script "/opt/local/bin/swfrender " & theFile & " -X 3840 -o " & theFile & "output.png"
end try
end repeat
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.