Murga-Projects Forums
Automating Fluid cxx to Lua conversion - Printable Version

+- Murga-Projects Forums (http://www.murga-projects.com/forum)
+-- Forum: Project Forums (/forumdisplay.php?fid=1)
+--- Forum: MurgaLua - General (/forumdisplay.php?fid=2)
+--- Thread: Automating Fluid cxx to Lua conversion (/showthread.php?tid=17)


Automating Fluid cxx to Lua conversion - iGame3D - 05-10-2007 03:32 PM

These first scripts automate the conversion process with AppleScript.
I'd be happy to see different styles/languages and means of doing this.
How do you Windows folks automate command line actions?

Code:
-- a drag and drop applescript to convert fluid .cxx to lua
-- it doesn't handle lists of files or files with spaces in the name

on open (added_items)
    try
        tell application "Finder"
            set oldDelims to AppleScript's text item delimiters -- get normal dilm
            set added_items to added_items as string
            set AppleScript's text item delimiters to "/"
            set folder_Path to "/" & words 2 thru -3 of added_items & "/" as string -- path to cxx file
            set cxx_file to folder_Path & word -2 of added_items & "." & word -1 of added_items as string
            set lua_filename to folder_Path & word -2 of added_items & ".lua" as string
            set AppleScript's text item delimiters to oldDelims
            set shell_Script to "/Library/Scripts/convertFluidToMurgaLua.lua " as string
            set the_command to "murgaLua " & shell_Script & cxx_file & " > " & lua_filename as string
        end tell
        do shell script the_command
    end try
end open


Code:
-- a folder action Applescript for converting the fluid file to lua on saving or adding to the folder
-- folder actions must be enabled and this script attached to a folder
-- updated May 10 2007, now handles multiple files and removes the .h and .cxx files after conversion.

on adding folder items to this_folder after receiving added_items
    try
        tell application "Finder"
            set oldDelims to AppleScript's text item delimiters -- get normal dilm
            set folder_name to POSIX path of this_folder as string -- path to folder
            repeat with i from 1 to the count of added_items
                set cur_file to POSIX path of item i of added_items as string -- path to the file
                set kill_file to item i of added_items as alias
                set AppleScript's text item delimiters to {"."} --sets new dilm
                set file_name to text item 1 of cur_file -- get the name of file without extension
                set the_ext to text item 2 of cur_file -- get the extension    
                set lua_filename to file_name & ".lua"
                set shell_ScriptPath to "/Library/Scripts/convertFluidToMurgaLua.lua "
                set the_command to "murgaLua " & shell_ScriptPath & cur_file & " > " & lua_filename as string
                set AppleScript's text item delimiters to oldDelims -- resets dilm
                if the_ext is "cxx" then do shell script the_command --convert new cxx files to lua
                if the_ext is "cxx" or the_ext is "h" then
                    do shell script ("rm " & cur_file) -- remove new cxx and h files
                end if
            end repeat
        end tell
    end try
end adding folder items to