News : The level of daily SPAM has reached insane proportions, all registrations are now manual. I ask you to send me an e-mail (john (at) murga (dot) org), to confirm that you want me to create an account for you.


Post Reply  Post Thread 
Automating Fluid cxx to Lua conversion
Author Message
iGame3D
Moderator
***


Posts: 231
Group: Moderators
Joined: Apr 2007
Status: Offline
Reputation: 0
Post: #1
Automating Fluid cxx to Lua conversion

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

This post was last modified: 05-11-2007 06:25 AM by iGame3D.

05-10-2007 03:32 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply  Post Thread 

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites

Forum Jump: