Slic3r droplet for OSX May 02, 2013 05:57AM |
Registered: 11 years ago Posts: 126 |
-- Slic3r batch script by Thinkyhead -- Version 1.0 (May 2, 2013) -- Drop an STL onto this, choose a config file, and wait on open filelist set slic3rMac to path to application "Slic3r" set slic3rHome to cut_off(slic3rMac as string, ":") tell application "Slic3r" to quit set theConfig to choose file with prompt ¬ "Choose a Slic3r config file" of type {"public.plain-text"} ¬ default location (slic3rHome as alias) ¬ with multiple selections allowed set sliceScript to POSIX path of (path to resource "slice.sh") repeat with stl in filelist do shell script sliceScript & " \"" & POSIX path of slic3rHome & "\" \"" & POSIX path of stl & "\" \"" & POSIX path of theConfig & "\"" end repeat beep delay 3 tell application "Slic3r" to quit end open on cut_off(the_string, delimiter) set old_delims to AppleScript's text item delimiters set AppleScript's text item delimiters to delimiter set temp_list to reverse of (every text item of the_string) try if item 1 of temp_list = "" then set temp_list to rest of temp_list end if end try if (count temp_list) < 2 then set AppleScript's text item delimiters to old_delims error "There is nothing to cut off in handler “cut_off”. String: “" & ¬ the_string & "”, delimiter: “" & delimiter & "”." end if set temp_list to rest of temp_list set temp_list to reverse of temp_list -- next makes sure the delimiter as added at end copy "" to end of temp_list set r to (temp_list as text) set AppleScript's text item delimiters to old_delims return r end cut_off
#!/bin/bash # # slice.sh helper script # Version 1.0 by Thinkyhead (May 2, 2013) # # This needs to live in DoSlice.app/Contents/Resources # SLICER_HOME=$1 SLICER=$SLICER_HOME/Slic3r.app/Contents/MacOS/slic3r if [ $# -lt 3 ]; then INCONFIG=$SLICER_HOME/config.ini else INCONFIG=$3 fi CONFIG=`basename "$INCONFIG" | sed -E 's/^config-?|\.ini$//g'` OUTNAME=${2/.stl/} if [ "$CONFIG" != "" ]; then OUTNAME="$OUTNAME-$CONFIG" fi $SLICER "$2" --load "$3" --output "$OUTNAME.gcode"
Re: Slic3r droplet for OSX May 11, 2013 10:44PM |
Registered: 11 years ago Posts: 126 |
-- Slic3r batch script by Thinkyhead -- Version 1.1 (May 10, 2013) -- Drop an STL onto this, choose a config file, and wait on open fileList set slic3rMac to ApplicationAlias("Slic3r") set slic3rHome to posix_dirname(slic3rMac) set theConfig to choose file with prompt "Choose a Slic3r config file" of type {"public.plain-text"} default location (POSIX file slic3rHome) without invisibles set SLICER to (POSIX path of slic3rMac) & "Contents/MacOS/slic3r" set CONFIG to regex(posix_basename(theConfig), "^config-?|\\.ini$", "") set filesDone to 0 set totalFiles to count fileList repeat with stl in fileList --set perc to (filesDone * 100 / totalFiles) as integer --display dialog "Slicing " & filesDone & " of " & totalFiles & " (" & perc & "%)" giving up after 1 with icon note set stlPath to POSIX path of stl if stlPath ends with ".stl" then set OUTNAME to regex(stlPath, "\\.stl", "") if not CONFIG = "" then set OUTNAME to OUTNAME & "-" & CONFIG do shell script quoted form of SLICER & ¬ " " & quoted form of stlPath & ¬ " --load " & quoted form of POSIX path of theConfig & ¬ " --output " & quoted form of (OUTNAME & ".g") set filesDone to filesDone + 1 end if end repeat beep set lingerTime to 5 set timestamp1 to (do shell script "date +%s") as integer display dialog "Done slicing " & filesDone & " objects!" giving up after lingerTime with icon note set timestamp2 to (do shell script "date +%s") as integer set leftover to lingerTime - (timestamp2 - timestamp1) if leftover < 0.5 then set leftover to 0.5 repeat leftover * 2 times if application "Slic3r" is running then tell application "Slic3r" to quit quit end if delay 0.5 end repeat end open on ApplicationAlias(appName) set lsRegisterPath to "/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister" set theAppPaths to paragraphs of (do shell script lsRegisterPath & " -dump | grep \"path:\" | grep \"" & appName & "\" | sed -E 's/.*path:[ ]+//g'") set shortestPath to "" repeat with appPath in theAppPaths if shortestPath is "" or appPath's length is less than shortestPath's length then set shortestPath to appPath as string end if end repeat return POSIX file shortestPath as alias end ApplicationAlias on regex(the_string, search_string, replace_string) return do shell script "echo " & quoted form of the_string & " | sed -E " & quoted form of ("s/" & search_string & "/" & replace_string & "/g") end regex on posix_basename(posix_path) return do shell script "basename " & quoted form of path_of(posix_path) end posix_basename on posix_dirname(posix_path) return do shell script "dirname " & quoted form of path_of(posix_path) end posix_dirname on path_of(path_or_item) if class of path_or_item is alias then return POSIX path of path_or_item end if return path_or_item end path_of