Apple script batch shell script

Discussion in 'Mac Programming' started by prramesh, Sep 14, 2013.

  1. prramesh, Sep 14, 2013
    Last edited: Sep 15, 2013

    prramesh macrumors newbie

    Joined:
    Jul 16, 2008
    #1
    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.
     
  2. subsonix macrumors 68040

    Joined:
    Feb 2, 2008
    #2
    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.
     
  3. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #3
    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.
     
  4. prramesh thread starter macrumors newbie

    Joined:
    Jul 16, 2008
    #4
    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
     
  5. subsonix macrumors 68040

    Joined:
    Feb 2, 2008
    #5
    Edit: never mind I missed an ampersand.

    Nice, so you are going to investigate swfrender a bit more?
     
  6. prramesh thread starter macrumors newbie

    Joined:
    Jul 16, 2008
    #6
    found a solution

    yup found the solution; just increase the resolution, here is the best setting that renders the letters very well.
    complete script
     

Share This Page