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!
You guys rock!
]]>Have you tried changing this line:
greenjeans wrote:convert $1 -strip -rotate "$rot" -set filename:copy '%t-rotated.%e' '%[filename:copy]'
To this:
convert "$@" -strip -rotate "$rot" -set filename:copy '%t-rotated.%e' '%[filename:copy]'
If the file name is separated by spaces then it will be interpreted as multiple arguments for the script and "$@" will pass them all through whereas $1 (or "$1", as it should be) will only pass the first part of the file name, which won't be recognised.
Wow, good eye, I never noticed that I hadn'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 '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.
Okay, trying stuff now, lol, BRB.
]]>convert $1 -strip -rotate "$rot" -set filename:copy '%t-rotated.%e' '%[filename:copy]'
To this:
convert "$@" -strip -rotate "$rot" -set filename:copy '%t-rotated.%e' '%[filename:copy]'
If the file name is separated by spaces then it will be interpreted as multiple arguments for the script and "$@" will pass them all through whereas $1 (or "$1", as it should be) will only pass the first part of the file name, which won't be recognised.
]]>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! but....
1. I don't know why that would fix it and would really like to understand why...no biggie but....
2. I have an almost identical extension that works the same way only it provides a "rotate image" function instead of re-sizing, so after fixing the first one I thought YAY this should fix the other too...but it didn't, still fails on spaces in file/folder names...what the actual heck???
Here's the new re-size .desktop and it works perfectly, zero issues now:
[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 "cd %d && shrink2 %f"
MimeTypes=image/bmp;image/jpeg;image/png;
And here's the .desktop for the rotater,did the same thing, changed the single quotes to double quotes, again the only change I made:
[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 "cd %d && rot %f"
MimeTypes=image/bmp;image/jpeg;image/png;
As you can see, pretty much identical...dunno why it won't work here when it did on the other...here's the script for the rotater:
#!/bin/sh
rotbox=$(yad --fixed --window-icon=edit-redo --form --title="Rotate Image" --field="Rotate:":CB --width=300 --text-align=center --text="Select rotation (clockwise, in degrees)" '90!180!270')
rot=$(echo $rotbox | awk 'BEGIN {FS="|" } { print $1 }')
convert $1 -strip -rotate "$rot" -set filename:copy '%t-rotated.%e' '%[filename:copy]'
# Depends: yad, imagemagick
# (note: later versions of imagemagick may require a different command than 'convert')
# 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 "rotated" 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 "Rotate Image"
# option when you right-click an image file, but can also be used in terminal: rot [img file]
You might try adding the following function:
urldecode() {
bash -c "printf '%b' '$(echo "$1" | sed 's|%%| |g;s|%|\\x|g;s| |%|g')'"
}
to your /bin/sh script, and then use
convert "$(urldecode $1)" ...
TL;DR; In detail, that urldecode function for dash processes its given argument with sed to replace all %NN with \xNN except for occurrences of %% which instead are replaced with single %. The resulting string is printed with bash printf using the %b format which makes all \xNN into characters of hexadecimal ASCII code NN.
Note that the sed processing uses space temporarily to make the %%-to-% translation bypass the %NN-to-\xNN translation. It therefore misbehaves for an input that already has space characters.
]]>Off topic but I would also suggest using whiptail (in a terminal) rather than yad because the output could be parsed without resorting to awk:
]]>First thing I tried was all kinds of quotes around the %f and %d and didn't work for me, but will go back and try again to be sure, normally that works in terminal but seems like it wouldn't work here because the entire command string is quoted.
@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're in.
Okay, just tried the recommended double quotes again, still no joy.
@Golinux: Hi there Lady! Hope all is well down there, FYI we may be moving back home soon, so maybe i'll get to see ya! ;-)
]]>Im pretty sure double quotes would rectify this as ralph mentions.
[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 'cd "%d" && shrink2 "%f"'
MimeTypes=image/bmp;image/jpeg;image/png;
confirmed working with gaps in file name, im using nemo file manager though.
]]>Here's the main one, it'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'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'm pretty good about not putting spaces in file/folder names, but ya know, would be nice if it didn't break script.
Here's the code, a .desktop file that goes into /home/user/.local/share/file-manager/actions and the script I made (usr/bin):
[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 'cd %d && shrink2 %f'
MimeTypes=image/bmp;image/jpeg;image/png;
#!/bin/sh
sizebox=$(yad --fixed --window-icon=edit-cut --form --title="Resize Image" --field="Resize to:" --width=400 --text-align=center --text="Enter new size (W x H in pixels, i.e. 800x600, 1024x768 etc.)")
size=$(echo $sizebox | awk 'BEGIN {FS="|" } { print $1 }')
convert "$1" -resize "$size" -set filename:copy '%t-%wx%h' '%[filename:copy].jpg'
# Depends: yad, imagemagick
# (note: later versions of imagemagick may require a different command than 'convert')
# 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 "Resize Image"
# option when you right-click an image file, but can also be used in terminal: shrink2 [img file]
Thanks!
~greenjeans