The Automator “Run Shell Script” action runs the script in a non-interactive shell (for an explanation of the difference between interactive and non-interactive shells, see the pertinent section of the Advanced Bash Scripting Guide) – there is, simply spoken, no terminal to get user input from. I suppose the gpg
utility recognizes this and skips the password prompt (else your script would hang).
You should be able to pipe your passphrase to GPG inside such an action using the --passphrase-fd 0
option (see gpg’s man page) , however, i.e.
echo "passphrase" | gpg --passphrase-fd 0 --output $outfile --decrypt /path/to/file.gpg
You can securely store your passphrase in the OS X Keychain and retrieve it from there. Although possible via a shell script (the TextMate blog has details on how to achieve that – be sure to read the comments), there are so many gotchas to that I’d recommend using a bit of AppleScript and Daniel Jalkut’s excellent Usable Keychain Scripting app. Once installed, the following bit of AppleScript will retrieve your password (assuming the account name is “GPG”):
tell application "Usable Keychain Scripting" to get password of first generic item of current keychain whose account is "GPG"
Either wrap it in an osascript
shell command, i.e.
passphrase=$(osascript -e '<command above>')
or, as you are using Automator, add an AppleScript action, retrieve the passphrase inside it and pass it to the shell script.
Automator Service
You can use Automator to create a new service or droplet:
- Launch Automator.app
- Create a new service with service receives files or folders in any application
- Add a Run Shell Script action
- Set Pass input: to as arguments
- Within the script, replace
echo
with the script below.
- Save your workflow as a service.
Shell Script
for f in "$@"
do
/Users/Amit/Documents/Scripts/ffmpeg -i "$f" -c:v copy -c:a copy "${f%.*}.mp4"
done
To learn more about using Automator, see Apple's Mac Basics: Automator.
Best Answer
Get rid of those get/set variable actions, and it'll stop doing that. Keep in mind that if two actions appear "linked" in Automator, it means the output of one is being fed to the input of the other. You don't need variables in this case. Basically, the folder from "Ask for Finder Items" is being passed down the chain to your shell script, along the way setting it to a variable, and then getting the same folder, and adding it to the stream. This stream now contains two folders.
The purpose of the get/set variable actions are for when you have a situation where you want to use a piece of data with two actions which terminate the stream. You can't get the data once it's been consumed by said action, so you have to store it somewhere so that you can retrieve it again.