Skip to content

Instantly share code, notes, and snippets.

@mattintosh4
Last active October 13, 2015 16:58
Show Gist options
  • Save mattintosh4/4227856 to your computer and use it in GitHub Desktop.
Save mattintosh4/4227856 to your computer and use it in GitHub Desktop.
Automator 用シェルスクリプト集 その2

ShellScript for Automator Part.2

Mac OS X 10.6.8 / Automator 2.1.1

# mode: stdin
while read f
do
### compress ###
[ -d "$f" ] && {
tar cfC - "${f%/*}" "${f##*/}" | 7z a -si "$f".tar.xz
}
### decompress ###
[ -f "$f" -a -z "${f##*.tar.xz}" ] && {
7z x -so "$f" | tar xfC - "${f%/*}"
}
done
afplay /System/Library/Sounds/Hero.aiff
# mode: stdin
while read f
do
[ ! -f "$f" ] && continue
### open in term ###
#tmp=/tmp/`uuidgen`
case "${f##*.}" in
bz|bz2|gz|tar|tbz|tbz2|tgz|zip)
### open in textedit ###
tar tf "$f" | open -ft
### open in term ###
#printf 'tar tvf "%s" | less' "$f" > $tmp; chmod +x $tmp; open $tmp
;;
lzma|xz)
### open in textedit ###
which xz && xz -tdc "$f" | tar tf - | open -ft
### open in term ###
#which xz && printf 'xz -tdc "%s" | tar tvf - | less' "$f" > $tmp; chmod +x $tmp; open $tmp
;;
esac
done
# mode: stdin
while read f
do
[ ! -f "$f" ] && continue
extension="`ffmpeg -i "$f" 2>&1 | egrep -o "Audio: \w+" | cut -d' ' -f2`"
case "$extension" in
aac)
printf 'ffmpeg -i "%s" -vn -acodec copy "%s"\n' "$f" "$f".m4a
;;
*)
printf 'ffmpeg -i "%s" -vn -acodec libfaac -ac 2 -ar 48000 -aq 100 "%s"\n' "$f" "$f".m4a
;;
esac
done > ${S:=/tmp/ffmpeg_$$}
echo "afplay /System/Library/Sounds/Hero.aiff" >> $S
chmod +x $S; open $S
# mode: stdin
while read f
do
[ ! -f "$f" ] && continue
extension="`ffmpeg -i "$f" 2>&1 | egrep -o "Audio: \w+" | cut -d' ' -f2`"
printf 'ffmpeg -i "%s" -vn -acodec copy "%s"\n' "$f" "$f".$extension
done > ${S:=/tmp/ffmpeg_$$}
echo "afplay /System/Library/Sounds/Hero.aiff" >> $S
chmod +x $S; open $S
# type: application
# mode: free
#
# output patterns
# ---------------
#
# (1) portname +variants:
# awk 'NR >= 2 { sub(/^[^+]+/, "", $2); print $1, $2 }'
#
# (2) portname:
# awk 'NR >= 2 { print $1 }'
#
# (3) portname @revision+variants:
# awk 'NR >= 2 { print $1, $2 }'
#
/opt/local/bin/port installed active | awk 'NR >= 2 { sub(/^[^+]+/, "", $2); print $1, $2 }' | open -ft
FILE=/tmp/automator_$$
cat > $FILE <<__EOF__
#!/bin/bash --login
# begin command
# end command
__EOF__
chmod +x $FILE
open $FILE
# mode: stdin
while read
do
### decompress ###
if echo "$REPLY" | grep -sq ".tar.xz$"; then
tmp=/tmp/automator_$$_$((i++))
printf '#!/bin/sh\nxzcat -v "%s" | tar xf - -C "%s"' $REPLY ${REPLY%/*} > $tmp
chmod +x $tmp
open -g $tmp
### compress ###
elif [ -d "$REPLY" ]; then
tmp=/tmp/automator_$$_$((i++))
printf '#!/bin/sh\ncd "%s" && tar cf - "%s" | xz -v --threads=0 > "%s".tar.xz' ${REPLY%/*} ${REPLY##*/} ${REPLY##*/} > $tmp
chmod +x $tmp
open -g $tmp
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment