snipt

Ctrl+h for KB shortcuts

Bash

Convert Image from Alfred

1
2
3
4
5
6
7
8
9
#!/bin/sh
#By Don Southard aka @binaryghost

NAME=${1%.*}
EXT=${1##*.} 
if [[ $EXT = "png" ]]; then CONVERTED=`echo $NAME.jpg`
else CONVERTED=`echo $NAME.png`
fi
/usr/local/bin/convert "$1" "$CONVERTED"
https://snipt.net/embed/e42abaeb696eb13127d2331910f115dc/
/raw/e42abaeb696eb13127d2331910f115dc/
e42abaeb696eb13127d2331910f115dc
bash
Bash
9
2019-06-19T15:23:56
True
False
False
/api/public/snipt/26716/
convert-image-from-alfred
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a> <a href="#L-8">8</a> <a href="#L-9">9</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="ch">#!/bin/sh</span> </span><span id="L-2"><a name="L-2"></a><span class="c1">#By Don Southard aka @binaryghost</span> </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="nv">NAME</span><span class="o">=</span><span class="si">${</span><span class="nv">1</span><span class="p">%.*</span><span class="si">}</span> </span><span id="L-5"><a name="L-5"></a><span class="nv">EXT</span><span class="o">=</span><span class="si">${</span><span class="nv">1</span><span class="p">##*.</span><span class="si">}</span> </span><span id="L-6"><a name="L-6"></a><span class="k">if</span> <span class="o">[[</span> <span class="nv">$EXT</span> <span class="o">=</span> <span class="s2">&quot;png&quot;</span> <span class="o">]]</span><span class="p">;</span> <span class="k">then</span> <span class="nv">CONVERTED</span><span class="o">=</span><span class="sb">`</span><span class="nb">echo</span> <span class="nv">$NAME</span>.jpg<span class="sb">`</span> </span><span id="L-7"><a name="L-7"></a><span class="k">else</span> <span class="nv">CONVERTED</span><span class="o">=</span><span class="sb">`</span><span class="nb">echo</span> <span class="nv">$NAME</span>.png<span class="sb">`</span> </span><span id="L-8"><a name="L-8"></a><span class="k">fi</span> </span><span id="L-9"><a name="L-9"></a>/usr/local/bin/convert <span class="s2">&quot;</span><span class="nv">$1</span><span class="s2">&quot;</span> <span class="s2">&quot;</span><span class="nv">$CONVERTED</span><span class="s2">&quot;</span> </span></pre></div> </td></tr></table>
alfred, bash