<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<atom:link href="https://dev1galaxy.org/extern.php?action=feed&amp;tid=4201&amp;type=rss" rel="self" type="application/rss+xml" />
		<title><![CDATA[Dev1 Galaxy Forum / [SOLVED] Need a lil coding help with an extension (shell script), openbox/pcman]]></title>
		<link>https://dev1galaxy.org/viewtopic.php?id=4201</link>
		<description><![CDATA[The most recent posts in [SOLVED] Need a lil coding help with an extension (shell script), openbox/pcman.]]></description>
		<lastBuildDate>Sat, 20 Mar 2021 20:44:26 +0000</lastBuildDate>
		<generator>FluxBB</generator>
		<item>
			<title><![CDATA[Re: [SOLVED] Need a lil coding help with an extension (shell script), openbox/pcman]]></title>
			<link>https://dev1galaxy.org/viewtopic.php?pid=28400#p28400</link>
			<description><![CDATA[<p>Man i&#039;m glad I posted these things...we don&#039;t have internet at the house, using the library wi-fi now that they finally opened back up, so for months all i&#039;ve had to work with are man pages, and nobody to ask to look at something for me, it&#039;s amazing how a fresh set of eyes can spot so quickly little mistakes that have been staring me in the face for days, lol.</p><p>Thanks Head_on_a_stick, all that was needed on that second script was to double-quote the $1 (plus the change to the .desktop) and the whole thing works perfectly now!</p><p>You guys rock!</p>]]></description>
			<author><![CDATA[dummy@example.com (greenjeans)]]></author>
			<pubDate>Sat, 20 Mar 2021 20:44:26 +0000</pubDate>
			<guid>https://dev1galaxy.org/viewtopic.php?pid=28400#p28400</guid>
		</item>
		<item>
			<title><![CDATA[Re: [SOLVED] Need a lil coding help with an extension (shell script), openbox/pcman]]></title>
			<link>https://dev1galaxy.org/viewtopic.php?pid=28399#p28399</link>
			<description><![CDATA[<div class="quotebox"><cite>Head_on_a_Stick wrote:</cite><blockquote><div><p>Have you tried changing this line:</p><div class="quotebox"><cite>greenjeans wrote:</cite><blockquote><div><div class="codebox"><pre><code>convert $1 -strip -rotate &quot;$rot&quot; -set filename:copy &#039;%t-rotated.%e&#039; &#039;%[filename:copy]&#039;</code></pre></div></div></blockquote></div><p>To this:</p><div class="codebox"><pre><code>convert &quot;$@&quot; -strip -rotate &quot;$rot&quot; -set filename:copy &#039;%t-rotated.%e&#039; &#039;%[filename:copy]&#039;</code></pre></div><p>If the file name is separated by spaces then it will be interpreted as multiple arguments for the script and <span class="bbc">&quot;$@&quot;</span> will pass them all through whereas <span class="bbc">$1</span> (or <span class="bbc">&quot;$1&quot;</span>, <a href="https://mywiki.wooledge.org/Quotes" rel="nofollow">as it should be</a>) will only pass the first part of the file name, which won&#039;t be recognised.</p></div></blockquote></div><p>Wow, good eye, I never noticed that I hadn&#039;t quoted the $1 in the second script...huh, but still worked other than the spaces issue...I made these like 4 years ago and was in a hurry to get &#039;em working, I sell a lot of stuff online and the re-size option is a huge time-saver for me, and the rotater is nice for the occasional cell-phone pic that needs to be rotated.</p><p>Okay, trying stuff now, lol, BRB.</p>]]></description>
			<author><![CDATA[dummy@example.com (greenjeans)]]></author>
			<pubDate>Sat, 20 Mar 2021 20:37:07 +0000</pubDate>
			<guid>https://dev1galaxy.org/viewtopic.php?pid=28399#p28399</guid>
		</item>
		<item>
			<title><![CDATA[Re: [SOLVED] Need a lil coding help with an extension (shell script), openbox/pcman]]></title>
			<link>https://dev1galaxy.org/viewtopic.php?pid=28397#p28397</link>
			<description><![CDATA[<p>Have you tried changing this line:</p><div class="quotebox"><cite>greenjeans wrote:</cite><blockquote><div><div class="codebox"><pre><code>convert $1 -strip -rotate &quot;$rot&quot; -set filename:copy &#039;%t-rotated.%e&#039; &#039;%[filename:copy]&#039;</code></pre></div></div></blockquote></div><p>To this:</p><div class="codebox"><pre><code>convert &quot;$@&quot; -strip -rotate &quot;$rot&quot; -set filename:copy &#039;%t-rotated.%e&#039; &#039;%[filename:copy]&#039;</code></pre></div><p>If the file name is separated by spaces then it will be interpreted as multiple arguments for the script and <span class="bbc">&quot;$@&quot;</span> will pass them all through whereas <span class="bbc">$1</span> (or <span class="bbc">&quot;$1&quot;</span>, <a href="https://mywiki.wooledge.org/Quotes" rel="nofollow">as it should be</a>) will only pass the first part of the file name, which won&#039;t be recognised.</p>]]></description>
			<author><![CDATA[dummy@example.com (Head_on_a_Stick)]]></author>
			<pubDate>Sat, 20 Mar 2021 20:05:11 +0000</pubDate>
			<guid>https://dev1galaxy.org/viewtopic.php?pid=28397#p28397</guid>
		</item>
		<item>
			<title><![CDATA[Re: [SOLVED] Need a lil coding help with an extension (shell script), openbox/pcman]]></title>
			<link>https://dev1galaxy.org/viewtopic.php?pid=28396#p28396</link>
			<description><![CDATA[<p>Okay so, even stranger....</p><p>Last night when I got home and started messing with it, I decided to double-check whether quoting changes would help, and I must never have tried replacing the single-quoted string in the .desktop with double quotes, and lo and behold it fixed it!&#160; but....</p><p>1. I don&#039;t know why that would fix it and would really like to understand why...no biggie but....</p><p>2. I have an almost identical extension that works the same way only it provides a &quot;rotate image&quot; function instead of re-sizing, so after fixing the first one I thought YAY this should fix the other too...but it didn&#039;t, still fails on spaces in file/folder names...what the actual heck???</p><p>Here&#039;s the new re-size .desktop and it works perfectly, zero issues now:</p><div class="codebox"><pre><code>[Desktop Entry]
Type=Action
Name=Resize Image
Comment=Shrink image and convert to jpg
Icon=edit-cut
Profiles=resize;

[X-Action-Profile resize]
Exec=sh -c &quot;cd %d &amp;&amp; shrink2 %f&quot;
MimeTypes=image/bmp;image/jpeg;image/png;</code></pre></div><p>And here&#039;s the .desktop for the rotater,did the same thing, changed the single quotes to double quotes, again the only change I made:</p><div class="codebox"><pre><code>[Desktop Entry]
Type=Action
Name=Rotate Image
Comment=Make rotated copy of image
Icon=edit-redo
Profiles=rot;

[X-Action-Profile rot]
Exec=sh -c &quot;cd %d &amp;&amp; rot %f&quot;
MimeTypes=image/bmp;image/jpeg;image/png;</code></pre></div><p>As you can see, pretty much identical...dunno why it won&#039;t work here when it did on the other...here&#039;s the script for the rotater:</p><div class="codebox"><pre><code>#!/bin/sh

rotbox=$(yad --fixed --window-icon=edit-redo --form --title=&quot;Rotate Image&quot; --field=&quot;Rotate:&quot;:CB --width=300 --text-align=center --text=&quot;Select rotation (clockwise, in degrees)&quot; &#039;90!180!270&#039;)

rot=$(echo $rotbox | awk &#039;BEGIN {FS=&quot;|&quot; } { print $1 }&#039;)

convert $1 -strip -rotate &quot;$rot&quot; -set filename:copy &#039;%t-rotated.%e&#039; &#039;%[filename:copy]&#039;

# Depends: yad, imagemagick
# (note: later versions of imagemagick may require a different command than &#039;convert&#039;)

# DESCRIPTION:
# This script makes a copy of an image file (JPG, BMP, PNG), rotates the copy to
# selection entered in yad dialog (90, 180 or 270 degrees clockwise), adds &quot;rotated&quot; to 
# the original filename, and outputs the copy into the same directory as the original. 
# It is intended to be used with a .desktop file for activation in PcmanFM to offer a &quot;Rotate Image&quot;
# option when you right-click an image file, but can also be used in terminal: rot [img file]</code></pre></div>]]></description>
			<author><![CDATA[dummy@example.com (greenjeans)]]></author>
			<pubDate>Sat, 20 Mar 2021 19:48:24 +0000</pubDate>
			<guid>https://dev1galaxy.org/viewtopic.php?pid=28396#p28396</guid>
		</item>
		<item>
			<title><![CDATA[Re: [SOLVED] Need a lil coding help with an extension (shell script), openbox/pcman]]></title>
			<link>https://dev1galaxy.org/viewtopic.php?pid=28369#p28369</link>
			<description><![CDATA[<p>There&#039;s also the possibillity that the filenames are &quot;urlencoded&quot; by the file manager. It would mean that spaces have been replaced with &quot;%20&quot; (and a bit more). </p><p>You might try adding the following function:</p><div class="codebox"><pre><code>urldecode() {
    bash -c &quot;printf &#039;%b&#039; &#039;$(echo &quot;$1&quot; | sed &#039;s|%%| |g;s|%|\\x|g;s| |%|g&#039;)&#039;&quot;
}</code></pre></div><p> to your <span class="bbc">/bin/sh</span> script, and then use</p><div class="codebox"><pre><code>convert &quot;$(urldecode $1)&quot; ...</code></pre></div><p>TL;DR; In detail, that <span class="bbc">urldecode</span> function for <span class="bbc">dash</span> processes its given argument with <span class="bbc">sed</span> to replace all <span class="bbc">%NN</span> with <span class="bbc">\xNN</span> except for occurrences&#160; of <span class="bbc">%%</span> which instead are replaced with single <span class="bbc">%</span>. The resulting string is printed with <span class="bbc">bash</span> <span class="bbc">printf</span> using the <span class="bbc">%b</span> format which makes all <span class="bbc">\xNN</span> into characters of hexadecimal ASCII code <span class="bbc">NN</span>.</p><p>Note that the <span class="bbc">sed</span> processing uses space temporarily to make the <span class="bbc">%%</span>-to-<span class="bbc">%</span> translation bypass the&#160; <span class="bbc">%NN</span>-to-<span class="bbc">\xNN</span> translation. It therefore misbehaves for an input that already has space characters.</p>]]></description>
			<author><![CDATA[dummy@example.com (ralph.ronnquist)]]></author>
			<pubDate>Fri, 19 Mar 2021 22:00:50 +0000</pubDate>
			<guid>https://dev1galaxy.org/viewtopic.php?pid=28369#p28369</guid>
		</item>
		<item>
			<title><![CDATA[Re: [SOLVED] Need a lil coding help with an extension (shell script), openbox/pcman]]></title>
			<link>https://dev1galaxy.org/viewtopic.php?pid=28365#p28365</link>
			<description><![CDATA[<p>Try using <span class="bbc">&quot;$@&quot;</span> instead of <span class="bbc">&quot;$1&quot;</span> in the <span class="bbc">convert</span> line of the shell script.</p><p>Off topic but I would also suggest using <a href="https://pkginfo.devuan.org/cgi-bin/policy-query.html?c=package&amp;q=whiptail" rel="nofollow">whiptail</a> (in a terminal) rather than yad because the output could be parsed without resorting to awk:</p><p><a href="https://en.wikibooks.org/wiki/Bash_Shell_Scripting/Whiptail#Input_box" rel="nofollow">https://en.wikibooks.org/wiki/Bash_Shel … #Input_box</a></p>]]></description>
			<author><![CDATA[dummy@example.com (Head_on_a_Stick)]]></author>
			<pubDate>Fri, 19 Mar 2021 20:45:25 +0000</pubDate>
			<guid>https://dev1galaxy.org/viewtopic.php?pid=28365#p28365</guid>
		</item>
		<item>
			<title><![CDATA[Re: [SOLVED] Need a lil coding help with an extension (shell script), openbox/pcman]]></title>
			<link>https://dev1galaxy.org/viewtopic.php?pid=28364#p28364</link>
			<description><![CDATA[<p>Thanks y&#039;all!</p><p>First thing I tried was all kinds of quotes around the %f and %d and didn&#039;t work for me, but will go back and try again to be sure, normally that works in terminal but seems like it wouldn&#039;t work here because the entire command string is quoted.</p><p>@dice: cd is to first change the directory to current one, or it will drop all output into the home folder regardless of what directory you&#039;re in.</p><p>Okay, just tried the recommended double quotes again, still no joy.</p><p>@Golinux: Hi there Lady! Hope all is well down there, FYI we may be moving back home soon, so maybe i&#039;ll get to see ya! ;-)</p>]]></description>
			<author><![CDATA[dummy@example.com (greenjeans)]]></author>
			<pubDate>Fri, 19 Mar 2021 20:30:56 +0000</pubDate>
			<guid>https://dev1galaxy.org/viewtopic.php?pid=28364#p28364</guid>
		</item>
		<item>
			<title><![CDATA[Re: [SOLVED] Need a lil coding help with an extension (shell script), openbox/pcman]]></title>
			<link>https://dev1galaxy.org/viewtopic.php?pid=28351#p28351</link>
			<description><![CDATA[<p>why is their a cd in the exec line of the .desktop file ?</p><p>Im pretty sure double quotes would rectify this as ralph mentions.</p><div class="codebox"><pre><code>[Desktop Entry]
Type=Action
Name=Resize Image
Comment=Shrink image and convert to jpg
Icon=edit-cut
Profiles=resize;

[X-Action-Profile resize]
Exec=sh -c &#039;cd &quot;%d&quot; &amp;&amp; shrink2 &quot;%f&quot;&#039;
MimeTypes=image/bmp;image/jpeg;image/png;</code></pre></div><p>confirmed working with gaps in file name, im using nemo file manager though.</p>]]></description>
			<author><![CDATA[dummy@example.com (dice)]]></author>
			<pubDate>Fri, 19 Mar 2021 11:29:41 +0000</pubDate>
			<guid>https://dev1galaxy.org/viewtopic.php?pid=28351#p28351</guid>
		</item>
		<item>
			<title><![CDATA[Re: [SOLVED] Need a lil coding help with an extension (shell script), openbox/pcman]]></title>
			<link>https://dev1galaxy.org/viewtopic.php?pid=28342#p28342</link>
			<description><![CDATA[<p>Perhaps double quotes around <span class="bbc">%f</span> makes a difference? and around <span class="bbc">%d</span> as well, probably.</p>]]></description>
			<author><![CDATA[dummy@example.com (ralph.ronnquist)]]></author>
			<pubDate>Thu, 18 Mar 2021 23:18:00 +0000</pubDate>
			<guid>https://dev1galaxy.org/viewtopic.php?pid=28342#p28342</guid>
		</item>
		<item>
			<title><![CDATA[Re: [SOLVED] Need a lil coding help with an extension (shell script), openbox/pcman]]></title>
			<link>https://dev1galaxy.org/viewtopic.php?pid=28341#p28341</link>
			<description><![CDATA[<p>Welcome home, greenjeans!!&#160; <img src="https://dev1galaxy.org/img/smilies/big_smile.png" width="15" height="15" alt="big_smile" /></p>]]></description>
			<author><![CDATA[dummy@example.com (golinux)]]></author>
			<pubDate>Thu, 18 Mar 2021 21:35:49 +0000</pubDate>
			<guid>https://dev1galaxy.org/viewtopic.php?pid=28341#p28341</guid>
		</item>
		<item>
			<title><![CDATA[[SOLVED] Need a lil coding help with an extension (shell script), openbox/pcman]]></title>
			<link>https://dev1galaxy.org/viewtopic.php?pid=28340#p28340</link>
			<description><![CDATA[<p>Hey guys, been out of touch for a long time now, big moves, covid, etc. been getting in the way of my linux&#039;ing...anyhoo, had a question about some extensions i&#039;ve been using and working on again and need some help if anybody has time. I&#039;m still a terrible rookie coder, lol, trying to leanr more though.</p><p>Here&#039;s the main one, it&#039;s a right-click context menu extension for pcmanfm that re-sizes pics using imagemagick for the backend and yad, super-handy and fast, and works perfectly...except...spaces in file or folder names break it, and can&#039;t seem to fix it with usual methods. I can finagle it into working with spaces in filenames but then it drops all output into home folder instead of current directory and no amount of cd or mv commands seems to make it work right. I&#039;m pretty good about not putting spaces in file/folder names, but ya know, would be nice if it didn&#039;t break script. </p><p>Here&#039;s the code, a .desktop file that goes into /home/user/.local/share/file-manager/actions and the script I made (usr/bin):</p><div class="codebox"><pre><code>[Desktop Entry]
Type=Action
Name=Resize Image
Comment=Shrink image and convert to jpg
Icon=edit-cut
Profiles=resize;

[X-Action-Profile resize]
Exec=sh -c &#039;cd %d &amp;&amp; shrink2 %f&#039;
MimeTypes=image/bmp;image/jpeg;image/png;</code></pre></div><div class="codebox"><pre><code>#!/bin/sh

sizebox=$(yad --fixed --window-icon=edit-cut --form --title=&quot;Resize Image&quot; --field=&quot;Resize to:&quot; --width=400 --text-align=center --text=&quot;Enter new size (W x H in pixels, i.e. 800x600, 1024x768 etc.)&quot;)

size=$(echo $sizebox | awk &#039;BEGIN {FS=&quot;|&quot; } { print $1 }&#039;)

convert &quot;$1&quot; -resize &quot;$size&quot; -set filename:copy &#039;%t-%wx%h&#039; &#039;%[filename:copy].jpg&#039;

# Depends: yad, imagemagick
# (note: later versions of imagemagick may require a different command than &#039;convert&#039;)

# DESCRIPTION:
# This script makes a copy of an image file (JPG, BMP, PNG), resizes the copy to whatever
# dimensions are entered, converts it to a JPEG, adds the new dimensions to the original
# filename, and outputs the copy into the same directory as the original. It is intended to
# be used with a .desktop file for activation in PcmanFM to offer a &quot;Resize Image&quot;
# option when you right-click an image file, but can also be used in terminal: shrink2 [img file]</code></pre></div><p>Thanks!<br />~greenjeans</p>]]></description>
			<author><![CDATA[dummy@example.com (greenjeans)]]></author>
			<pubDate>Thu, 18 Mar 2021 21:14:14 +0000</pubDate>
			<guid>https://dev1galaxy.org/viewtopic.php?pid=28340#p28340</guid>
		</item>
	</channel>
</rss>
