I mentioned in a previous post that for testing purposes, you need to comment out the remove line in the script. I see you haven’t, and yes, it will remove every file in the source folder as it currently stands. I leave this line commented (preceding #) for testing purposes. You file names must not contain a space (e.g. foo bar.GBS).
The script as written will make copies of your source folder files in your login directory/glast folder. It still works with my dataset, with a proper formatted dialog, and the archive always gets written to the Desktop, containing eight correct files.
The script logic is expecting a folder to be passed to it from the Ask for Finder Items action. You have set the Start at: to your source folder containing your files. So the individual files are passed to the script, resulting in incorrect script behavior. If your source folder is on the Desktop, set the Start at: to Desktop, as I originally had it configured. When the application runs, the choose dialog will show your folder on the Desktop. Click once on the folder, and then Choose. Now you are passing a folder to the application as it expects.
On the outside chance that you may have compromised the original script in an editing session, I am reposting the most recent that works for me. I even moved the source folder to the Desktop, and it still worked exactly as I have interpreted your original intention. Start Automator, cancel the open file dialog, and from the File menu, pick this application name from Open Recent menu. In the Run Shell Script window, select everything and remove it. Copy/Paste the contents from below — back into that Run Shell Script window. Again, verify that the Pass input selector is set to, as arguments, and not to stdin. Save the application.
#!/bin/bash
# if testing in Terminal, supplied folder name must have relative "~" or
# full path name. Automator will pass full path from folder chooser.
# array for processed files that also doubles as a counter
# VikingOSX, July 2014, Apple Support Communities
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 tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to space
set pcnt to count of (text items 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 & (text item ndx of processed) & return
end repeat
set AppleScript's text item delimiters to tid
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[@]} -eq 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