4

I have used Automator Application to create application(.app which runs by double clicking). It runs commands which executes command one by one. Every command takes 2-3 minutes. What I want to achieve is show percentage progress after completion of every command.

enter image description here

In above image percentage is always zero. I want to explicitly set progress after completion of every command. I also know this is possible using AppleScript but I want to implement in bash script.

2
  • If it just one "Run Shell Script" action and that shell script contains multiple commands I don't think you can do it. The % complete is the % of actions complete. If you can split your shell script into multiple scripts across several "Run Shell Script" actions then the % complete will update as they finish. Commented Jun 5, 2020 at 23:41
  • @tzs I just want to show progress. Which I think is possible to throw using Automator I found sample of automator script on apple documentation but that doesn't show progress either. And of course if we have 10 command and 4 of them are completed we should be able to show 40% completed. Commented Jun 6, 2020 at 0:48

1 Answer 1

-2

I did this once for a script of mine:

progress() { set -- "$@" "$((100*$1/$2))" "$(($1 == 0 ? -1 : SECONDS*($2-$1)/$1))" printf "%d of %d (%d%%) eta %s sec" "$@" } 

You pass it 2 parameters:

  1. the current number of the thing you're processing,
  2. the total number of things you're processing

Your script will look like:

#!/bin/bash progress() { set -- "$@" "$((100*$1/$2))" "$(($1 == 0 ? -1 : SECONDS*($2-$1)/$1))" printf "%d of %d (%d%%) eta %s sec" "$@" } n=10 # you need to hardcode this, the total number of commands to run i=0 command_01; progress $((++i)) $n command_02; progress $((++i)) $n command_03; progress $((++i)) $n command_04; progress $((++i)) $n command_05; progress $((++i)) $n command_06; progress $((++i)) $n command_07; progress $((++i)) $n command_08; progress $((++i)) $n command_09; progress $((++i)) $n command_10; progress $((++i)) $n printf "\nThat took %d sec\n" $SECONDS 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the reply but this is working fine when I run bash script from Terminal. But I have created application(.app) from Automator which runs when you double click on it. So for knowing progress of it I can only show percentage of it on menu bar as attached in Image above.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.