If you can solve my automator issue I will marry you

Hello programmers,
I need help with Zipping the contents of a folder without including the folder itself:

Every day at work I need to do the same task and I would die if automator could solve this for me.
What I need it to do:
1.Open Folder A
2.In this Folder there are 5 Subfolders. We will call these 1,2,3,4,5. It needs to open these subfolders, select all assets within the folder
3. Compress the selected assets.
4. Rename the zip file (which will be automatically called “archive” by apple. Change name “archive” to Folder Name. So in this example the folders would then be calles '1" “2” “3” etc.
5. Take zip File “1” and drag and drop it into the Folder A Folder.

What makes this difficult: For other reasons the automator should NOT just zip the main folder “1”, it needs to really select all the stuff inside “1” and then zip it. It makes a difference for my software I use afterwards.

Not even sure if this is solvable in automator. I am also open for any software that can do this, or scripts etc…
Okay If you can solve this I will marry you. You need to fly to Germany though.
Thank you,
Hannah

Model: macbook pro
Browser: Safari 604.3.5
Operating System: Mac OS X (10.13 Developer Beta 3)

Hello Hannah,

This problem is not overly difficult if you have a little proficiency with the shell.

[format]
#!/usr/bin/env bash

--------------------------------------------------

USER-SETTING – Root Source Directory

--------------------------------------------------

srcDir=~/‘test_directory/KM_TEST/A’

--------------------------------------------------

dirList=$(find $srcDir -type d -mindepth 1)

for dir in $dirList
do
cd “$dir”
zip -j …/“$(basename $dir)”‘.zip’ *
done
[/format]

In AppleScript this looks like:


set shCMD to text 2 thru -1 of "
#!/usr/bin/env bash

# --------------------------------------------------
# USER-SETTING -- Root Source Directory
# --------------------------------------------------
srcDir=~/'test_directory/KM_TEST/A'
# --------------------------------------------------

dirList=$(find $srcDir -type d -mindepth 1)
for dir in $dirList
	do
		cd \"$dir\"
		zip -j ../\"$(basename $dir)\"'.zip' *
	done
"
do shell script shCMD

Full POSIX Paths should be single-quoted.

Tilde-Based-POSIX-Paths should be singe-quoted as demonstrated in the scripts.


Automator is much better than nothing, but after so many years of un-improvements it’s become awfully lame.


I recommend FastScripts or Keyboard Maestro for running scripts of this sort.

FastScripts’ demo mode allows unlimited scripts but only 10 assignable keyboard shortcuts, and this is often enough for people with modest macro needs.

The full version is $9.95 U.S. and unlocks unlimited app-specific and global keyboard shortcuts.

You can give your task/script a specific keyboard shortcut, or you can use the FastScripts app’s keyboard shortcut to pop open its menu and then type-select to get to the script you want to invoke.


Keyboard Maestro at $36.00 U.S. is is a full-fledged automation utility and significantly more powerful than FastScripts.


I’ve used both hundreds of times a day since 2003 and gained not 1 penny by evangelizing them.

-Chris