The following uses your original gcode sample and my answer in reply #11:
• The script already names the csv
file the same as the gcode
file, although it adds a “[fields]” suffix. That and a file URL can be added before writing to the csv
file by using something like:
set newf to csvFolder & theName & " [fields].csv" -- just save to pre-set folder
set fileURL to ((current application's NSURL's fileURLWithPath:(POSIX path of (imageFolder & theName & ".png")))'s URLByStandardizingPath's absoluteString) as text
set found to {"project_name," & (theName & extension), "image_URL," & fileURL} & found
• By getting the words of an entry like “enable_support = 0” or “nozzle_diameter=0.4”, if the the last word is a number then that word will be the complete number, including the decimal.
• Renaming certain settings can be done in the repeat statement where it is looking for matches to the extractedSettings
, for example a property can be set up with a list of lists for the old and new settings:
property settingRenames : {¬
{"adaptive_pressure_advance_model", "APAM"}, ¬
{"machine_start_gcode", "MSG"}} -- {oldName, newName}
Add a handler for the rename:
to renameSetting(setting) -- rename select settings
repeat with anItem in settingRenames
set {old, new} to anItem
if setting is old then return new
end repeat
return missing value
end renameSetting
And call it where the settings are extracted:
tell (text items of setting) to if second item is in extractedSettings then -- check for setting
set candidate to my renameSetting(second item) -- check for rename
if candidate is not missing value then set second item to candidate
set AppleScript's text item delimiters to "," -- csv separator
set end of found to (rest of it as text) -- add to found list
end if
You still have a few hundred lines to go to pass my Menubar Timer, but try not to get too carried away.