Hi I'm new to Macs and OSX, I'm using p7zip cli app to compress folders with big files inside (1; 2 GB or more). So I managed to make a Bash script to do it in batch process when I go to bed and I'm not using the computer.

This the code:

 for folder in */
 7z a -t7z -m0=lzma2 -mx=9 -mfb=64 -md=1024m -ms=on -mmt2 "${folder%/}.7z" "$folder"

I have this in Comp7zip.sh file, I put that file inside the main folder that contains all the other subfolders I want to compress. So from the terminal I do:

$cd myfolder

Then in the terminal I can see how the 7z app is working, and it compresses all the folders just fine.

But since it is a bit annoying, copying the .sh file inside the folder and using the terminal every time, I use Automator to create a service and do it with a couple of clicks, this is the code:

cd "$@"
for folder in */
do /usr/local/bin/7z a -t7z -m0=lzma2 -mx=9 -mfb=64 -md=1024m -ms=on -mmt2 "${folder%/}.7z" "$folder"

It's almost the same, just add the cd "$@" to use the selected folder in finder, so I have a new service that does the same thing that the .sh file does.

I just select the folder that has all the subfolders I want to compress, then pick my service from Finder's context menu, works fine and compresses all the folders inside the selected folder.

The problem here is, that in this way I can't see the 7z app wile it's working, all the compressing is made in the background with just and icon of a little gear in the menu bar that indicate the compress is running, and nothing more.

So with little files this is not a problem the compress ends fast, but with large files, I can't see how the compress work is doing it.

So the question is, how can I make Automator to show me the running task in the same way the method with the .sh Bash file does?

Also any ideas of how to add to this process a way to compress files outside subfolders in the selected folder? I mean all this code only works with folders and it's content, but not with files, so how cam I make it work with folders and files in the same process?

I'm sorry for my grammar, English is not my native language.

  • With many of the zip apps, just dragging the folder onto the app icon is sufficient to get the folder and contents compressed usually with a progress bar shown on the icon.
    – Solar Mike
    Apr 13, 2019 at 7:14
  • I already know that, but usually thats apps dont let u set the max compres settings, or are just zip, in this case the compresor is 7z and the comand I put give one of the best compres ratio and are ideal for big files.
    – TulkasLE
    Apr 13, 2019 at 13:53

1 Answer 1


If you run a shell script by:

  1. Opening the Terminal application
  2. Telling the Terminal application to start your script

Then the script's output will, by default, be displayed inside the Terminal window (this can be changed by, for example, redirecting the output to a text file with the > character). This is what you have been doing "before going to bed".

Shell scripts, however, can also be run without ever opening the Terminal application! For example, you could create a launchd plist to run a shell script whenever your computer finishes booting. In this case, the script would run, but nothing would be displayed on screen, because the Terminal application was never opened.

Similarly, Applescript's do shell script command executes shell code directly without ever opening the Terminal.

Instead of running the shell code directly, tell the Terminal application to run the shell code for you:

tell application "Terminal"
  do script "echo 'Hello World'"
end tell

Now, Applescript will open a Terminal window, and run your shell code inside of it.


  • Thx for the answer, I already try to do it in this way and the scritp dont work, the problems is, the script need to know what are the folders to compres, and with the method "tell aplicaion" applescript dont pass that info to the script. Whit the .sh file meothd is need to copy the .sh file inside the main folder and then : for folder in */ tell what to compres. whit the automator method the : cd "$@"
    – TulkasLE
    Apr 13, 2019 at 22:17
  • cd "$@" tell the script go inside the selected folder and compres all the subfolders. I dont know how to make it work with applescript, I dont find a way to indicate in what folder has the things that has to be compresed, ofc I have o most no programming knowledge, I manage to do the first bash script just reeding the wiki of bash an the wiki of 7z, Iam learning, thats why ask, Iam totally noob on Mac and applescript. LOL.
    – TulkasLE
    Apr 13, 2019 at 22:34
  • @TulkasLE I hope this doesn't come across as petty, but I'm legitimately finding your comments difficult to read with all the spelling and grammar errors. If you were to clean that up I might be able to help you more. Apr 13, 2019 at 22:45
  • Yes sorry, English is not my native language, I have done the best I could with the help of Google Translate
    – TulkasLE
    Apr 13, 2019 at 22:48
  • I put the bash code inside the apple script as u say, and dont work, dont run, and error is reported. tell application "Terminal" do script for folder in */ do /usr/local/bin/7z a -t7z -m0=lzma2 -mx=9 -mfb=64 -md=1024m -ms=on -mmt2 "${folder%/}.7z" "$folder" done end tell
    – TulkasLE
    Apr 13, 2019 at 22:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .