Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Archiving a group of files

Is there a way to automatic a process to zip up several files? What I’m envisioning is, that I go to the finder, and locate a specific folder. Then I hit some hot key or a custom button on the toolbar that will zip up 8 files in that folder. The file names of these 8 files will always be different, but the file extensions will always be the same. There are 8 file extensions, 1 each of:

.GBL

.GBO

.GBS

.GKO

.GTL

.GTO

.GTS

.TXT

There will never be more than 1 file of each file extension in the folder. And if it’s possible, call this archive “GerberFiles”, and move it to my desktop.

Mac OS X (10.7.3)

Posted on Jul 19, 2014 10:30 AM

Reply
17 replies

Jul 30, 2014 8:46 AM in response to SouthernAtHeart

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

Archiving a group of files

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.