No tip process provided or expected. This is a community of international volunteers, not Apple employees.
I decided to clean up my script code from the previous post. An array of the processed files that went into the archive, is now passed to AppleScript in the shell function. These files appear in the completion dialog as a reminder of what went into the Desktop archive. Do to the increased script size, I only screen captured the Run Shell Script portion of the original Automator workflow. The new script code follows this screen shot, and should replace what I posted earlier in the Do Shell Script Automator action.
I am looking into changing this into a Folder Action, so that the act of your application saving into the Gerber folder, would automatically trigger processing, without the current interactive component requiring you to specify the folder.
This script has some limitations. If you do not clear files from the folder that the application saves too, the script is unaware of processing history, and will grab the first eight documents found, which could include new and processed files in the resultant archive. This would be an issue with a folder action as well. May need more information about frequency and possibly checking creation dates.
Here is todayâs revision screen shot.
Code
# if testing in Terminal, supplied folder name must have relative "~" or
# full path name. Automator will pass full path from folder chooser.
# VikingOSX, July 2014, Apple Support Communities
# array for processed files that also doubles as a counter
Processed=()
gfolder="$@"
garchive="${gfolder}/GerberFiles.zip"
# keep one iteration of files in reserve
glastfolder="$HOME/glast"
shopt -s extglob
function ASDialog () {
`osascript <<-AppleScript
set filecnt to "${1}"
set archive to "${2}"
-- remaining arguments are passed processed array items
set processed to "${@: 3}"
set pcnt to count of words of processed
set msg to ""
set msg to msg & "Archive moved to Desktop: " & archive & return
set msg to msg & "Processed Files: " & pcnt & return & return
repeat with ndx from 1 to pcnt
set msg to msg & tab & (word ndx of processed) & return
end repeat
tell application "System Events"
display dialog msg with title "Processing Complete" giving up after 20
end tell
return quit
AppleScript`
}
cd "$@"
for file in \( * \)
do
[[ ${#Processed[@]} -gt 8 ]] && break
case "${file}" in
*.+(GBL|GBO|GBS|GKO|GTL|GTO|GTS|TXT))
Processed+=( "${file}" )
# do not zip the enclosing folder path, only the filename
/usr/bin/zip -g ${garchive} `/usr/bin/basename "${file}" "${gfolder}"` -x \*.DS_Store &>/dev/null
;;
*)
;;
esac
done
shopt -u extglob
# provide user completion dialog
ASDialog "${#Processed[@]}" "${garchive##*/}" "${Processed[@]}"
unset Processed
/bin/mv ${garchive} ~/Desktop/${garchive##*/}
# keep one iteration of Gerber files as backup
/usr/bin/ditto "${gfolder}" "${glastfolder}"
#/bin/rm -f \{ "${gfolder}"/* \)
exit 0